Skip to content
Open
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
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ Unreleased

- Return default response when request to the GSC service failed. [#227]

- Fix a bug in ``stwcs.wcsutil.hstwcs.HSTWCS.pc2cd()`` that would result in
incorrect CD matrix when the WCS has a PC matrix. [#228]


1.7.5 (2025-07-14)
------------------
- Work around an issue with the AStrometry DB which returns NaNs in certain cases. [#221]


1.7.4 (2025-01-07)
------------------

Expand Down
26 changes: 26 additions & 0 deletions stwcs/tests/test_hstwcs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from astropy.io import fits
from stwcs.wcsutil import hstwcs, HSTWCS
import numpy as np


def test_radesys():
Expand All @@ -22,3 +23,28 @@ def test_prihdu_with_extver_no_extname():
extname = HSTWCS(hdulist).extname
assert extname == ('PRIMARY', 7)
assert hdulist[extname] is hdulist[0]


def test_pc2cd():
e = np.exp(1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why not use np.e?

hdulist = fits.HDUList([
fits.PrimaryHDU(header=fits.Header([('extver', 1)])),
fits.ImageHDU(header=fits.Header([
('pc1_1', 0.1),
('pc1_2', 0.08),
('pc2_1', -0.05),
('pc2_2', 0.7),
('cdelt1', e),
('cdelt2', np.pi),
('crpix1', 512.0),
('crpix2', 512.0),
('crval1', 150.0),
('crval2', 2.0),
('ctype1', 'RA---TAN'),
('ctype2', 'DEC--TAN'),
]))
])
wcs = HSTWCS(hdulist, ext=1)
assert wcs.wcs.has_cd()
cd = np.array([[0.1 * e, 0.08 * e], [-0.05 * np.pi, 0.7 * np.pi]])
assert np.allclose(wcs.wcs.cd, cd)
2 changes: 1 addition & 1 deletion stwcs/wcsutil/hstwcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def _idc2hdr(self):

def pc2cd(self):
if self.wcs.has_pc():
self.wcs.cd = self.wcs.pc * self.wcs.cdelt[1]
self.wcs.cd = self.pixel_scale_matrix

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will work for HST files because they don't have a PC matrix. However, the example in the test generates an incorrect file because it has now a CD, a PC, and CDELT all defined.

I'm not sure offhand what the correct action here is. I need to look into how this is used and whether it should be deleted.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the test generates an incorrect file because it has now a CD, a PC, and CDELT all defined

@nden Which test?


@deprecated_renamed_argument('accuracy', 'tolerance', '1.6.1', arg_in_kwargs=True)
def all_world2pix(self, *args, **kwargs):
Expand Down