Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: CoordinateImage API #1090

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1b7df51
ENH: Start restoring triangular meshes
effigies Sep 19, 2023
5d25cef
TEST: Test basic TriangularMesh behavior
effigies Sep 20, 2023
e426afe
RF: Use order kwarg for array proxies
effigies Sep 20, 2023
1a46c70
TEST: Rework FreeSurferHemisphere and H5Geometry examples with mixin
effigies Sep 20, 2023
be05f09
TEST: Tag tests that require access to the data directory
effigies Sep 20, 2023
cbb91d1
RF: Allow coordinate names to be set on init
effigies Sep 22, 2023
107ead6
TEST: More fully test mesh and family APIs
effigies Sep 22, 2023
368c145
ENH: Avoid duplicating objects, note that coordinate family mappings …
effigies Sep 22, 2023
9d5361a
ENH: Add copy() method to ArrayProxy
effigies Sep 19, 2023
81b1033
ENH: Copy lock if filehandle is shared, add tests
effigies Sep 22, 2023
b70a4d9
Merge branches 'enh/copyarrayproxy', 'enh/xml-kwargs' and 'enh/triang…
effigies Sep 22, 2023
798f0c6
ENH: Add stubs from BIAP 9
effigies Feb 18, 2022
7a6d50c
ENH: Implement CoordinateAxis. and Parcel.__getitem__
effigies Feb 21, 2022
344bfd8
TEST: Add FreeSurferSubject geometry collection, test loading Cifti2 …
effigies Feb 21, 2022
1138a95
ENH: Add CaretSpecFile type for use with CIFTI-2
effigies Feb 22, 2022
c7ab610
TEST: Load CaretSpecFile as a GeometryCollection
effigies Feb 22, 2022
a458ec3
ENH: Hacky mixin to make surface CaretDataFiles implement TriangularMesh
effigies Feb 23, 2022
921173b
FIX: CoordinateAxis.__getitem__ fix
effigies Feb 24, 2022
d4d42a0
ENH: Implement CoordinateAxis.get_indices
effigies Feb 24, 2022
b51ec36
TEST: Add some assertions and smoke tests to exercise methods
effigies Feb 24, 2022
76b52f5
ENH: Add from_image/from_header methods to bring logic out of tests
effigies Jan 25, 2023
1392a06
TEST: Add fsLR.wb.spec file for interpreting fsLR data
effigies Feb 24, 2022
5edddd4
ENH: Add CoordinateImage slicing by parcel name
effigies Jan 25, 2023
05ca9fb
RF: Simplify CaretSpecParser slightly
effigies Feb 25, 2022
6c2407d
TEST: Check SurfaceDataFile retrieval
effigies Aug 20, 2022
20f71df
Merge branch 'master' into enh/coordimage_api
effigies Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
RF: Allow coordinate names to be set on init
effigies committed Sep 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit cbb91d1f9eb8a5768190bc313f82755f83c7df94
13 changes: 9 additions & 4 deletions nibabel/pointset.py
Original file line number Diff line number Diff line change
@@ -169,17 +169,21 @@ def from_tuple(
mesh: tuple[CoordinateArray, CoordinateArray],
affine: np.ndarray | None = None,
homogeneous: bool = False,
**kwargs,
) -> Self:
return cls(mesh[0], mesh[1], affine=affine, homogeneous=homogeneous)
return cls(mesh[0], mesh[1], affine=affine, homogeneous=homogeneous, **kwargs)

@classmethod
def from_object(
cls,
mesh: HasMeshAttrs,
affine: np.ndarray | None = None,
homogeneous: bool = False,
**kwargs,
) -> Self:
return cls(mesh.coordinates, mesh.triangles, affine=affine, homogeneous=homogeneous)
return cls(
mesh.coordinates, mesh.triangles, affine=affine, homogeneous=homogeneous, **kwargs
)

@property
def n_triangles(self):
@@ -198,9 +202,10 @@ def get_mesh(self, *, as_homogeneous: bool = False):


class CoordinateFamilyMixin(Pointset):
def __init__(self, *args, **kwargs):
self._coords = {}
def __init__(self, *args, name='original', **kwargs):
mapping = kwargs.pop('mapping', {})
super().__init__(*args, **kwargs)
self._coords = {name: self.coordinates, **mapping}

def get_names(self):
"""List of surface names that can be passed to :meth:`with_name`"""
18 changes: 9 additions & 9 deletions nibabel/tests/test_pointset.py
Original file line number Diff line number Diff line change
@@ -262,7 +262,7 @@ def __getitem__(self, slicer):
return h5f[self.dataset_name][slicer]


class H5Geometry(ps.TriangularMesh, ps.CoordinateFamilyMixin):
class H5Geometry(ps.CoordinateFamilyMixin, ps.TriangularMesh):
"""Simple Geometry file structure that combines a single topology
with one or more coordinate sets
"""
@@ -274,8 +274,7 @@ def from_filename(klass, pathlike):
triangles = H5ArrayProxy(pathlike, '/topology')
for name in h5f['coordinates']:
coords[name] = H5ArrayProxy(pathlike, f'/coordinates/{name}')
self = klass(next(iter(coords.values())), triangles)
self._coords.update(coords)
self = klass(next(iter(coords.values())), triangles, mapping=coords)
return self

def to_filename(self, pathlike):
@@ -336,13 +335,12 @@ def triangles(self):
)


class FreeSurferHemisphere(ps.TriangularMesh, ps.CoordinateFamilyMixin):
class FreeSurferHemisphere(ps.CoordinateFamilyMixin, ps.TriangularMesh):
@classmethod
def from_filename(klass, pathlike):
path = Path(pathlike)
hemi, default = path.name.split('.')
self = klass.from_object(FSGeometryProxy(path))
self._coords[default] = self.coordinates
self = klass.from_object(FSGeometryProxy(path), name=default)
mesh_names = (
'orig',
'white',
@@ -353,10 +351,12 @@ def from_filename(klass, pathlike):
'midthickness',
'graymid',
) # Often created

for mesh in mesh_names:
fpath = path.parent / f'{hemi}.{mesh}'
if mesh not in self._coords and fpath.exists():
self.add_coordinates(mesh, FSGeometryProxy(fpath).coordinates)
if mesh != default:
fpath = path.parent / f'{hemi}.{mesh}'
if fpath.exists():
self.add_coordinates(mesh, FSGeometryProxy(fpath).coordinates)
return self