Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadia committed Jun 14, 2024
1 parent ff195fb commit cd325e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions gwcs/tests/test_coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def test_bare_baseframe():
output_frame=frame,
input_frame=cf.CoordinateFrame(1, "PIXEL", (0,), unit=(u.pix,), name="detector_frame")
)
#w.bounding_box = (0, 9)
assert u.allclose(w.world_to_pixel(0*u.km), 0)


Expand Down
32 changes: 31 additions & 1 deletion gwcs/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,13 @@ def invert(self, *args, **kwargs):

with_bounding_box = kwargs.pop('with_bounding_box', True)
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)

if btrans is not None:
akwargs = {k: v for k, v in kwargs.items() if k not in _ITER_INV_KWARGS}
#akwargs = {k: v for k, v in kwargs.items() if k not in _ITER_INV_KWARGS}
result = btrans(*args, **akwargs)
else:
result = self.numerical_inverse(*args, **kwargs, with_units=with_units)
Expand All @@ -498,6 +502,26 @@ def invert(self, *args, **kwargs):
return self.input_frame.coordinates(*result)
else:
return result

def outside_footprint(self, world_arrays):
for axis in world_arrays:
if np.isscalar(world_arrays) or self.output_frame.naxes == 1:
world_arrays = [world_arrays]
world_arrays = list(world_arrays)
footprint = self.footprint()
for idim, coord in enumerate(world_arrays):
axis_range = footprint[:, idim]
range = [axis_range.min(), axis_range.max()]
outside = (coord < range[0]) | (coord > range[1])
if np.any(outside):
if np.isscalar(coord):
coord = np.nan

Check warning on line 518 in gwcs/wcs.py

View check run for this annotation

Codecov / codecov/patch

gwcs/wcs.py#L517-L518

Added lines #L517 - L518 were not covered by tests
else:
coord[outside] = np.nan
world_arrays[idim] = coord

Check warning on line 521 in gwcs/wcs.py

View check run for this annotation

Codecov / codecov/patch

gwcs/wcs.py#L520-L521

Added lines #L520 - L521 were not covered by tests

return world_arrays


def out_of_bounds(self, pixel_arrays, fill_value=np.nan):
if np.isscalar(pixel_arrays) or self.input_frame.naxes == 1:
Expand Down Expand Up @@ -1401,6 +1425,11 @@ def footprint(self, bounding_box=None, center=False, axis_type="all"):
"""
def _order_clockwise(v):
# if self.input_frame.naxes == 1:
# bb = self.bounding_box.bounding_box()
# if isinstance(bb[0], u.Quantity):
# bb = [v.value for v in bb] * bb[0].unit
# return (bb,)
return np.asarray([[v[0][0], v[1][0]], [v[0][0], v[1][1]],
[v[0][1], v[1][1]], [v[0][1], v[1][0]]]).T

Expand All @@ -1418,6 +1447,7 @@ def _order_clockwise(v):
else:
vertices = np.array(list(itertools.product(*bb))).T

# workaround an issue with bbox with quantity, interval needs to be a cquantity, not a list of quantities
if center:
vertices = utils._toindex(vertices)

Expand Down

0 comments on commit cd325e4

Please sign in to comment.