22 __all__ = (
"FitsRawFormatterBase",)
24 from abc
import ABCMeta, abstractmethod
26 from astro_metadata_translator
import ObservationInfo
30 from lsst.daf.butler.formatters.fitsExposureFormatter
import FitsExposureFormatter
39 """Abstract base class for reading and writing raw data to and from 46 """`~astro_metadata_translator.MetadataTranslator` to translate 47 metadata header to `~astro_metadata_translator.ObservationInfo`. 51 _observationInfo =
None 54 """Read just the image component of the Exposure. 58 image : `~lsst.afw.image.Image` 59 In-memory image component. 61 return lsst.afw.image.ImageU(self.fileDescriptor.location.path)
64 """Read just the mask component of the Exposure. 66 May return None (as the default implementation does) to indicate that 67 there is no mask information to be extracted (at least not trivially) 68 from the raw data. This will prohibit direct reading of just the mask, 69 and set the mask of the full Exposure to zeros. 73 mask : `~lsst.afw.image.Mask` 74 In-memory mask component. 79 """Read just the variance component of the Exposure. 81 May return None (as the default implementation does) to indicate that 82 there is no variance information to be extracted (at least not 83 trivially) from the raw data. This will prohibit direct reading of 84 just the variance, and set the variance of the full Exposure to zeros. 88 image : `~lsst.afw.image.Image` 89 In-memory variance component. 94 """Remove metadata entries that are parsed into components. 103 """Construct a VisitInfo from metadata. 107 visitInfo : `~lsst.afw.image.VisitInfo` 108 Structured metadata about the observation. 110 return MakeRawVisitInfoViaObsInfo.observationInfo2visitInfo(self.
observationInfo)
114 """Return the detector that acquired this raw exposure. 119 The identifying number of the detector to get. 123 detector : `~lsst.afw.cameraGeom.Detector` 124 The detector associated with that ``id``. 126 raise NotImplementedError(
"Must be implemented by subclasses.")
129 """Create a SkyWcs from information about the exposure. 131 If VisitInfo is not None, use it and the detector to create a SkyWcs, 132 otherwise return the metadata-based SkyWcs (always created, so that 133 the relevant metadata keywords are stripped). 137 visitInfo : `~lsst.afw.image.VisitInfo` 138 The information about the telescope boresight and camera 139 orientation angle for this exposure. 140 detector : `~lsst.afw.cameraGeom.Detector` 141 The detector used to acquire this exposure. 145 skyWcs : `~lsst.afw.geom.SkyWcs` 146 Reversible mapping from pixel coordinates to sky coordinates. 151 Raised if there is an error generating the SkyWcs, chained from the 152 lower-level exception if available. 156 log = lsst.log.Log.getLogger(
"fitsRawFormatter")
157 if visitInfo
is None:
158 msg =
"No VisitInfo; cannot access boresight information. Defaulting to metadata-based SkyWcs." 162 "See warnings in log messages for details.")
168 def _createSkyWcsFromMetadata(self):
169 """Create a SkyWcs from the FITS header metadata in an Exposure. 173 skyWcs: `lsst.afw.geom.SkyWcs`, or None 174 The WCS that was created from ``self.metadata``, or None if that 175 creation fails due to invalid metadata. 178 return lsst.afw.geom.makeSkyWcs(self.metadata, strip=
True)
180 log = lsst.log.Log.getLogger(
"fitsRawFormatter")
181 log.warn(
"Cannot create a valid WCS from metadata: %s", e.args[0])
185 """Construct a Filter from metadata. 189 filter : `~lsst.afw.image.Filter` 190 Object that identifies the filter for this image. 192 raise NotImplementedError(
"Must be implemented by subclasses.")
195 """Read the image, mask, or variance component of an Exposure. 199 component : `str`, optional 200 Component to read from the file. Always one of "image", 201 "variance", or "mask". 205 image : `~lsst.afw.image.Image` or `~lsst.afw.image.Mask` 206 In-memory image, variance, or mask component. 208 if component ==
"image":
210 elif component ==
"mask":
212 elif component ==
"variance":
216 """Read a component held by ExposureInfo. 218 The implementation provided by FitsRawFormatter provides only "wcs" 219 and "visitInfo". When adding support for other components, subclasses 220 should delegate to `super()` for those and update `readFull` with 225 component : `str`, optional 226 Component to read from the file. 230 obj : component-dependent 231 In-memory component object. 233 if component ==
"filter":
235 elif component ==
"visitInfo":
237 elif component ==
"wcs":
240 return self.
makeWcs(visitInfo, detector)
244 """Read the full Exposure object. 248 parameters : `dict`, optional 249 If specified, a dictionary of slicing parameters that overrides 250 those in the `fileDescriptor` attribute. 254 exposure : `~lsst.afw.image.Exposure` 255 Complete in-memory exposure. 257 from lsst.afw.image
import makeExposure, makeMaskedImage
258 full = makeExposure(makeMaskedImage(self.
readImage()))
263 if variance
is not None:
264 full.setVariance(variance)
266 info = full.getInfo()
269 info.setWcs(self.
makeWcs(info.getVisitInfo(), info.getDetector()))
272 full.setMetadata(self.metadata)
276 """Write a Python object to a file. 280 inMemoryDataset : `object` 281 The Python object to store. 286 The `URI` where the primary file is stored. 288 raise NotImplementedError(
"Raw data cannot be `put`.")
292 """The `~astro_metadata_translator.ObservationInfo` extracted from 293 this file's metadata (`~astro_metadata_translator.ObservationInfo`,
def createInitialSkyWcs(visitInfo, detector, flipX=False)