Skip to content

Commit

Permalink
Avoid writing garbage EQUINOX to FITS.
Browse files Browse the repository at this point in the history
For ICRS coordinates, EQUINOX is not required. Previously, we wrote a nonsense
number, but this confused some FITS readers (notably DS9 7.4). Now, we write
nothing.
  • Loading branch information
jdswinbank committed Feb 26, 2016
1 parent ce64d60 commit 81462b9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/formatters/TanWcsFormatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ afwForm::TanWcsFormatter::generatePropertySet(afwImg::TanWcs const& wcs) {
}

wcsProps->add("NAXIS", wcs._wcsInfo[0].naxis, "number of data axes");
wcsProps->add("EQUINOX", wcs._wcsInfo[0].equinox, "Equinox of coordinates");
// EQUINOX is "not relevant" (FITS definition, version 3.0, page 30) when
// dealing with ICRS, and may confuse readers. Don't write it.
if (strncmp(wcs._wcsInfo[0].radesys, "ICRS", 4) != 0) {
wcsProps->add("EQUINOX", wcs._wcsInfo[0].equinox, "Equinox of coordinates");
}
wcsProps->add("RADESYS", std::string(wcs._wcsInfo[0].radesys), "Coordinate system for equinox");
wcsProps->add("CRPIX1", wcs._wcsInfo[0].crpix[0], "WCS Coordinate reference pixel");
wcsProps->add("CRPIX2", wcs._wcsInfo[0].crpix[1], "WCS Coordinate reference pixel");
Expand Down
6 changes: 5 additions & 1 deletion src/formatters/WcsFormatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ afwForm::WcsFormatter::generatePropertySet(afwImg::Wcs const& wcs) {
assert(wcs._wcsInfo); // default ctor is private, so an uninitialized Wcs should not exist in the wild

wcsProps->add("NAXIS", wcs._wcsInfo[0].naxis, "number of data axes");
wcsProps->add("EQUINOX", wcs._wcsInfo[0].equinox, "Equinox of coordinates");
// EQUINOX is "not relevant" (FITS definition, version 3.0, page 30) when
// dealing with ICRS, and may confuse readers. Don't write it.
if (strncmp(wcs._wcsInfo[0].radesys, "ICRS", 4) != 0) {
wcsProps->add("EQUINOX", wcs._wcsInfo[0].equinox, "Equinox of coordinates");
}
wcsProps->add("RADESYS", std::string(wcs._wcsInfo[0].radesys), "Coordinate system for equinox");
wcsProps->add("CRPIX1", wcs._wcsInfo[0].crpix[0], "WCS Coordinate reference pixel");
wcsProps->add("CRPIX2", wcs._wcsInfo[0].crpix[1], "WCS Coordinate reference pixel");
Expand Down
15 changes: 15 additions & 0 deletions tests/wcs1.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ def refIsSameSkySystem(wcs1, wcs2):
wcs2 = makeWcs(coordSys=coordSys2, equinox=equinox2)
self.assertEqual(refIsSameSkySystem(wcs, wcs2), wcs.isSameSkySystem(wcs2))

def testIcrsEquinox(self):
"""Check that EQUINOX is not written to FITS for ICRS coordinates"""
def checkEquinoxHeader(coordSysName, writeEquinox):
coordSys = getattr(afwCoord, coordSysName)
for dummyWcs in (makeWcs(coordSys=coordSys), afwImage.TanWcs.cast(makeWcs(coordSys=coordSys))):
dummyWcs = afwImage.TanWcs.cast(makeWcs(coordSys=coordSys))
dummyExposure = afwImage.ExposureF()
dummyExposure.setWcs(dummyWcs)
with utilsTests.getTempFilePath(".fits") as tmpFile:
dummyExposure.writeFits(tmpFile)
metadata = afwImage.readMetadata(tmpFile)
self.assertEqual(metadata.get("RADESYS"), coordSysName)
self.assertTrue(("EQUINOX" in metadata.names()) == writeEquinox)
checkEquinoxHeader("ICRS", False)
checkEquinoxHeader("FK5", True)

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Expand Down

0 comments on commit 81462b9

Please sign in to comment.