Skip to content

solves #726: bug in default inverse mapping#729

Open
0Navin0 wants to merge 2 commits into
spacetelescope:mainfrom
0Navin0:fix-wcs-inverse
Open

solves #726: bug in default inverse mapping#729
0Navin0 wants to merge 2 commits into
spacetelescope:mainfrom
0Navin0:fix-wcs-inverse

Conversation

@0Navin0
Copy link
Copy Markdown

@0Navin0 0Navin0 commented Mar 18, 2026

This PR supersedes #727 (moved to a feature branch instead of main to follow repo workflow).

# =============================================
# Following the same example described in the issue #726  
# after bug fix
# =============================================

In [23]: wa
Out[23]:
<SkyCoord (ICRS): (ra, dec) in deg
    (5.46165002, -72.12183946)>


In [29]: wcsobj.backward_transform
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
File ~/Softwares/gwcs/gwcs/wcs/_pipeline.py:639, in Pipeline.backward_transform(self)
    638 try:
--> 639     backward = self.forward_transform.inverse
    640 except NotImplementedError as err:

File ~/anaconda3/envs/rdm_env_latest/lib/python3.14/site-packages/astropy/modeling/core.py:1383, in Model.inverse(self)
   1382 elif self._inverse is not None:
-> 1383     result = self._inverse()
   1384     if result is not NotImplemented:
.
.
.
.
NotImplementedError: No analytical or user-supplied inverse transform has been implemented for this model.

# Even when backward transform is not implemented in the original definition of the `wcsobj`, it should default successfully to `numerical_inverse` as shown below:
In [24]: wcsobj.world_to_pixel(wa)
Out[24]: (np.float64(3.999999999638021), np.float64(3.999999999540023))

In [25]: wcsobj.numerical_inverse(wa.ra.deg, wa.dec.deg)
Out[25]: (3.999999999638021, 3.999999999540023)

This PR addresses a bug that triggered when a backward_transform is not defined and default numerical_inverse needs to be used.

Tasks

News fragment change types:
  • changes/729.bugfix.rst: fixes an issue

sky2pix_proj can't access the __name__ attribute of the parent class, so
explicitly access from the parent class.
@0Navin0 0Navin0 requested a review from a team as a code owner March 18, 2026 23:34
Copy link
Copy Markdown
Member

@mcara mcara left a comment

Choose a reason for hiding this comment

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

It needs a change log entry and a unit test.

Comment thread gwcs/wcs/_wcs.py
sky2pix_proj = transform
break
if sky2pix_proj.__name__.startswith("Pix2Sky"):
if sky2pix_proj.__class__.__name__.startswith("pix2sky"):
Copy link
Copy Markdown
Member

@mcara mcara Mar 19, 2026

Choose a reason for hiding this comment

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

Suggested change
if sky2pix_proj.__class__.__name__.startswith("pix2sky"):
if type(sky2pix_proj).__name__.startswith("Pix2Sky")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants