55import numpy as np
66
77import astropy .nddata
8- from astropy .wcs .wcsapi import BaseHighLevelWCS , HighLevelWCSWrapper , SlicedLowLevelWCS
8+ from astropy .wcs .wcsapi import BaseHighLevelWCS , BaseLowLevelWCS , HighLevelWCSWrapper , SlicedLowLevelWCS
99
1010from ndcube .utils import wcs as wcs_utils
1111
@@ -81,6 +81,8 @@ def sanitize_crop_inputs(points, wcs):
8181 # Confirm whether point contains at least one None entry.
8282 if all (coord is None for coord in points [i ]):
8383 values_are_none [i ] = True
84+ # Squeeze length-1 coordinate objects to scalars.
85+ points [i ] = [coord .squeeze () if hasattr (coord , "squeeze" ) else coord for coord in points [i ]]
8486 # If no points contain a coord, i.e. if all entries in all points are None,
8587 # set no-op flag to True and exit.
8688 if all (values_are_none ):
@@ -138,6 +140,8 @@ def get_crop_item_from_points(points, wcs, crop_by_values, keepdims):
138140 # Define a list of lists to hold the array indices of the points
139141 # where each inner list gives the index of all points for that array axis.
140142 combined_points_array_idx = [[]] * wcs .pixel_n_dim
143+ high_level_wcs = HighLevelWCSWrapper (wcs ) if isinstance (wcs , BaseLowLevelWCS ) else wcs
144+ wcs = high_level_wcs .low_level_wcs
141145 # For each point compute the corresponding array indices.
142146 for point in points :
143147 # Get the arrays axes associated with each element in point.
@@ -150,8 +154,7 @@ def get_crop_item_from_points(points, wcs, crop_by_values, keepdims):
150154 wcs_utils .convert_between_array_and_pixel_axes (pix_axes , wcs .pixel_n_dim )))
151155 point_inputs_array_axes = tuple (point_inputs_array_axes )
152156 else :
153- point_inputs_array_axes = wcs_utils .array_indices_for_world_objects (
154- HighLevelWCSWrapper (wcs ))
157+ point_inputs_array_axes = wcs_utils .array_indices_for_world_objects (high_level_wcs )
155158 # Get indices of array axes which correspond to only None inputs in point
156159 # as well as those that correspond to a coord.
157160 point_indices_with_inputs = []
0 commit comments