5
5
import numpy as np
6
6
7
7
import astropy .nddata
8
- from astropy .wcs .wcsapi import BaseHighLevelWCS , HighLevelWCSWrapper , SlicedLowLevelWCS
8
+ from astropy .wcs .wcsapi import BaseHighLevelWCS , BaseLowLevelWCS , HighLevelWCSWrapper , SlicedLowLevelWCS
9
9
10
10
from ndcube .utils import wcs as wcs_utils
11
11
@@ -81,6 +81,8 @@ def sanitize_crop_inputs(points, wcs):
81
81
# Confirm whether point contains at least one None entry.
82
82
if all (coord is None for coord in points [i ]):
83
83
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 ]]
84
86
# If no points contain a coord, i.e. if all entries in all points are None,
85
87
# set no-op flag to True and exit.
86
88
if all (values_are_none ):
@@ -138,6 +140,8 @@ def get_crop_item_from_points(points, wcs, crop_by_values, keepdims):
138
140
# Define a list of lists to hold the array indices of the points
139
141
# where each inner list gives the index of all points for that array axis.
140
142
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
141
145
# For each point compute the corresponding array indices.
142
146
for point in points :
143
147
# 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):
150
154
wcs_utils .convert_between_array_and_pixel_axes (pix_axes , wcs .pixel_n_dim )))
151
155
point_inputs_array_axes = tuple (point_inputs_array_axes )
152
156
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 )
155
158
# Get indices of array axes which correspond to only None inputs in point
156
159
# as well as those that correspond to a coord.
157
160
point_indices_with_inputs = []
0 commit comments