22 __all__ = (
"FitsRawFormatterBase",)
24 from abc
import ABCMeta, abstractmethod
26 from lsst.daf.butler.formatters.fitsExposureFormatter
import FitsExposureFormatter
30 """Abstract base class for reading and writing raw data to and from 33 Subclasses must provide implementations of `readImage` and 34 `makeRawVisitInfo`. Other methods may also be overridden to provide 35 additional components (most default to `None`). 40 """Read just the image component of the Exposure. 44 fileDescriptor : `FileDescriptor` 45 Identifies the file to read and parameters to be used for reading. 49 image : `~lsst.afw.image.Image` 50 In-memory image component. 52 raise NotImplementedError(
"Must be implemented by subclasses.")
55 """Read just the mask component of the Exposure. 57 May return None (as the default implementation does) to indicate that 58 there is no mask information to be extracted (at least not trivially) 59 from the raw data. This will prohibit direct reading of just the mask, 60 and set the mask of the full Exposure to zeros. 64 fileDescriptor : `FileDescriptor` 65 Identifies the file to read and parameters to be used for reading. 69 mask : `~lsst.afw.image.Mask` 70 In-memory mask component. 75 """Read just the variance component of the Exposure. 77 May return None (as the default implementation does) to indicate that 78 there is no variance information to be extracted (at least not 79 trivially) from the raw data. This will prohibit direct reading of 80 just the variance, and set the variance of the full Exposure to zeros. 84 fileDescriptor : `FileDescriptor` 85 Identifies the file to read and parameters to be used for reading. 89 image : `~lsst.afw.image.Image` 90 In-memory variance component. 95 """Remove metadata entries that are parsed into components. 99 metadata : `~lsst.daf.base.PropertyList` 100 Header metadata, to be modified in-place. 107 """Construct a VisitInfo from metadata. 111 metadata : `~lsst.daf.base.PropertyList` 112 Header metadata. May be modified in-place. 116 visitInfo : `~lsst.afw.image.VisitInfo` 117 Structured metadata about the observation. 119 raise NotImplementedError(
"Must be implemented by subclasses.")
122 """Construct a SkyWcs from metadata. 126 metadata : `~lsst.daf.base.PropertyList` 127 Header metadata. May be modified in-place. 131 wcs : `~lsst.afw.geom.SkyWcs` 132 Reversible mapping from pixel coordinates to sky coordinates. 134 from lsst.afw.geom
import makeSkyWcs
135 return makeSkyWcs(metadata, strip=
True)
138 """Construct a Filter from metadata. 142 metadata : `~lsst.daf.base.PropertyList` 143 Header metadata. May be modified in-place. 147 filter : `~lsst.afw.image.Filter` 148 Object that identifies the filter for this image. 150 raise NotImplementedError(
"Must be implemented by subclasses.")
153 """Read the image, mask, or variance component of an Exposure. 157 fileDescriptor : `FileDescriptor` 158 Identifies the file to read and parameters to be used for reading. 159 component : `str`, optional 160 Component to read from the file. Always one of "image", 161 "variance", or "mask". 165 image : `~lsst.afw.image.Image` or `~lsst.afw.image.Mask` 166 In-memory image, variance, or mask component. 168 if component ==
"image":
170 elif component ==
"mask":
171 return self.
readMask(fileDescriptor)
172 elif component ==
"variance":
176 """Read a component held by ExposureInfo. 178 The implementation provided by FitsRawFormatter provides only "wcs" 179 and "visitInfo". When adding support for other components, subclasses 180 should delegate to `super()` for those and update `readFull` with 185 fileDescriptor : `FileDescriptor` 186 Identifies the file to read and parameters to be used for reading. 187 component : `str`, optional 188 Component to read from the file. 192 obj : component-dependent 193 In-memory component object. 195 if component ==
"filter":
196 return self.
makeFilter(self.readMetadata(fileDescriptor))
197 elif component ==
"visitInfo":
199 elif component ==
"wcs":
200 return self.
makeWcs(self.readMetadata(fileDescriptor))
203 def readFull(self, fileDescriptor, parameters=None):
204 """Read the full Exposure object. 208 fileDescriptor : `FileDescriptor` 209 Identifies the file to read and parameters to be used for reading. 210 parameters : `dict`, optional 211 If specified a dictionary of slicing parameters that overrides 212 those in ``fileDescriptor`. 216 exposure : `~lsst.afw.image.Exposure` 217 Complete in-memory exposure. 219 from lsst.afw.image
import makeExposure, makeMaskedImage
220 full = makeExposure(makeMaskedImage(self.
readImage(fileDescriptor)))
221 mask = self.
readMask(fileDescriptor)
225 if variance
is not None:
226 full.setVariance(variance)
227 metadata = self.readMetadata(fileDescriptor)
228 info = full.getInfo()
229 info.setWcs(self.
makeWcs(metadata))
235 full.setMetadata(metadata)
238 def write(self, inMemoryDataset, fileDescriptor):
239 """Write a Python object to a file. 243 inMemoryDataset : `object` 244 The Python object to store. 245 fileDescriptor : `FileDescriptor` 246 Identifies the file to read, type to read it into and parameters 247 to be used for reading. 252 The `URI` where the primary file is stored. 254 raise NotImplementedError(
"Raw data cannot be `put`.")