Skip to content

bug: astropy.wcs.WCS() constructor adds newline to CTYPE1? - #257

Merged
mdboom merged 1 commit into
astropy:masterfrom
mdboom:wcs/newlines-in-cards
Jun 5, 2012
Merged

mdboom merged 1 commit into
astropy:masterfrom
mdboom:wcs/newlines-in-cards

Conversation

@mdboom

@mdboom mdboom commented Jun 5, 2012

Copy link
Copy Markdown
Contributor

I have a FITS file with a header that looks fine, but for some reason, when the WCS() constructor is called, it appears to prepend a newline character to CTYPE1 upon construction. I can't tell if this is a problem with astropy.wcs or with my file, but the behavior is extremely strange regardless. I had the same problem with pywcs-1.10, but the error messages were less helpful than they are with the current version.

To reproduce: grab
http://supernova.lbl.gov/~kbarbary/tmp/PTF_200906253621_i_p_mask_t084123_u012052003_f02_p002899_c07.fits (17MB)

>>> from astropy.wcs import WCS
>>> import astropy.io.fits as fits
>>> hdulist = fits.open('PTF_200906253621_i_p_mask_t084123_u012052003_f02_p002899_c07.fits')
>>> hdulist[0].header['CTYPE1']
'RA---TAN-SIP'
>>> hdulist[0].header['CTYPE2']
'DEC--TAN-SIP'
>>> wcs = WCS(hdulist[0].header)
WARNING: FITSFixedWarning: 'celfix' made the change 'Unrecognized projection code (-TA in CTYPE1)'. This FITS header contains non-standard content. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: 'cdfix' made the change 'Success'. This FITS header contains non-standard content. [astropy.wcs.wcs]
>>> wcs.wcs.ctype
['\nRA---TAN-SIP', 'DEC--TAN-SIP']

... The result is that the wcs object is not constructed correctly because it thought the projection code was "-TA" rather than "TAN".

@ghost ghost assigned mdboom Jun 5, 2012
@mdboom

mdboom commented Jun 5, 2012

Copy link
Copy Markdown
Contributor

This FITS file has 81-character-aligned header cards (with extra newlines at the end). io.fits (pyfits) is clever enough to handle this case, but the header parser is wcslib is more strict about 80-character alignment. The fix is to get pyfits to "normalize" the header for us before passing it to wcslib.

…s are read fine by io.fits, but break with wcslib (which has a less lenient parser). Add a unit test for this case.
@kbarbary

kbarbary commented Jun 5, 2012

Copy link
Copy Markdown
Member Author

Huh, I don't see the newlines in the header when opening it with a text editor, or doing this:

>>> f = open('PTF_200906253621_i_p_mask_t084123_u012052003_f02_p002899_c07.fits', 'r')
>>> f.read(200)
'SIMPLE  =                    T / Fits standard                                  BITPIX  =                   16 / FOUR-BYTE SINGLE PRECISION FLOATING POINT      NAXIS   =                    2 / STANDAR'

What can I use to see the newlines?

@mdboom

mdboom commented Jun 5, 2012

Copy link
Copy Markdown
Contributor

Ah, good catch. It wasn't the file, but the way PyFITS formats the header when using repr(header). Using repr(header.ascard) formats things correctly for wcslib. Sorry for the confusion.

@mdboom

mdboom commented Jun 5, 2012

Copy link
Copy Markdown
Contributor

@kbarbary: Can you confirm that this PR resolves your original issue? If so, I'll merge it.

@kbarbary

kbarbary commented Jun 5, 2012

Copy link
Copy Markdown
Member Author

Yes, it fixed the original issue. ctype[0] no longer contains a newline:

>>> wcs = WCS(hdulist[0].header)
WARNING: FITSFixedWarning: 'celfix' made the change 'PV1_5 : Unrecognized coordinate transformation parameter'. This FITS header contains non-standard content. [astropy.wcs.wcs]
>>> wcs.wcs.ctype
['RA---TAN-SIP', 'DEC--TAN-SIP']

Unfortunately the PV1_5 header keyword (and probably other PV*_* keywords) cause an error when trying to do any transforms, so I couldn't test further. But this must be a separate issue.

@mdboom

mdboom commented Jun 5, 2012

Copy link
Copy Markdown
Contributor

Ok. I'll merge this. Please file another issue if you have problems regarding the PV*_* keywords as you investigate further.

mdboom added a commit that referenced this pull request Jun 5, 2012
bug: astropy.wcs.WCS() constructor adds newline to CTYPE1?
@mdboom
mdboom merged commit 3ee29cf into astropy:master Jun 5, 2012
@astrofrog

Copy link
Copy Markdown
Member

For info, this is causing a failure with Python 3 (see Jenkins)

@mdboom

mdboom commented Jun 6, 2012

Copy link
Copy Markdown
Contributor

Thanks. Fixed directly on master.

2 similar comments
@mdboom

mdboom commented Jun 6, 2012

Copy link
Copy Markdown
Contributor

Thanks. Fixed directly on master.

@mdboom

mdboom commented Jun 6, 2012

Copy link
Copy Markdown
Contributor

Thanks. Fixed directly on master.

keflavich pushed a commit to keflavich/astropy that referenced this pull request Oct 9, 2013
…s are read fine by io.fits, but break with wcslib (which has a less lenient parser). Add a unit test for this case.
keflavich pushed a commit to keflavich/astropy that referenced this pull request Oct 9, 2013
bug: astropy.wcs.WCS() constructor adds newline to CTYPE1?
astrofrog added a commit to astrofrog/astropy that referenced this pull request Jun 12, 2019
Replaced copy2 with copy in build_ext
jeffjennings pushed a commit to jeffjennings/astropy that referenced this pull request Jul 2, 2025
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.

3 participants