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-27832: Fatal errors from astro_metadata_translator in DECam #45

Merged
merged 2 commits into from
Dec 3, 2020
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
4 changes: 3 additions & 1 deletion python/astro_metadata_translator/translators/decam.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,15 @@ def to_detector_name(self):
return name[1:]

@classmethod
def fix_header(cls, header, obsid, filename=None):
def fix_header(cls, header, instrument, obsid, filename=None):
"""Fix DECam headers.

Parameters
----------
header : `dict`
The header to update. Updates are in place.
instrument : `str`
The name of the instrument.
obsid : `str`
Unique observation identifier associated with this header.
Will always be provided.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_decam.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_decam_translator(self):
observation_type="zero",
observation_reason="unknown",
observing_day=20121211,
physical_filter="Y DECam c0005 10095.0 1130.0",
physical_filter="solid plate 0.0 0.0", # corrected value
pressure=777.0*u.hPa,
relative_humidity=38.0,
science_program="2012B-0416",
Expand Down
29 changes: 25 additions & 4 deletions tests/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def fix_header(cls, header, instrument, obsid, filename=None):
raise RuntimeError("Failure to work something out from header")


class NullDecamTranslator(DecamTranslator):
"""This is a DECam translator that doesn't do any fixes."""
name = None

@classmethod
def fix_header(cls, header, instrument, obsid, filename=None):
return False


class HeadersTestCase(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -327,22 +336,24 @@ def test_basic_fix_header(self):
self.assertEqual(header["DETECTOR"], "S3-111_107419-8-3")

# First fix header but using no search path (should work as no-op)
fixed = fix_header(header)
fixed = fix_header(header, translator_class=NullDecamTranslator)
self.assertFalse(fixed)

# Now using the test corrections directory
fixed = fix_header(header, search_path=os.path.join(TESTDIR, "data", "corrections"))
fixed = fix_header(header, search_path=os.path.join(TESTDIR, "data", "corrections"),
translator_class=NullDecamTranslator)
self.assertTrue(fixed)
self.assertEqual(header["DETECTOR"], "NEW-ID")

# Now with a corrections directory that has bad YAML in it
with self.assertLogs(level="WARN"):
fixed = fix_header(header, search_path=os.path.join(TESTDIR, "data", "bad_corrections"))
fixed = fix_header(header, search_path=os.path.join(TESTDIR, "data", "bad_corrections"),
translator_class=NullDecamTranslator)
self.assertFalse(fixed)

# Test that fix_header of unknown header is allowed
header = {"SOMETHING": "UNKNOWN"}
fixed = fix_header(header)
fixed = fix_header(header, translator_class=NullDecamTranslator)
self.assertFalse(fixed)

def test_hsc_fix_header(self):
Expand All @@ -365,6 +376,16 @@ def test_hsc_fix_header(self):
self.assertFalse(fixed)
self.assertEqual(header["DATA-TYP"], "FLAT")

def test_decam_fix_header(self):
"""Check that one of the known DECam corrections is being applied
properly."""

# This header is a bias (zero) with an erroneous Y filter
header = read_test_file("fitsheader-decam-0160496.yaml", dir=os.path.join(TESTDIR, "data"))
fixed = fix_header(header, translator_class=DecamTranslator)
self.assertTrue(fixed)
self.assertEqual(header["FILTER"], "solid plate 0.0 0.0")

def test_translator_fix_header(self):
"""Check that translator classes can fix headers."""

Expand Down