Skip to content

Commit

Permalink
Add new visitInfo fields and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Sep 6, 2022
1 parent 2ce158c commit ac4a970
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/lsst/obs/base/makeRawVisitInfoViaObsInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ def observationInfo2visitInfo(obsInfo, log=None):
argDict["instrumentLabel"] = obsInfo.instrument
if obsInfo.focus_z is not None:
argDict["focusZ"] = obsInfo.focus_z.to_value("mm")
if obsInfo.observation_type is not None:
argDict["observationType"] = obsInfo.observation_type
if obsInfo.science_program is not None:
argDict["scienceProgram"] = obsInfo.science_program
if obsInfo.observation_reason is not None:
argDict["observationReason"] = obsInfo.observation_reason
if obsInfo.object is not None:
argDict["object"] = obsInfo.object
if obsInfo.has_simulated_content is not None:
argDict["hasSimulatedContent"] = obsInfo.has_simulated_content

# VisitInfo uses the middle of the observation for the date
if obsInfo.datetime_begin is not None and obsInfo.datetime_end is not None:
Expand Down
31 changes: 31 additions & 0 deletions tests/test_makeRawVisitInfoViaObsInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import astropy.units as u
import lsst.afw.image
import numpy as np
from astro_metadata_translator import FitsTranslator, ObservationInfo, StubTranslator
from astropy.time import Time
from lsst.daf.base import DateTime
Expand All @@ -33,6 +34,11 @@ class NewTranslator(FitsTranslator, StubTranslator):
_trivial_map = {
"exposure_time": "EXPTIME",
"exposure_id": "EXP-ID",
"observation_type": "OBSTYPE",
"science_program": "PROGRAM",
"observation_reason": "REASON",
"object": "OBJECT",
"has_simulated_content": "SIMULATE",
}

def to_location(self):
Expand Down Expand Up @@ -71,6 +77,11 @@ def setUp(self):
"FOCUSZ": self.focus_z,
"EXTRA1": "an abitrary key and value",
"EXTRA2": 5,
"OBSTYPE": "test type",
"PROGRAM": "test program",
"REASON": "test reason",
"OBJECT": "test object",
"SIMULATE": True,
}

def testMakeRawVisitInfoViaObsInfo(self):
Expand All @@ -94,6 +105,26 @@ def testMakeRawVisitInfoViaObsInfo(self):
self.assertEqual(visitInfo.getInstrumentLabel(), "SomeCamera")
# Check focusZ with default value from astro_metadata_translator
self.assertEqual(visitInfo.getFocusZ(), self.focus_z.to_value("mm"))
self.assertEqual(visitInfo.observationType, "test type")
self.assertEqual(visitInfo.scienceProgram, "test program")
self.assertEqual(visitInfo.observationReason, "test reason")
self.assertEqual(visitInfo.object, "test object")
self.assertEqual(visitInfo.hasSimulatedContent, True)

def testMakeRawVisitInfoViaObsInfo_empty(self):
"""Test that empty metadata fields are set to appropriate defaults."""
maker = MakeTestableVisitInfo()
# Capture the warnings from StubTranslator since they are
# confusing to people but irrelevant for the test.
with self.assertWarns(UserWarning):
with self.assertLogs(level="WARNING"):
visitInfo = maker({})
self.assertTrue(np.isnan(visitInfo.focusZ))
self.assertEqual(visitInfo.observationType, "")
self.assertEqual(visitInfo.scienceProgram, "")
self.assertEqual(visitInfo.observationReason, "")
self.assertEqual(visitInfo.object, "")
self.assertEqual(visitInfo.hasSimulatedContent, False)

def testObservationInfo2VisitInfo(self):

Expand Down

0 comments on commit ac4a970

Please sign in to comment.