22 __all__ = (
"FitsRawFormatterBase",)
24 from abc
import ABCMeta, abstractmethod
25 from deprecated.sphinx
import deprecated
27 from astro_metadata_translator
import ObservationInfo
32 from lsst.daf.butler
import FileDescriptor
35 from .formatters.fitsExposure
import FitsExposureFormatter
36 from .makeRawVisitInfoViaObsInfo
import MakeRawVisitInfoViaObsInfo
37 from .utils
import createInitialSkyWcsFromBoresight, InitialSkyWcsError
41 """Abstract base class for reading and writing raw data to and from
47 """Control whether the WCS is flipped in the X-direction (`bool`)"""
55 def fromMetadata(cls, metadata, obsInfo=None, storageClass=None, location=None):
56 """Construct a possibly-limited formatter from known metadata.
60 metadata : `lsst.daf.base.PropertyList`
61 Raw header metadata, with any fixes (see
62 `astro_metadata_translator.fix_header`) applied but nothing
64 obsInfo : `astro_metadata_translator.ObservationInfo`, optional
65 Structured information already extracted from ``metadata``.
66 If not provided, will be read from ``metadata`` on first use.
67 storageClass : `lsst.daf.butler.StorageClass`, optional
68 StorageClass for this file. If not provided, the formatter will
69 only support `makeWcs`, `makeVisitInfo`, `makeFilter`, and other
70 operations that operate purely on metadata and not the actual file.
71 location : `lsst.daf.butler.Location`, optional.
72 Location of the file. If not provided, the formatter will only
73 support `makeWcs`, `makeVisitInfo`, `makeFilter`, and other
74 operations that operate purely on metadata and not the actual file.
78 formatter : `FitsRawFormatterBase`
79 An instance of ``cls``.
81 self =
cls(FileDescriptor(location, storageClass))
89 """`~astro_metadata_translator.MetadataTranslator` to translate
90 metadata header to `~astro_metadata_translator.ObservationInfo`.
94 _observationInfo =
None
99 """`~lsst.obs.base.FilterDefinitions`, defining the filters for this
105 """Read just the image component of the Exposure.
109 image : `~lsst.afw.image.Image`
110 In-memory image component.
112 return lsst.afw.image.ImageU(self.fileDescriptor.location.path)
115 """Read just the mask component of the Exposure.
117 May return None (as the default implementation does) to indicate that
118 there is no mask information to be extracted (at least not trivially)
119 from the raw data. This will prohibit direct reading of just the mask,
120 and set the mask of the full Exposure to zeros.
124 mask : `~lsst.afw.image.Mask`
125 In-memory mask component.
130 """Read just the variance component of the Exposure.
132 May return None (as the default implementation does) to indicate that
133 there is no variance information to be extracted (at least not
134 trivially) from the raw data. This will prohibit direct reading of
135 just the variance, and set the variance of the full Exposure to zeros.
139 image : `~lsst.afw.image.Image`
140 In-memory variance component.
145 """Boolean to determine if the exposure is thought to be on the sky.
150 Returns `True` if the observation looks like it was taken on the
151 sky. Returns `False` if this observation looks like a calibration
156 If there is tracking RA/Dec information associated with the
157 observation it is assumed that the observation is on sky.
158 Currently the observation type is not checked.
165 """Remove metadata entries that are parsed into components.
174 """Construct a VisitInfo from metadata.
178 visitInfo : `~lsst.afw.image.VisitInfo`
179 Structured metadata about the observation.
181 return MakeRawVisitInfoViaObsInfo.observationInfo2visitInfo(self.
observationInfoobservationInfo)
185 """Return the detector that acquired this raw exposure.
190 The identifying number of the detector to get.
194 detector : `~lsst.afw.cameraGeom.Detector`
195 The detector associated with that ``id``.
197 raise NotImplementedError(
"Must be implemented by subclasses.")
200 """Create a SkyWcs from information about the exposure.
202 If VisitInfo is not None, use it and the detector to create a SkyWcs,
203 otherwise return the metadata-based SkyWcs (always created, so that
204 the relevant metadata keywords are stripped).
208 visitInfo : `~lsst.afw.image.VisitInfo`
209 The information about the telescope boresight and camera
210 orientation angle for this exposure.
211 detector : `~lsst.afw.cameraGeom.Detector`
212 The detector used to acquire this exposure.
216 skyWcs : `~lsst.afw.geom.SkyWcs`
217 Reversible mapping from pixel coordinates to sky coordinates.
222 Raised if there is an error generating the SkyWcs, chained from the
223 lower-level exception if available.
232 if visitInfo
is None:
233 msg =
"No VisitInfo; cannot access boresight information. Defaulting to metadata-based SkyWcs."
237 "See warnings in log messages for details.")
241 visitInfo.getBoresightRotAngle(),
246 """Class method to make a raw sky WCS from boresight and detector.
250 boresight : `lsst.geom.SpherePoint`
251 The ICRS boresight RA/Dec
252 orientation : `lsst.geom.Angle`
253 The rotation angle of the focal plane on the sky.
254 detector : `lsst.afw.cameraGeom.Detector`
255 Where to get the camera geomtry from.
259 skyWcs : `~lsst.afw.geom.SkyWcs`
260 Reversible mapping from pixel coordinates to sky coordinates.
264 def _createSkyWcsFromMetadata(self):
265 """Create a SkyWcs from the FITS header metadata in an Exposure.
269 skyWcs: `lsst.afw.geom.SkyWcs`, or None
270 The WCS that was created from ``self.metadata``, or None if that
271 creation fails due to invalid metadata.
279 except TypeError
as e:
281 log.warn(
"Cannot create a valid WCS from metadata: %s", e.args[0])
285 @deprecated(reason="Replaced with makeFilterLabel. Will be removed after v22.", category=FutureWarning)
287 """Construct a Filter from metadata.
291 filter : `~lsst.afw.image.Filter`
292 Object that identifies the filter for this image.
297 Raised if the physical filter was not registered via
298 `~lsst.afw.image.utils.defineFilter`.
304 """Construct a FilterLabel from metadata.
308 filter : `~lsst.afw.image.FilterLabel`
309 Object that identifies the filter for this image.
316 """Read a component held by the Exposure.
320 component : `str`, optional
321 Component to read from the file.
322 parameters : `dict`, optional
323 If specified, a dictionary of slicing parameters that
324 overrides those in ``fileDescriptor``.
328 obj : component-dependent
329 In-memory component object.
334 Raised if the requested component cannot be handled.
336 if component ==
"image":
338 elif component ==
"mask":
340 elif component ==
"variance":
342 elif component ==
"filter":
344 elif component ==
"filterLabel":
346 elif component ==
"visitInfo":
348 elif component ==
"wcs":
351 return self.
makeWcsmakeWcs(visitInfo, detector)
355 """Read the full Exposure object.
359 parameters : `dict`, optional
360 If specified, a dictionary of slicing parameters that overrides
361 those in the `fileDescriptor` attribute.
365 exposure : `~lsst.afw.image.Exposure`
366 Complete in-memory exposure.
374 if variance
is not None:
375 full.setVariance(variance)
377 info = full.getInfo()
380 info.setWcs(self.
makeWcsmakeWcs(info.getVisitInfo(), info.getDetector()))
383 full.setMetadata(self.
metadatametadata)
387 """Read the SkyWcs stored in the un-modified raw FITS WCS header keys.
392 """Write a Python object to a file.
396 inMemoryDataset : `object`
397 The Python object to store.
402 The `URI` where the primary file is stored.
404 raise NotImplementedError(
"Raw data cannot be `put`.")
408 """The `~astro_metadata_translator.ObservationInfo` extracted from
409 this file's metadata (`~astro_metadata_translator.ObservationInfo`,
413 location = self.fileDescriptor.location
414 path = location.path
if location
is not None else None
A group of labels for a filter in an exposure or coadd.
static Log getLogger(Log const &logger)
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
std::shared_ptr< Exposure< ImagePixelT, MaskPixelT, VariancePixelT > > makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, std::shared_ptr< geom::SkyWcs const > wcs=std::shared_ptr< geom::SkyWcs const >())
A function to return an Exposure of the correct type (cf.
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT >> image, typename std::shared_ptr< Mask< MaskPixelT >> mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT >> variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.
def createInitialSkyWcsFromBoresight(boresight, orientation, detector, flipX=False)