@@ -141,17 +141,17 @@ def get_crop_item_from_points(points, wcs, crop_by_values, keepdims):
141
141
# where each inner list gives the index of all points for that array axis.
142
142
combined_points_array_idx = [[]] * wcs .pixel_n_dim
143
143
high_level_wcs = HighLevelWCSWrapper (wcs ) if isinstance (wcs , BaseLowLevelWCS ) else wcs
144
- wcs = high_level_wcs .low_level_wcs
144
+ low_level_wcs = high_level_wcs .low_level_wcs
145
145
# For each point compute the corresponding array indices.
146
146
for point in points :
147
147
# Get the arrays axes associated with each element in point.
148
148
if crop_by_values :
149
149
point_inputs_array_axes = []
150
- for i in range (wcs .world_n_dim ):
150
+ for i in range (low_level_wcs .world_n_dim ):
151
151
pix_axes = np .array (
152
- wcs_utils .world_axis_to_pixel_axes (i , wcs .axis_correlation_matrix ))
152
+ wcs_utils .world_axis_to_pixel_axes (i , low_level_wcs .axis_correlation_matrix ))
153
153
point_inputs_array_axes .append (tuple (
154
- wcs_utils .convert_between_array_and_pixel_axes (pix_axes , wcs .pixel_n_dim )))
154
+ wcs_utils .convert_between_array_and_pixel_axes (pix_axes , low_level_wcs .pixel_n_dim )))
155
155
point_inputs_array_axes = tuple (point_inputs_array_axes )
156
156
else :
157
157
point_inputs_array_axes = wcs_utils .array_indices_for_world_objects (high_level_wcs )
@@ -164,14 +164,17 @@ def get_crop_item_from_points(points, wcs, crop_by_values, keepdims):
164
164
point_indices_with_inputs .append (i )
165
165
array_axes_with_input .append (point_inputs_array_axes [i ])
166
166
array_axes_with_input = set (chain .from_iterable (array_axes_with_input ))
167
- array_axes_without_input = set (range (wcs .pixel_n_dim )) - array_axes_with_input
167
+ array_axes_without_input = set (range (low_level_wcs .pixel_n_dim )) - array_axes_with_input
168
168
# Slice out the axes that do not correspond to a coord
169
169
# from the WCS and the input point.
170
- wcs_slice = np . array ([ slice ( None )] * wcs . pixel_n_dim )
171
- if len ( array_axes_without_input ):
170
+ if len ( array_axes_without_input ) > 0 :
171
+ wcs_slice = np . array ([ slice ( None )] * low_level_wcs . pixel_n_dim )
172
172
wcs_slice [np .array (list (array_axes_without_input ))] = 0
173
- sliced_wcs = SlicedLowLevelWCS (wcs , slices = tuple (wcs_slice ))
174
- sliced_point = np .array (point , dtype = object )[np .array (point_indices_with_inputs )]
173
+ sliced_wcs = SlicedLowLevelWCS (low_level_wcs , slices = tuple (wcs_slice ))
174
+ sliced_point = np .array (point , dtype = object )[np .array (point_indices_with_inputs )]
175
+ else :
176
+ # Else, if all axes have at least one crop input, no need to slice the WCS.
177
+ sliced_wcs , sliced_point = low_level_wcs , np .array (point , dtype = object )
175
178
# Derive the array indices of the input point and place each index
176
179
# in the list corresponding to its axis.
177
180
if crop_by_values :
0 commit comments