Skip to content

Commit

Permalink
Fix is_non_science_or_lab
Browse files Browse the repository at this point in the history
The logic was slightly wrong such that non-science observations
were triggering the failure mode.  This change includes two
new test headers from the future.
  • Loading branch information
timj committed Nov 4, 2019
1 parent 25e8ceb commit 11031db
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 1 deletion.
13 changes: 12 additions & 1 deletion python/lsst/obs/lsst/translators/latiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,21 @@ def is_non_science_or_lab(self):
KeyError
If this is a science observation and on the mountain.
"""
if is_non_science(self):
# Return without raising if this is not a science observation
# since the defaults are fine.
try:
# This will raise if it is a science observation
is_non_science(self)
return
except KeyError:
pass

# We are still in the lab, return and use the default
if not self._is_on_mountain():
return

# This is a science observation on the mountain so we should not
# use defaults
raise KeyError("Required key is missing and this is a mountain science observation")


Expand Down
88 changes: 88 additions & 0 deletions tests/headers/latiss-future-bad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# A header pretending to be in the future that must act like it
# is "on the mountain" but is bad because it is a "science" observation
# but has none of the associated RA/DEC headers.
SIMPLE: true
BITPIX: 32
NAXIS: 2
EXTEND: true
COMMENT:
- ' FITS (Flexible Image Transport System) format is defined in ''Astronomy'
- ' and Astrophysics'', volume 376, page 359; bibcode: 2001A&A...376..359H'
EXTNAME: Segment10
ORIGIN: LSST DM Header Service
DATE: '2020-03-29T16:57:40.064'
DATE-OBS: '2020-03-29T16:57:37.055'
DATE-END: '2020-03-29T16:57:37.055'
MJD: 58937.7067137073
MJD-OBS: 58937.7066788773
OBSID: AT_X_20200329_000022
GROUPID: 'ABCDEF'
OBSTYPE: 'science'
BUNIT: adu
TELESCOP: LSST AuxTelescope
INSTRUME: LATISS
OBSERVER: LSST
OBS-LONG: -70.749417
OBS-LAT: -30.244639
OBS-ELEV: 2663.0
OBSGEO-X: 1818938.94
OBSGEO-Y: -5208470.95
OBSGEO-Z: -3195172.08
RATEL: null
DECTEL: null
ROTPATEL: null
ROTCOORD: null
RA: null
DEC: null
ROTPA: null
HASTART: null
ELSTART: null
AZSTART: null
AMSTART: null
HAEND: null
ELEND: null
AZEND: null
AMEND: null
TELCODE: AT
CONTRLLR: null
DAYOBS: '20200329'
SEQNUM: 22
CCD_MANU: ITL
CCD_TYPE: 3800C
CCD_SERN: '20304'
LSST_NUM: ITL-3800C-098
SEQCKSUM: null
SEQNAME: null
REBNAME: null
CONTNUM: null
IMAGETAG: null
TEMP_SET: null
CCDTEMP: null
DETSIZE: '[1:4072,1:4000]'
OVERH: 64
OVERV: 48
PREH: 3
FILTER: null
FILTPOS: null
GRATING: null
GRATPOS: null
LINSTAGE: null
EXPTIME: null
DARKTIME: null
FILENAME: AT_X_20200329_000022.fits
HEADVER: ACCS_MCM/OCS_Bridge
XTENSION: IMAGE
NAXIS1: 576
NAXIS2: 2048
PCOUNT: 0
GCOUNT: 1
INHERIT: true
CHANNEL: 9
DATASEC: '[4:512,1:2000]'
DETSEC: '[509:1,1:2000]'
DTV1: 513
DTV2: 0
DTM1_1: -1.0
DTM2_2: 1.0
DTM1_2: 0
DTM2_1: 0
87 changes: 87 additions & 0 deletions tests/headers/latiss-future.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# A header pretending to be in the future that must act like it
# is "on the mountain"
SIMPLE: true
BITPIX: 32
NAXIS: 2
EXTEND: true
COMMENT:
- ' FITS (Flexible Image Transport System) format is defined in ''Astronomy'
- ' and Astrophysics'', volume 376, page 359; bibcode: 2001A&A...376..359H'
EXTNAME: Segment10
ORIGIN: LSST DM Header Service
DATE: '2020-03-29T16:57:40.064'
DATE-OBS: '2020-03-29T16:57:37.055'
DATE-END: '2020-03-29T16:57:37.055'
MJD: 58937.7067137073
MJD-OBS: 58937.7066788773
OBSID: AT_X_20200329_000022
GROUPID: 'AGROUPID'
OBSTYPE: 'bias'
BUNIT: adu
TELESCOP: LSST AuxTelescope
INSTRUME: LATISS
OBSERVER: LSST
OBS-LONG: -70.749417
OBS-LAT: -30.244639
OBS-ELEV: 2663.0
OBSGEO-X: 1818938.94
OBSGEO-Y: -5208470.95
OBSGEO-Z: -3195172.08
RATEL: null
DECTEL: null
ROTPATEL: null
ROTCOORD: null
RA: null
DEC: null
ROTPA: null
HASTART: null
ELSTART: null
AZSTART: null
AMSTART: null
HAEND: null
ELEND: null
AZEND: null
AMEND: null
TELCODE: AT
CONTRLLR: null
DAYOBS: '20200329'
SEQNUM: 22
CCD_MANU: ITL
CCD_TYPE: 3800C
CCD_SERN: '20304'
LSST_NUM: ITL-3800C-098
SEQCKSUM: null
SEQNAME: null
REBNAME: null
CONTNUM: null
IMAGETAG: null
TEMP_SET: null
CCDTEMP: null
DETSIZE: '[1:4072,1:4000]'
OVERH: 64
OVERV: 48
PREH: 3
FILTER: null
FILTPOS: null
GRATING: null
GRATPOS: null
LINSTAGE: null
EXPTIME: 0.0
DARKTIME: 0.0
FILENAME: AT_X_20200329_000022.fits
HEADVER: ACCS_MCM/OCS_Bridge
XTENSION: IMAGE
NAXIS1: 576
NAXIS2: 2048
PCOUNT: 0
GCOUNT: 1
INHERIT: true
CHANNEL: 9
DATASEC: '[4:512,1:2000]'
DETSEC: '[509:1,1:2000]'
DTV1: 513
DTV2: 0
DTM1_1: -1.0
DTM2_2: 1.0
DTM1_2: 0
DTM2_1: 0
35 changes: 35 additions & 0 deletions tests/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,38 @@ def test_latiss_translator(self):
temperature=None,
visit_id=2019032900022,
)),
("latiss-future.yaml",
dict(telescope="LSSTAuxTel",
instrument="LATISS",
boresight_rotation_coord="unknown",
dark_time=0.0*u.s,
detector_exposure_id=2020032900022,
detector_group="RXX",
detector_name="S00",
detector_num=0,
detector_serial="ITL-3800C-098",
exposure_id=2020032900022,
exposure_time=0.0*u.s,
object="UNKNOWN",
observation_id="AT_X_20200329_000022",
observation_type="bias",
physical_filter="NONE",
pressure=None,
relative_humidity=None,
science_program="unknown",
temperature=None,
visit_id=2020032900022,
)),
)
self.assertObservationInfoFromYaml("latiss-future.yaml", dir=self.datadir)
for filename, expected in test_data:
with self.subTest(f"Testing {filename}"):
self.assertObservationInfoFromYaml(filename, dir=self.datadir, **expected)

# This translation should fail
with self.assertRaises(KeyError):
self.assertObservationInfoFromYaml("latiss-future-bad.yaml", dir=self.datadir)

def test_imsim_translator(self):
test_data = (("imsim-bias-lsst_a_3010002_R11_S00.yaml",
dict(telescope="LSST",
Expand Down Expand Up @@ -470,6 +497,14 @@ def test_ucdcam_translator(self):
with self.subTest(f"Testing {filename}"):
self.assertObservationInfoFromYaml(filename, dir=self.datadir, **expected)

def test_checker(self):
filename = "latiss-future.yaml"
from astro_metadata_translator.tests import read_test_file
from astro_metadata_translator import ObservationInfo
header = read_test_file(filename, self.datadir)
obsInfo = ObservationInfo(header, pedantic=True)
self.assertTrue(obsInfo)


if __name__ == "__main__":
unittest.main()

0 comments on commit 11031db

Please sign in to comment.