1
+ from nibabel .fileslice import fill_slicer
2
+
3
+
1
4
class CoordinateImage :
2
5
"""
3
6
Attributes
@@ -7,6 +10,11 @@ class CoordinateImage:
7
10
dataobj : array-like
8
11
"""
9
12
13
+ def __init__ (self , data , coordaxis , header = None ):
14
+ self .data = data
15
+ self .coordaxis = coordaxis
16
+ self .header = header
17
+
10
18
11
19
class CoordinateAxis :
12
20
"""
@@ -15,6 +23,9 @@ class CoordinateAxis:
15
23
parcels : list of ``Parcel`` objects
16
24
"""
17
25
26
+ def __init__ (self , parcels ):
27
+ self .parcels = parcels
28
+
18
29
def load_structures (self , mapping ):
19
30
"""
20
31
Associate parcels to ``Pointset`` structures
@@ -26,7 +37,31 @@ def __getitem__(self, slicer):
26
37
Return a sub-sampled CoordinateAxis containing structures
27
38
matching the indices provided.
28
39
"""
29
- raise NotImplementedError
40
+ if slicer is Ellipsis or slicer == slice (None ):
41
+ return self
42
+ elif isinstance (slicer , slice ):
43
+ slicer = fill_slicer (slicer , len (self ))
44
+ print (slicer )
45
+ start , stop , step = slicer .start , slicer .stop , slicer .step
46
+ else :
47
+ raise TypeError (f'Indexing type not supported: { type (slicer )} ' )
48
+
49
+ subparcels = []
50
+ pstop = 0
51
+ for parcel in self .parcels :
52
+ pstart , pstop = pstop , pstop + len (parcel )
53
+ print (pstart , pstop )
54
+ if pstop < start :
55
+ continue
56
+ if pstart >= stop :
57
+ break
58
+ if start < pstart :
59
+ substart = (start - pstart ) % step
60
+ else :
61
+ substart = start - pstart
62
+ print (slice (substart , stop - pstart , step ))
63
+ subparcels .append (parcel [substart : stop - pstop : step ])
64
+ return CoordinateAxis (subparcels )
30
65
31
66
def get_indices (self , parcel , indices = None ):
32
67
"""
@@ -36,6 +71,9 @@ def get_indices(self, parcel, indices=None):
36
71
"""
37
72
raise NotImplementedError
38
73
74
+ def __len__ (self ):
75
+ return sum (len (parcel ) for parcel in self .parcels )
76
+
39
77
40
78
class Parcel :
41
79
"""
@@ -46,6 +84,20 @@ class Parcel:
46
84
indices : object that selects a subset of coordinates in structure
47
85
"""
48
86
87
+ def __init__ (self , name , structure , indices ):
88
+ self .name = name
89
+ self .structure = structure
90
+ self .indices = indices
91
+
92
+ def __repr__ (self ):
93
+ return f'<Parcel { self .name } ({ len (self .indices )} )>'
94
+
95
+ def __len__ (self ):
96
+ return len (self .indices )
97
+
98
+ def __getitem__ (self , slicer ):
99
+ return self .__class__ (self .name , self .structure , self .indices [slicer ])
100
+
49
101
50
102
class GeometryCollection :
51
103
"""
0 commit comments