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

DM-20143: Convert blank keyword comments to normal FITS comments on read #473

Merged
merged 2 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/fits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,12 @@ void MetadataIterationFunctor::operator()(std::string const &key, std::string co
add(key, comment, "");
} else if (key == "COMMENT" && !(strip && boost::regex_match(comment, fitsDefinitionCommentRegex))) {
add(key, comment, "");
} else if (key.empty() && value.empty()) {
// This is a blank keyword comment. Since comments do not retain
// their position on read there is nothing to be gained by storing
// this in the PropertyList as a blank keyword. Therefore store
// them with the other comments.
add("COMMENT", comment, "");
} else if (value.empty()) {
// do nothing for empty values that are comments
// Otherwise write null value to PropertySet
Expand Down
1 change: 1 addition & 0 deletions tests/data/ticket20143.fits
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SIMPLE = T / file does conform to FITS standard BITPIX = 16 / number of bits per data pixel NAXIS = 0 / number of data axes EXTEND = T / FITS dataset may contain extensions COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H EXTNAME = 'PRIMARY ' ORIGIN = 'LSST DM Header Service' / FITS file originator ---- Date, night and basic image information ---- DATE = '2019-06-12T22:48:21.920' / Creation Date and Time of File DATE-OBS= '2019-06-12T22:48:18.841' / Date of the observation (image acquisitionDATE-BEG= '2019-06-12T22:48:18.841' / Time at the start of integration DATE-END= '2019-06-12T22:48:18.841' / end date of the observation MJD = 58646.9502536988 / Modified Julian Date that the file was written MJD-OBS = 58646.9502180671 / Modified Julian Date of observation MJD-BEG = 58646.9502180671 / Modified Julian Date derived from DATE-BEG MJD-END = 58646.9502180671 / Modified Julian Date derived from DATE-END OBSID = 'AT_O_20190612_000007' / ImageName from Camera StartIntergration GROUPID = 'bias_0001_0010' OBSTYPE = / BIAS, DARK, FLAT, OBJECT BUNIT = 'adu ' / Brightness units for pixel array ---- Telescope info, location, observer ---- TELESCOP= 'LSST AuxTelescope' / Telescope name INSTRUME= 'LATISS ' / Instrument used to obtain these data OBSERVER= 'LSST ' / Observer name(s) OBS-LONG= -70.749417 / [deg] Observatory east longitude OBS-LAT = -30.244639 / [deg] Observatory latitude OBS-ELEV= 2663. / [m] Observatory elevation OBSGEO-X= 1818938.94 / [m] X-axis Geocentric coordinate OBSGEO-Y= -5208470.95 / [m] Y-axis Geocentric coordinate OBSGEO-Z= -3195172.08 / [m] Z-axis Geocentric coordinate ---- Pointing info, etc. ---- RATEL = / Telescope RA of observation DECTEL = / Telescope DEC of observation ROTPATEL= / Telescope Rotation ROTCOORD= 'sky ' / Telescope Rotation Coordinates RA = / RA of Target DEC = / DEC of Target ROTPA = / Rotation angle relative to the sky (deg) HASTART = / [HH:MM:SS] Telescope hour angle at start ELSTART = / [deg] Telescope zenith distance at start AZSTART = / [deg] Telescope azimuth angle at start AMSTART = / Airmass at start HAEND = / [HH:MM:SS] Telescope hour angle at end ELEND = / [deg] Telescope zenith distance at end AZEND = / [deg] Telescope azimuth angle at end AMEND = / Airmass at end ---- Image-identifying used to build OBS-ID ---- TELCODE = 'AT ' / The code for the telecope CONTRLLR= / The controller (e.g. O for OCS, C for CCS) DAYOBS = '20190612' / The observation day as defined by image name SEQNUM = 7 / The sequence number from the image name ---- Information from Camera CCD_MANU= 'ITL ' / CCD Manufacturer CCD_TYPE= '3800C ' / CCD Model Number CCD_SERN= '20304 ' / Manufacturers? CCD Serial Number LSST_NUM= 'ITL-3800C-098' / LSST Assigned CCD Number SEQCKSUM= / Checksum of Sequencer SEQNAME = / SequenceName from Camera StartIntergration REBNAME = / Name of the REB CONTNUM = / CCD Controller (WREB) Serial Number IMAGETAG= / DAQ Image id TEMP_SET= / Temperature set point (deg C) CCDTEMP = -90.5990905761719 / Measured temperature (deg C) ---- Geometry from Camera ---- DETSIZE = '[1:4072,1:4000]' / Size of sensor OVERH = 64 / Over-scan pixels OVERV = 48 / Vert-overscan pix PREH = 3 / Pre-scan pixels ---- Filter/grating information ---- FILTER = / Name of the filter FILTPOS = / Filter position GRATING = / Name of the second disperser GRATPOS = / disperser position LINSPOS = / Linear Stage ---- Exposure-related information ---- EXPTIME = 0. / Exposure time in seconds SHUTTIME= 1.048 / Shutter exposure time in seconds DARKTIME= / Dark time in seconds ---- Header information ---- FILENAME= 'AT_O_20190612_000007.fits' / Original file name HEADVER = '0.9.7 ' / Version of header ---- Checksums ---- END
8 changes: 8 additions & 0 deletions tests/test_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ def testReadUndefined(self):
# was undefined
self.assertAlmostEqual(metadata.getScalar("DOM-WND"), 4.8)

def testReadBlankKeywordComment(self):
"""Read a header that uses blank keyword comments."""
testFile = os.path.join(testPath, "data", "ticket20143.fits")
metadata = lsst.afw.fits.readMetadata(testFile)

self.assertEqual("---- Checksums ----", metadata["COMMENT"])
self.assertNotIn("", metadata, "Check empty strings as keys")

def testIgnoreKeywords(self):
"""Check that certain keywords are ignored in read/write of headers"""
# May not appear at all in the FITS file (cfitsio doesn't write these by default)
Expand Down