Skip to content

Commit

Permalink
Update error handling of raw ingest to match base class
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Mar 16, 2021
1 parent 99a8f18 commit 4e0497d
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions python/lsst/obs/decam/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import re


from lsst.daf.butler import ButlerURI
from lsst.daf.butler import ButlerURI, Formatter
from astro_metadata_translator import fix_header, DecamTranslator
from lsst.afw.fits import readMetadata
from lsst.pipe.tasks.ingest import ParseTask, IngestTask, IngestArgumentParser
Expand All @@ -38,22 +38,33 @@ class DecamRawIngestTask(lsst.obs.base.RawIngestTask):
"""
def extractMetadata(self, filename: ButlerURI) -> RawFileData:
datasets = []
with filename.as_local() as local_file:
fitsData = lsst.afw.fits.Fits(local_file.ospath, 'r')
# NOTE: The primary header (HDU=0) does not contain detector data.
for i in range(1, fitsData.countHdus()):
fitsData.setHdu(i)
header = fitsData.readMetadata()
if header['CCDNUM'] > 62: # ignore the guide CCDs
continue
datasets.append(self._calculate_dataset_info(header, filename))

# The data model currently assumes that whilst multiple datasets
# can be associated with a single file, they must all share the
# same formatter.
instrument, formatterClass = self._determine_instrument_formatter(datasets[0].dataId, filename)
if instrument is None:
try:
with filename.as_local() as local_file:
fitsData = lsst.afw.fits.Fits(local_file.ospath, 'r')
# NOTE: The primary header (HDU=0) does not contain detector data.
for i in range(1, fitsData.countHdus()):
fitsData.setHdu(i)
header = fitsData.readMetadata()
if header['CCDNUM'] > 62: # ignore the guide CCDs
continue
datasets.append(self._calculate_dataset_info(header, filename))
except Exception as e:
self.log.debug("Problem extracting metadata from %s: %s", filename, e)
# Indicate to the caller that we failed to read.
# Do not try to ingest partial contents of file.
datasets = []
formatterClass = Formatter
instrument = None
self._on_metadata_failure(filename, e)
if self.config.failFast:
raise RuntimeError(f"Problem extracting metadata for file {filename}") from e
else:
# The data model currently assumes that whilst multiple datasets
# can be associated with a single file, they must all share the
# same formatter.
instrument, formatterClass = self._determine_instrument_formatter(datasets[0].dataId, filename)
if instrument is None:
datasets = []

self.log.debug(f"Found images for {len(datasets)} detectors in {filename}")
return RawFileData(datasets=datasets, filename=filename,
Expand Down

0 comments on commit 4e0497d

Please sign in to comment.