@@ -122,30 +122,31 @@ def _calc_data_slices(self, data, position, extent, stop_rule):
122
122
units = self .units
123
123
124
124
for idx , dim in enumerate (data .dimensions ):
125
+ scaling = 1.0
125
126
if idx < len (position ):
126
- pos = position [idx ]
127
- start = self ._pos_to_idx (pos , units [idx ], dim , IndexMode .GreaterOrEqual )
128
- else :
129
- # Tag doesn't specify (pos, ext) for all dimensions: will return entire remaining dimensions (0:len)
130
- start = 0
131
- if extent is None or len (extent ) == 0 :
132
- # no extents: return one element
133
- stop = start + 1
134
- elif idx < len (extent ):
135
- ext = extent [idx ]
136
- stop = self ._pos_to_idx (pos + ext , units [idx ], dim , stop_rule .to_index_mode ()) + 1
137
- else :
138
- # Tag doesn't specify (pos, ext) for all dimensions: will return entire remaining dimensions (0:len)
139
- stop = data .shape [idx ]
140
-
141
- if stop <= start :
142
- # always return at least one element per dimension
143
- stop = start + 1
144
- refslice .append (slice (start , stop ))
127
+ start_pos = position [idx ]
128
+ start_pos , scaling = self ._scale_position (start_pos , units [idx ], dim )
129
+ if extent is not None and idx < len (extent ):
130
+ stop_pos = extent [idx ]
131
+ stop_pos *= scaling
132
+ stop_pos += start_pos
133
+ slice_mode = stop_rule if extent [idx ] > 0.0 else SliceMode .Inclusive
134
+ else :
135
+ stop_pos = start_pos
136
+ slice_mode = SliceMode .Inclusive
137
+ range_indices = dim .range_indices (start_pos , stop_pos , slice_mode )
138
+ refslice .append (range_indices if range_indices is None else slice (range_indices [0 ], range_indices [1 ] + 1 ))
139
+ else : # no position, we take the whole slice for this dimension
140
+ start_index = 0
141
+ stop_index = data .shape [idx ]
142
+ refslice .append (slice (start_index , stop_index ))
143
+
145
144
return tuple (refslice )
146
145
147
146
@staticmethod
148
147
def _slices_in_data (data , slices ):
148
+ if slices is None or not all (slices ):
149
+ return False
149
150
dasize = data .data_extent
150
151
stops = tuple (sl .stop for sl in slices )
151
152
return np .all (np .less_equal (stops , dasize ))
0 commit comments