Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix outside_footprint for spherical coordinates #535

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions gwcs/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,11 @@
world_arrays = list(world_arrays)

axes_types = set(self.output_frame.axes_type)
footprint = self.footprint()
try:
footprint = self.footprint()
except AttributeError:

Check warning on line 498 in gwcs/wcs.py

View check run for this annotation

Codecov / codecov/patch

gwcs/wcs.py#L498

Added line #L498 was not covered by tests
# SlicedWCS does not implement footrpint
return world_arrays

Check warning on line 500 in gwcs/wcs.py

View check run for this annotation

Codecov / codecov/patch

gwcs/wcs.py#L500

Added line #L500 was not covered by tests
not_numerical = False
if not utils.isnumerical(world_arrays[0]):
not_numerical = True
Expand All @@ -502,13 +506,17 @@
ind = np.asarray((np.asarray(self.output_frame.axes_type) == axtyp))

for idim, coord in enumerate(world_arrays):
coord = _tofloat(coord)
if not np.isscalar(coord):
coord = _tofloat(coord.copy())
if np.asarray(ind).sum() > 1:
axis_range = footprint[:, idim]
else:
axis_range = footprint
axis_range = footprint[:, idim]
range = [axis_range.min(), axis_range.max()]
outside = (coord < range[0]) | (coord > range[1])
if axtyp == 'SPATIAL' and isinstance(self.output_frame, cf.CelestialFrame):
range = np.mod(range, 180)
coord = np.mod(coord, 180)
Comment on lines +517 to +518
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinates already should be in the [0, 360] and [0, 180] (or [-90, 90]) range. Taking mod at 180 does not look like the correct approach. I think there may be cases when this could fail. For example, take CRVAL at 180 and an image that spans from ra=179.8 to 180.1.

Try adding some unit tests for this.

Also a good time to replace range with something else like world_range.

outside = np.logical_or(coord < range[0], coord > range[1])
if np.any(outside):
if np.isscalar(coord):
coord = np.nan
Expand Down
Loading