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
38 """Abstract base class for reading and writing raw data to and from 49 """`~astro_metadata_translator.MetadataTranslator` to translate 50 metadata header to `~astro_metadata_translator.ObservationInfo`. 54 _observationInfo =
None 59 """`~lsst.obs.base.FilterDefinitions`, defining the filters for this 65 """Read just the image component of the Exposure. 69 image : `~lsst.afw.image.Image` 70 In-memory image component. 72 return lsst.afw.image.ImageU(self.fileDescriptor.location.path)
75 """Read just the mask component of the Exposure. 77 May return None (as the default implementation does) to indicate that 78 there is no mask information to be extracted (at least not trivially) 79 from the raw data. This will prohibit direct reading of just the mask, 80 and set the mask of the full Exposure to zeros. 84 mask : `~lsst.afw.image.Mask` 85 In-memory mask component. 90 """Read just the variance component of the Exposure. 92 May return None (as the default implementation does) to indicate that 93 there is no variance information to be extracted (at least not 94 trivially) from the raw data. This will prohibit direct reading of 95 just the variance, and set the variance of the full Exposure to zeros. 99 image : `~lsst.afw.image.Image` 100 In-memory variance component. 105 """Boolean to determine if the exposure is thought to be on the sky. 110 Returns `True` if the observation looks like it was taken on the 111 sky. Returns `False` if this observation looks like a calibration 116 If there is tracking RA/Dec information associated with the 117 observation it is assumed that the observation is on sky. 118 Currently the observation type is not checked. 125 """Remove metadata entries that are parsed into components. 134 """Construct a VisitInfo from metadata. 138 visitInfo : `~lsst.afw.image.VisitInfo` 139 Structured metadata about the observation. 141 return MakeRawVisitInfoViaObsInfo.observationInfo2visitInfo(self.
observationInfo)
145 """Return the detector that acquired this raw exposure. 150 The identifying number of the detector to get. 154 detector : `~lsst.afw.cameraGeom.Detector` 155 The detector associated with that ``id``. 157 raise NotImplementedError(
"Must be implemented by subclasses.")
160 """Create a SkyWcs from information about the exposure. 162 If VisitInfo is not None, use it and the detector to create a SkyWcs, 163 otherwise return the metadata-based SkyWcs (always created, so that 164 the relevant metadata keywords are stripped). 168 visitInfo : `~lsst.afw.image.VisitInfo` 169 The information about the telescope boresight and camera 170 orientation angle for this exposure. 171 detector : `~lsst.afw.cameraGeom.Detector` 172 The detector used to acquire this exposure. 176 skyWcs : `~lsst.afw.geom.SkyWcs` 177 Reversible mapping from pixel coordinates to sky coordinates. 182 Raised if there is an error generating the SkyWcs, chained from the 183 lower-level exception if available. 191 log = lsst.log.Log.getLogger(
"fitsRawFormatter")
192 if visitInfo
is None:
193 msg =
"No VisitInfo; cannot access boresight information. Defaulting to metadata-based SkyWcs." 197 "See warnings in log messages for details.")
203 def _createSkyWcsFromMetadata(self):
204 """Create a SkyWcs from the FITS header metadata in an Exposure. 208 skyWcs: `lsst.afw.geom.SkyWcs`, or None 209 The WCS that was created from ``self.metadata``, or None if that 210 creation fails due to invalid metadata. 217 return lsst.afw.geom.makeSkyWcs(self.metadata, strip=
True)
218 except TypeError
as e:
219 log = lsst.log.Log.getLogger(
"fitsRawFormatter")
220 log.warn(
"Cannot create a valid WCS from metadata: %s", e.args[0])
224 """Construct a Filter from metadata. 228 filter : `~lsst.afw.image.Filter` 229 Object that identifies the filter for this image. 234 Raised if the physical filter was not registered via 235 `~lsst.afw.image.utils.defineFilter`. 240 """Read the image, mask, or variance component of an Exposure. 244 component : `str`, optional 245 Component to read from the file. Always one of "image", 246 "variance", or "mask". 250 image : `~lsst.afw.image.Image` or `~lsst.afw.image.Mask` 251 In-memory image, variance, or mask component. 253 if component ==
"image":
255 elif component ==
"mask":
257 elif component ==
"variance":
261 """Read a component held by ExposureInfo. 263 The implementation provided by FitsRawFormatter provides only "wcs" 264 and "visitInfo". When adding support for other components, subclasses 265 should delegate to `super()` for those and update `readFull` with 270 component : `str`, optional 271 Component to read from the file. 275 obj : component-dependent 276 In-memory component object. 278 if component ==
"filter":
280 elif component ==
"visitInfo":
282 elif component ==
"wcs":
285 return self.
makeWcs(visitInfo, detector)
289 """Read the full Exposure object. 293 parameters : `dict`, optional 294 If specified, a dictionary of slicing parameters that overrides 295 those in the `fileDescriptor` attribute. 299 exposure : `~lsst.afw.image.Exposure` 300 Complete in-memory exposure. 302 from lsst.afw.image
import makeExposure, makeMaskedImage
303 full = makeExposure(makeMaskedImage(self.
readImage()))
308 if variance
is not None:
309 full.setVariance(variance)
311 info = full.getInfo()
314 info.setWcs(self.
makeWcs(info.getVisitInfo(), info.getDetector()))
317 full.setMetadata(self.metadata)
321 """Write a Python object to a file. 325 inMemoryDataset : `object` 326 The Python object to store. 331 The `URI` where the primary file is stored. 333 raise NotImplementedError(
"Raw data cannot be `put`.")
337 """The `~astro_metadata_translator.ObservationInfo` extracted from 338 this file's metadata (`~astro_metadata_translator.ObservationInfo`,
def createInitialSkyWcs(visitInfo, detector, flipX=False)