22"""Gen3 Butler Formatters for Dark Energy Camera raw data.
26import astro_metadata_translator
30from lsst.obs.base
import FitsRawFormatterBase
32from .
import DarkEnergyCamera
34__all__ = (
"DarkEnergyCameraRawFormatter",
"DarkEnergyCameraCPCalibFormatter")
39detector_to_hdu = {25: 1, 26: 2, 27: 3, 32: 4, 33: 5, 34: 6, 19: 7, 20: 8, 13: 9,
40 14: 10, 8: 11, 4: 12, 39: 13, 40: 14, 45: 15, 46: 16, 51: 17, 56: 18, 21: 19,
41 22: 20, 23: 21, 24: 22, 17: 23, 18: 24, 15: 25, 16: 26, 9: 27, 10: 28, 11: 29,
42 12: 30, 5: 31, 6: 32, 7: 33, 1: 34, 2: 35, 3: 36, 35: 37, 36: 38, 37: 39,
43 38: 40, 28: 41, 29: 42, 30: 43, 31: 44, 41: 45, 42: 46, 43: 47, 44: 48, 49: 49,
44 50: 50, 47: 51, 48: 52, 52: 53, 53: 54, 54: 55, 55: 56, 57: 57, 58: 58, 59: 59,
45 60: 60, 61: 61, 62: 62, 72: 63, 71: 64, 64: 65, 63: 66, 73: 67, 74: 68, 70: 69,
51 translatorClass = astro_metadata_translator.DecamTranslator
52 filterDefinitions = DarkEnergyCamera.filterDefinitions
60 return DarkEnergyCamera().getCamera()[id]
63 """Scan through a file for the HDU containing data from one detector.
68 The file to search through.
70 The detector id to search for.
75 The index of the HDU
with the requested data.
77 The metadata read
from the header
for that detector id.
82 Raised
if detectorId
is not found
in any of the file HDUs
84 log = logging.getLogger("lsst.obs.decam.DarkEnergyCameraRawFormatter")
85 log.debug(
"Did not find detector=%s at expected HDU=%s in %s: scanning through all HDUs.",
86 detectorId, detector_to_hdu[detectorId], filename)
90 for i
in range(1, fitsData.countHdus()):
92 metadata = fitsData.readMetadata()
93 if metadata[
'CCDNUM'] == detectorId:
96 raise ValueError(f
"Did not find detectorId={detectorId} as CCDNUM in any HDU of {filename}.")
99 """Determine the correct HDU number for a given detector id.
104 The detector id to search for.
109 The index of the HDU
with the requested data.
111 The metadata read
from the header
for that detector id.
116 Raised
if detectorId
is not found
in any of the file HDUs
118 filename = self.fileDescriptor.location.path
120 index = detector_to_hdu[detectorId]
122 if metadata[
'CCDNUM'] != detectorId:
124 return self.
_scanHdus(filename, detectorId)
127 fitsData.setHdu(index)
128 return index, metadata
131 return self.
_scanHdus(filename, detectorId)
133 def readMetadata(self):
134 index, metadata = self.
_determineHDU(self.dataId[
'detector'])
135 astro_metadata_translator.fix_header(metadata)
139 index, metadata = self.
_determineHDU(self.dataId[
'detector'])
140 return lsst.afw.image.ImageI(self.fileDescriptor.location.path, index)
144 """DECam Community Pipeline calibrations (bias, dark, flat, fringe) are
145 multi-extension FITS files with detector=index+1.
149 """The HDU to read is the same as the detector number."""
150 filename = self.fileDescriptor.location.path
152 if metadata[
'CCDNUM'] != detectorId:
153 msg = f
"Found CCDNUM={metadata['CCDNUM']} instead of {detectorId} in {filename} HDU={detectorId}."
154 raise ValueError(msg)
155 return detectorId, metadata
159 return lsst.afw.image.ImageF(self.fileDescriptor.location.path, index)
An exception thrown when problems are found when reading or writing FITS files.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Class for storing ordered metadata with comments.
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.