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

AL-852: GWCS inverse transform should respect its bounding box #8554

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
42 changes: 21 additions & 21 deletions jwst/assign_wcs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,30 @@ def _domain_to_bounding_box(domain):
return bb


def reproject(wcs1, wcs2):
"""
Given two WCSs return a function which takes pixel coordinates in
the first WCS and computes their location in the second one.
# def reproject(wcs1, wcs2):
# """
# Given two WCSs return a function which takes pixel coordinates in
# the first WCS and computes their location in the second one.

It performs the forward transformation of ``wcs1`` followed by the
inverse of ``wcs2``.
# It performs the forward transformation of ``wcs1`` followed by the
# inverse of ``wcs2``.

Parameters
----------
wcs1, wcs2 : `~gwcs.wcs.WCS`
WCS objects.
# Parameters
# ----------
# wcs1, wcs2 : `~gwcs.wcs.WCS`
# WCS objects.

Returns
-------
_reproject : func
Function to compute the transformations. It takes x, y
positions in ``wcs1`` and returns x, y positions in ``wcs2``.
"""
# Returns
# -------
# _reproject : func
# Function to compute the transformations. It takes x, y
# positions in ``wcs1`` and returns x, y positions in ``wcs2``.
# """

def _reproject(x, y):
sky = wcs1.forward_transform(x, y)
return wcs2.backward_transform(*sky)
return _reproject
# def _reproject(x, y):
# sky = wcs1.forward_transform(x, y)
# return wcs2.backward_transform(*sky)
# return _reproject


def compute_scale(wcs: WCS, fiducial: Union[tuple, np.ndarray],
Expand Down Expand Up @@ -129,7 +129,7 @@ def compute_scale(wcs: WCS, fiducial: Union[tuple, np.ndarray],
if spectral and disp_axis is None:
raise ValueError('If input WCS is spectral, a disp_axis must be given')

crpix = np.array(wcs.invert(*fiducial))
crpix = np.array(wcs.invert(*fiducial, with_bounding_box=False))

delta = np.zeros_like(crpix)
spatial_idx = np.where(np.array(wcs.output_frame.axes_type) == 'SPATIAL')[0]
Expand Down
3 changes: 3 additions & 0 deletions jwst/resample/resample_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import numpy as np
from astropy import units as u
from astropy import wcs as fitswcs
from astropy.wcs.wcsapi.wrappers import SlicedLowLevelWCS
from astropy.modeling import Model
import gwcs

from stdatamodels.dqflags import interpret_bit_flags
Expand Down
4 changes: 2 additions & 2 deletions jwst/resample/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def wcs_gwcs():
crpix = (500.0, 500.0)
shape = (1000, 1000)
pscale = 0.06 / 3600

prj = astmodels.Pix2Sky_TAN()
fiducial = np.array(crval)

Expand Down Expand Up @@ -192,7 +192,7 @@ def test_reproject(wcs1, wcs2, offset, request):
wcs1 = request.getfixturevalue(wcs1)
wcs2 = request.getfixturevalue(wcs2)
x = np.arange(150, 200)

f = reproject(wcs1, wcs2)
res = f(x, x)
assert_allclose(x, res[0] + offset)
Expand Down
2 changes: 1 addition & 1 deletion jwst/skymatch/skyimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def calc_sky(self, overlap=None, delta=True):
continue

# set pixels in 'fill_mask' that are inside a polygon to True:
x, y = self.wcs_inv(ra, dec)
x, y = self.wcs_inv(ra, dec, with_bounding_box=False)
poly_vert = list(zip(*[x, y]))

polygon = region.Polygon(True, poly_vert)
Expand Down
8 changes: 5 additions & 3 deletions jwst/tweakreg/tests/test_multichip_jwst.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _make_gwcs_wcs(fits_hdr):
Mapping((1, 2), name='xtyt'))
c2tan.name = 'Cartesian 3D to TAN'

tan2c = (Mapping((0, 0, 1), n_inputs=2, name='xtyt2xyz') |
tan2c = (Mapping((0, 0, 1), name='xtyt2xyz') |
(Const1D(1, name='one') & Identity(2, name='I(2D)')))
tan2c.name = 'TAN to cartesian 3D'

Expand Down Expand Up @@ -377,7 +377,8 @@ def test_multichip_alignment_step(monkeypatch):
format='ascii.ecsv', delimiter=' ',
names=['RA', 'DEC']
)
x, y = wr.world_to_pixel(refcat['RA'], refcat['DEC'])
#x, y = wr.world_to_pixel(refcat['RA'].value, refcat['DEC'].value)
x, y = wr.invert(refcat['RA'].value, refcat['DEC'].value, with_bounding_box=False)
refcat['x'] = x
refcat['y'] = y
mr.tweakreg_catalog = refcat
Expand Down Expand Up @@ -450,7 +451,8 @@ def test_multichip_alignment_step_abs(monkeypatch):
format='ascii.ecsv', delimiter=' ',
names=['RA', 'DEC']
)
x, y = wr.world_to_pixel(refcat['RA'], refcat['DEC'])
#x, y = wr.world_to_pixel(refcat['RA'], refcat['DEC'])
x, y = wr.invert(refcat['RA'].value, refcat['DEC'].value, with_bounding_box=False)
refcat['x'] = x
refcat['y'] = y
mr.tweakreg_catalog = refcat
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies = [
"BayesicFitting>=3.0.1",
"crds>=11.17.14",
"drizzle>=1.15.0",
"gwcs>=0.21.0,<0.22.0",
"gwcs @ git+https://github.com/nden/gwcs.git@ff195fb,
"numpy>=1.22",
"opencv-python-headless>=4.6.0.66",
"photutils>=1.5.0",
Expand Down
Loading