From 9969898117c0befb4b8fbd7cb2740ed153e16a4d Mon Sep 17 00:00:00 2001 From: Nadia Dencheva Date: Sat, 13 Aug 2016 09:20:14 -0400 Subject: fix for refframe=OTHER --- stwcs/tests/test_hstwcs.py | 15 +++++++++++++++ stwcs/wcsutil/hstwcs.py | 27 +++++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 stwcs/tests/test_hstwcs.py (limited to 'stwcs') diff --git a/stwcs/tests/test_hstwcs.py b/stwcs/tests/test_hstwcs.py new file mode 100644 index 0000000..8a4a9ba --- /dev/null +++ b/stwcs/tests/test_hstwcs.py @@ -0,0 +1,15 @@ +from __future__ import absolute_import, division, print_function +from astropy.io import fits +from ..wcsutil import hstwcs + + +def test_radesys(): + phdr = fits.PrimaryHDU().header + phdr['refframe'] = 'icrs' + assert hstwcs.determine_refframe(phdr) == 'ICRS' + phdr['refframe'] = 'gsc1' + assert hstwcs.determine_refframe(phdr) == 'FK5' + phdr['refframe'] = 'other' + assert hstwcs.determine_refframe(phdr) is None + phdr['refframe'] = ' ' + assert hstwcs.determine_refframe(phdr) is None diff --git a/stwcs/wcsutil/hstwcs.py b/stwcs/wcsutil/hstwcs.py index 27f6467..aeaa43f 100644 --- a/stwcs/wcsutil/hstwcs.py +++ b/stwcs/wcsutil/hstwcs.py @@ -137,7 +137,8 @@ class HSTWCS(WCS): self.instrument = instrument_name # Set the correct reference frame refframe = determine_refframe(hdr0) - ehdr['RADESYS'] = refframe + if refframe is not None: + ehdr['RADESYS'] = refframe WCS.__init__(self, ehdr, fobj=phdu, minerr=self.minerr, key=self.wcskey) @@ -960,20 +961,34 @@ adaptive=False, detect_divergence=False, quiet=False) def determine_refframe(phdr): """ - Determine the reference frame in standard FITS WCS terms. + Determine the reference frame in standard FITS WCS. + + This is necessary for two reasons: + - The reference frame in HST images is stored not in RADESYS (FITS standard) but in REFFRAME. + - REFFRAME is in the primary header, while the rest of the WCS keywords are in the + extension header. + + The values of REFFRAME are populated from the APT template where observers are + given three options: GSC1 (corresponds to FK5), ICRS or OTHER. + In the case of "OTHER", we leave this to wcslib which has a default of ICRS. Parameters ---------- phdr : `astropy.io.fits.Header` Primary Header of an HST observation - In HST images the reference frame is recorded in the primary extension as REFFRAME. - Values are "GSC1" which means FK5 or ICRS (for GSC2 observations). + Returns + ------- + refframe : str or None + One of the FITS WCS standard reference frames. + """ try: - refframe = phdr['REFFRAME'] + refframe = phdr['REFFRAME'].upper() except KeyError: - refframe = " " + refframe = None if refframe == "GSC1": refframe = "FK5" + elif refframe != "ICRS": + refframe = None return refframe -- cgit