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