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 50 """`~astro_metadata_translator.MetadataTranslator` to translate 51 metadata header to `~astro_metadata_translator.ObservationInfo`. 55 _observationInfo =
None 60 """`~lsst.obs.base.FilterDefinitions`, defining the filters for this 66 """Read just the image component of the Exposure. 70 image : `~lsst.afw.image.Image` 71 In-memory image component. 73 return lsst.afw.image.ImageU(self.fileDescriptor.location.path)
76 """Read just the mask component of the Exposure. 78 May return None (as the default implementation does) to indicate that 79 there is no mask information to be extracted (at least not trivially) 80 from the raw data. This will prohibit direct reading of just the mask, 81 and set the mask of the full Exposure to zeros. 85 mask : `~lsst.afw.image.Mask` 86 In-memory mask component. 91 """Read just the variance component of the Exposure. 93 May return None (as the default implementation does) to indicate that 94 there is no variance information to be extracted (at least not 95 trivially) from the raw data. This will prohibit direct reading of 96 just the variance, and set the variance of the full Exposure to zeros. 100 image : `~lsst.afw.image.Image` 101 In-memory variance component. 106 """Remove metadata entries that are parsed into components. 115 """Construct a VisitInfo from metadata. 119 visitInfo : `~lsst.afw.image.VisitInfo` 120 Structured metadata about the observation. 122 return MakeRawVisitInfoViaObsInfo.observationInfo2visitInfo(self.
observationInfo)
126 """Return the detector that acquired this raw exposure. 131 The identifying number of the detector to get. 135 detector : `~lsst.afw.cameraGeom.Detector` 136 The detector associated with that ``id``. 138 raise NotImplementedError(
"Must be implemented by subclasses.")
141 """Create a SkyWcs from information about the exposure. 143 If VisitInfo is not None, use it and the detector to create a SkyWcs, 144 otherwise return the metadata-based SkyWcs (always created, so that 145 the relevant metadata keywords are stripped). 149 visitInfo : `~lsst.afw.image.VisitInfo` 150 The information about the telescope boresight and camera 151 orientation angle for this exposure. 152 detector : `~lsst.afw.cameraGeom.Detector` 153 The detector used to acquire this exposure. 157 skyWcs : `~lsst.afw.geom.SkyWcs` 158 Reversible mapping from pixel coordinates to sky coordinates. 163 Raised if there is an error generating the SkyWcs, chained from the 164 lower-level exception if available. 168 log = lsst.log.Log.getLogger(
"fitsRawFormatter")
169 if visitInfo
is None:
170 msg =
"No VisitInfo; cannot access boresight information. Defaulting to metadata-based SkyWcs." 174 "See warnings in log messages for details.")
180 def _createSkyWcsFromMetadata(self):
181 """Create a SkyWcs from the FITS header metadata in an Exposure. 185 skyWcs: `lsst.afw.geom.SkyWcs`, or None 186 The WCS that was created from ``self.metadata``, or None if that 187 creation fails due to invalid metadata. 190 return lsst.afw.geom.makeSkyWcs(self.metadata, strip=
True)
192 log = lsst.log.Log.getLogger(
"fitsRawFormatter")
193 log.warn(
"Cannot create a valid WCS from metadata: %s", e.args[0])
197 """Construct a Filter from metadata. 201 filter : `~lsst.afw.image.Filter` 202 Object that identifies the filter for this image. 207 Raised if the physical filter was not registered via 208 `~lsst.afw.image.utils.defineFilter`. 213 """Read the image, mask, or variance component of an Exposure. 217 component : `str`, optional 218 Component to read from the file. Always one of "image", 219 "variance", or "mask". 223 image : `~lsst.afw.image.Image` or `~lsst.afw.image.Mask` 224 In-memory image, variance, or mask component. 226 if component ==
"image":
228 elif component ==
"mask":
230 elif component ==
"variance":
234 """Read a component held by ExposureInfo. 236 The implementation provided by FitsRawFormatter provides only "wcs" 237 and "visitInfo". When adding support for other components, subclasses 238 should delegate to `super()` for those and update `readFull` with 243 component : `str`, optional 244 Component to read from the file. 248 obj : component-dependent 249 In-memory component object. 251 if component ==
"filter":
253 elif component ==
"visitInfo":
255 elif component ==
"wcs":
258 return self.
makeWcs(visitInfo, detector)
262 """Read the full Exposure object. 266 parameters : `dict`, optional 267 If specified, a dictionary of slicing parameters that overrides 268 those in the `fileDescriptor` attribute. 272 exposure : `~lsst.afw.image.Exposure` 273 Complete in-memory exposure. 275 from lsst.afw.image
import makeExposure, makeMaskedImage
276 full = makeExposure(makeMaskedImage(self.
readImage()))
281 if variance
is not None:
282 full.setVariance(variance)
284 info = full.getInfo()
287 info.setWcs(self.
makeWcs(info.getVisitInfo(), info.getDetector()))
290 full.setMetadata(self.metadata)
294 """Write a Python object to a file. 298 inMemoryDataset : `object` 299 The Python object to store. 304 The `URI` where the primary file is stored. 306 raise NotImplementedError(
"Raw data cannot be `put`.")
310 """The `~astro_metadata_translator.ObservationInfo` extracted from 311 this file's metadata (`~astro_metadata_translator.ObservationInfo`,
def createInitialSkyWcs(visitInfo, detector, flipX=False)