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

Obscure WCSLIB error when trying to deep copy 0-d WCS #16298

Open
astrofrog opened this issue Apr 16, 2024 · 0 comments
Open

Obscure WCSLIB error when trying to deep copy 0-d WCS #16298

astrofrog opened this issue Apr 16, 2024 · 0 comments

Comments

@astrofrog
Copy link
Member

Description

When trying to deep copy a 0-d WCS, an obscure error occurs. We should either disallow 0-d WCSes from being created in .sub, or gracefully deep copy the 0-d WCS.

Expected behavior

The deep copy should work or the .sub call should fail because it results in a 0-d WCS.

How to Reproduce

In [1]: from astropy.wcs import WCS, WCSSUB_SPECTRAL

In [2]: wcs = WCS(naxis=2)

In [3]: wcs_sub = wcs.sub([WCSSUB_SPECTRAL])

In [4]: wcs_sub.deepcopy()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[4], line 1
----> 1 wcs_sub.deepcopy()

File ~/python/dev/lib/python3.11/site-packages/astropy/wcs/wcs.py:653, in WCS.deepcopy(self)
    646 def deepcopy(self):
    647     """
    648     Return a deep copy of the object.
    649 
    650     Convenience method so user doesn't have to import the
    651     :mod:`copy` stdlib module.
    652     """
--> 653     return copy.deepcopy(self)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/copy.py:153, in deepcopy(x, memo, _nil)
    151 copier = getattr(x, "__deepcopy__", None)
    152 if copier is not None:
--> 153     y = copier(memo)
    154 else:
    155     reductor = dispatch_table.get(cls)

File ~/python/dev/lib/python3.11/site-packages/astropy/wcs/wcs.py:626, in WCS.__deepcopy__(self, memo)
    620 new_copy = self.__class__()
    621 new_copy.naxis = deepcopy(self.naxis, memo)
    622 WCSBase.__init__(
    623     new_copy,
    624     deepcopy(self.sip, memo),
    625     (deepcopy(self.cpdis1, memo), deepcopy(self.cpdis2, memo)),
--> 626     deepcopy(self.wcs, memo),
    627     (deepcopy(self.det2im1, memo), deepcopy(self.det2im2, memo)),
    628 )
    629 for key, val in self.__dict__.items():
    630     new_copy.__dict__[key] = deepcopy(val, memo)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/copy.py:153, in deepcopy(x, memo, _nil)
    151 copier = getattr(x, "__deepcopy__", None)
    152 if copier is not None:
--> 153     y = copier(memo)
    154 else:
    155     reductor = dispatch_table.get(cls)

RuntimeError: NULL error object in wcslib

Versions

macOS-14.1.1-arm64-arm-64bit
Python 3.11.2 (main, Mar 23 2023, 23:28:33) [Clang 14.0.0 (clang-1400.0.29.202)]
astropy 7.0.0.dev14+gaae4425033.d20240411
Numpy 1.26.4
pyerfa 2.0.1.1
Scipy 1.10.1
Matplotlib 3.6.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant