22 __all__ = (
"FitsRawFormatterBase",)
24 from abc
import ABCMeta, abstractmethod
26 from astro_metadata_translator
import ObservationInfo
30 from lsst.daf.butler
import FileDescriptor
31 from lsst.daf.butler.formatters.fitsExposureFormatter
import FitsExposureFormatter
39 """Abstract base class for reading and writing raw data to and from 48 def fromMetadata(cls, metadata, obsInfo=None, storageClass=None, location=None):
49 """Construct a possibly-limited formatter from known metadata. 53 metadata : `lsst.daf.base.PropertyList` 54 Raw header metadata, with any fixes (see 55 `astro_metadata_translator.fix_header`) applied but nothing 57 obsInfo : `astro_metadata_translator.ObservationInfo`, optional 58 Structured information already extracted from ``metadata``. 59 If not provided, will be read from ``metadata`` on first use. 60 storageClass : `lsst.daf.butler.StorageClass`, optional 61 StorageClass for this file. If not provided, the formatter will 62 only support `makeWcs`, `makeVisitInfo`, `makeFilter`, and other 63 operations that operate purely on metadata and not the actual file. 64 location : `lsst.daf.butler.Location`, optional. 65 Location of the file. If not provided, the formatter will only 66 support `makeWcs`, `makeVisitInfo`, `makeFilter`, and other 67 operations that operate purely on metadata and not the actual file. 71 formatter : `FitsRawFormatterBase` 72 An instance of ``cls``. 74 self = cls(FileDescriptor(location, storageClass))
82 """`~astro_metadata_translator.MetadataTranslator` to translate 83 metadata header to `~astro_metadata_translator.ObservationInfo`. 87 _observationInfo =
None 92 """`~lsst.obs.base.FilterDefinitions`, defining the filters for this 98 """Read just the image component of the Exposure. 102 image : `~lsst.afw.image.Image` 103 In-memory image component. 105 return lsst.afw.image.ImageU(self.fileDescriptor.location.path)
108 """Read just the mask component of the Exposure. 110 May return None (as the default implementation does) to indicate that 111 there is no mask information to be extracted (at least not trivially) 112 from the raw data. This will prohibit direct reading of just the mask, 113 and set the mask of the full Exposure to zeros. 117 mask : `~lsst.afw.image.Mask` 118 In-memory mask component. 123 """Read just the variance component of the Exposure. 125 May return None (as the default implementation does) to indicate that 126 there is no variance information to be extracted (at least not 127 trivially) from the raw data. This will prohibit direct reading of 128 just the variance, and set the variance of the full Exposure to zeros. 132 image : `~lsst.afw.image.Image` 133 In-memory variance component. 138 """Boolean to determine if the exposure is thought to be on the sky. 143 Returns `True` if the observation looks like it was taken on the 144 sky. Returns `False` if this observation looks like a calibration 149 If there is tracking RA/Dec information associated with the 150 observation it is assumed that the observation is on sky. 151 Currently the observation type is not checked. 158 """Remove metadata entries that are parsed into components. 167 """Construct a VisitInfo from metadata. 171 visitInfo : `~lsst.afw.image.VisitInfo` 172 Structured metadata about the observation. 174 return MakeRawVisitInfoViaObsInfo.observationInfo2visitInfo(self.
observationInfo)
178 """Return the detector that acquired this raw exposure. 183 The identifying number of the detector to get. 187 detector : `~lsst.afw.cameraGeom.Detector` 188 The detector associated with that ``id``. 190 raise NotImplementedError(
"Must be implemented by subclasses.")
193 """Create a SkyWcs from information about the exposure. 195 If VisitInfo is not None, use it and the detector to create a SkyWcs, 196 otherwise return the metadata-based SkyWcs (always created, so that 197 the relevant metadata keywords are stripped). 201 visitInfo : `~lsst.afw.image.VisitInfo` 202 The information about the telescope boresight and camera 203 orientation angle for this exposure. 204 detector : `~lsst.afw.cameraGeom.Detector` 205 The detector used to acquire this exposure. 209 skyWcs : `~lsst.afw.geom.SkyWcs` 210 Reversible mapping from pixel coordinates to sky coordinates. 215 Raised if there is an error generating the SkyWcs, chained from the 216 lower-level exception if available. 224 log = lsst.log.Log.getLogger(
"fitsRawFormatter")
225 if visitInfo
is None:
226 msg =
"No VisitInfo; cannot access boresight information. Defaulting to metadata-based SkyWcs." 230 "See warnings in log messages for details.")
236 def _createSkyWcsFromMetadata(self):
237 """Create a SkyWcs from the FITS header metadata in an Exposure. 241 skyWcs: `lsst.afw.geom.SkyWcs`, or None 242 The WCS that was created from ``self.metadata``, or None if that 243 creation fails due to invalid metadata. 250 return lsst.afw.geom.makeSkyWcs(self.metadata, strip=
True)
251 except TypeError
as e:
252 log = lsst.log.Log.getLogger(
"fitsRawFormatter")
253 log.warn(
"Cannot create a valid WCS from metadata: %s", e.args[0])
257 """Construct a Filter from metadata. 261 filter : `~lsst.afw.image.Filter` 262 Object that identifies the filter for this image. 267 Raised if the physical filter was not registered via 268 `~lsst.afw.image.utils.defineFilter`. 273 """Read the image, mask, or variance component of an Exposure. 277 component : `str`, optional 278 Component to read from the file. Always one of "image", 279 "variance", or "mask". 283 image : `~lsst.afw.image.Image` or `~lsst.afw.image.Mask` 284 In-memory image, variance, or mask component. 286 if component ==
"image":
288 elif component ==
"mask":
290 elif component ==
"variance":
294 """Read a component held by ExposureInfo. 296 The implementation provided by FitsRawFormatter provides only "wcs" 297 and "visitInfo". When adding support for other components, subclasses 298 should delegate to `super()` for those and update `readFull` with 303 component : `str`, optional 304 Component to read from the file. 308 obj : component-dependent 309 In-memory component object. 311 if component ==
"filter":
313 elif component ==
"visitInfo":
315 elif component ==
"wcs":
318 return self.
makeWcs(visitInfo, detector)
322 """Read the full Exposure object. 326 parameters : `dict`, optional 327 If specified, a dictionary of slicing parameters that overrides 328 those in the `fileDescriptor` attribute. 332 exposure : `~lsst.afw.image.Exposure` 333 Complete in-memory exposure. 335 from lsst.afw.image
import makeExposure, makeMaskedImage
336 full = makeExposure(makeMaskedImage(self.
readImage()))
341 if variance
is not None:
342 full.setVariance(variance)
344 info = full.getInfo()
347 info.setWcs(self.
makeWcs(info.getVisitInfo(), info.getDetector()))
350 full.setMetadata(self.metadata)
354 """Write a Python object to a file. 358 inMemoryDataset : `object` 359 The Python object to store. 364 The `URI` where the primary file is stored. 366 raise NotImplementedError(
"Raw data cannot be `put`.")
370 """The `~astro_metadata_translator.ObservationInfo` extracted from 371 this file's metadata (`~astro_metadata_translator.ObservationInfo`,
def createInitialSkyWcs(visitInfo, detector, flipX=False)