Skip to content

Commit

Permalink
fix something
Browse files Browse the repository at this point in the history
  • Loading branch information
nden committed Dec 10, 2024
1 parent fb5f70d commit c455cab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
6 changes: 3 additions & 3 deletions gwcs/tests/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,10 +1161,10 @@ def test_in_image():
None)])
w2.bounding_box = [(1, 100), (2, 20)]

assert np.isscalar(w2.in_image(2, 6))
assert np.isscalar(w2.in_image(2, 6))#[0])
assert not np.isscalar(w2.in_image([2], [6]))
assert w2.in_image(4, 6)
assert not w2.in_image(5, 0)
assert (w2.in_image(4, 6))#.all()
assert not (w2.in_image(5, 0))#, [True, False])
assert np.array_equal(
w2.in_image(
[[9, 10, 11, 15], [8, 9, 67, 98], [2, 2, np.nan, 102]],
Expand Down
30 changes: 4 additions & 26 deletions gwcs/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,31 +400,12 @@ def in_image(self, *args, **kwargs):
and `False` if input is outside the footprint.
"""
coords = self.invert(*args, with_bounding_box=False, **kwargs)
coords = self.invert(*args, **kwargs)

result = np.isfinite(coords)
if self.input_frame.naxes > 1:
result = np.all(result, axis=0)

if self.bounding_box is None or not np.any(result):
return result

if self.input_frame.naxes == 1:
x1, x2 = self.bounding_box.bounding_box()

if len(np.shape(args[0])) > 0:
result[result] = (coords[result] >= x1) & (coords[result] <= x2)
elif result:
result = (coords >= x1) and (coords <= x2)

else:
if len(np.shape(args[0])) > 0:
for c, (x1, x2) in zip(coords, self.bounding_box):
result[result] = (c[result] >= x1) & (c[result] <= x2)

elif result:
result = all([(c >= x1) and (c <= x2) for c, (x1, x2) in zip(coords, self.bounding_box)])

return result

def invert(self, *args, **kwargs):
Expand Down Expand Up @@ -489,7 +470,7 @@ def invert(self, *args, **kwargs):
fill_value = kwargs.pop('fill_value', np.nan)
akwargs = {k: v for k, v in kwargs.items() if k not in _ITER_INV_KWARGS}
if with_bounding_box and self.bounding_box is not None:
result = self.outside_footprint(args)
args = self.outside_footprint(args)

if btrans is not None:
result = btrans(*args, **akwargs)
Expand All @@ -513,11 +494,8 @@ def outside_footprint(self, world_arrays):

axes_types = set(self.output_frame.axes_type)
footprint = self.footprint()
world_arrays = [coo.to(unit) for coo, unit in zip(world_arrays, self.output_frame.unit)
if isinstance(coo, u.Quantity)]
world_arrays = [high_level_objects_to_values(coo, low_level_wcs=self) for
coo in world_arrays if not utils.isnumerical(coo)]

if not utils.isnumerical(world_arrays[0]):
world_arrays = high_level_objects_to_values(*world_arrays, low_level_wcs=self)
for axtyp in axes_types:
ind = np.asarray((np.asarray(self.output_frame.axes_type) == axtyp))

Expand Down

0 comments on commit c455cab

Please sign in to comment.