8
8
from astropy .wcs .wcsapi import BaseHighLevelWCS , BaseLowLevelWCS , HighLevelWCSWrapper , SlicedLowLevelWCS
9
9
10
10
from ndcube .utils import wcs as wcs_utils
11
+ from ndcube .utils .exceptions import warn_user
11
12
12
13
__all__ = [
13
14
"get_crop_item_from_points" ,
@@ -191,8 +192,9 @@ def get_crop_item_from_points(points, wcs, crop_by_values, keepdims):
191
192
combined_points_array_idx [axis ] = combined_points_array_idx [axis ] + [index ]
192
193
# Define slice item with which to slice cube.
193
194
item = []
195
+ ambiguous = []
194
196
result_is_scalar = True
195
- for axis_indices in combined_points_array_idx :
197
+ for axis_num , axis_indices in enumerate ( combined_points_array_idx ) :
196
198
if axis_indices == []:
197
199
result_is_scalar = False
198
200
item .append (slice (None ))
@@ -201,12 +203,17 @@ def get_crop_item_from_points(points, wcs, crop_by_values, keepdims):
201
203
min_idx = int (np .floor (min (axis_indices ) + 0.5 ))
202
204
max_idx = int (np .ceil (max (axis_indices ) - 0.5 )) + 1
203
205
if min_idx == max_idx :
204
- raise ValueError ("Input points cause cube to be cropped to zero size along a pixel axis." )
206
+ ambiguous .append (axis_num )
207
+ max_idx += 1
205
208
if max_idx - min_idx == 1 and not keepdims :
206
209
item .append (min_idx )
207
210
else :
208
211
item .append (slice (min_idx , max_idx ))
209
212
result_is_scalar = False
213
+ if ambiguous :
214
+ warn_user ("Input points all lie on the same pixel edge of array "
215
+ + (f"axis { ambiguous [0 ]} , " if len (ambiguous ) == 1 else f"axes { ambiguous } , " )
216
+ + "so the crop is ambiguous. The pixel 'greater than' each edge is returned." )
210
217
# If item will result in a scalar cube, raise an error as this is not currently supported.
211
218
if result_is_scalar :
212
219
raise ValueError ("Input points causes cube to be cropped to a single pixel. "
0 commit comments