22 """Support for assembling and disassembling afw Exposures."""
28 from lsst.daf.butler
import StorageClassDelegate
33 EXPOSURE_COMPONENTS =
set((
"image",
"variance",
"mask",
"wcs",
"psf"))
34 EXPOSURE_INFO_COMPONENTS =
set((
"apCorrMap",
"coaddInputs",
"photoCalib",
"metadata",
35 "filterLabel",
"transmissionCurve",
"visitInfo",
36 "detector",
"validPolygon",
"summaryStats"))
37 EXPOSURE_READ_COMPONENTS = {
"bbox",
"dimensions",
"xy0",
"filter"}
39 COMPONENT_MAP = {
"bbox":
"BBox",
"xy0":
"XY0"}
40 """Map component name to actual getter name."""
42 def _groupRequestedComponents(self):
43 """Group requested components into top level and ExposureInfo.
47 expComps : `set` [`str`]
48 Components associated with the top level Exposure.
49 expInfoComps : `set` [`str`]
50 Components associated with the ExposureInfo
55 There are components defined in the storage class that are not
56 expected by this assembler.
58 requested =
set(self.storageClass.components.keys())
63 raise ValueError(
"Asking for unrecognized component: {}".
format(unknown))
67 return expItems, expInfoItems
70 """Get a component from an Exposure
74 composite : `~lsst.afw.image.Exposure`
75 `Exposure` to access component.
77 Name of component to retrieve.
82 The component. Can be None.
87 The component can not be found.
93 if hasattr(composite,
"getInfo"):
97 composite = composite.getInfo()
100 raise AttributeError(
"Do not know how to retrieve component {} from {}".
format(componentName,
104 """Extract all non-None components from a composite.
109 Composite from which to extract components.
114 Non-None components extracted from the composite, indexed by the
115 component name as derived from the `self.storageClass`.
123 components.update(infoComps)
127 """Disassemble an afw Exposure.
129 This implementation attempts to extract components from the parent
130 by looking for attributes of the same name or getter methods derived
131 from the component name.
135 composite : `~lsst.afw.image.Exposure`
136 `Exposure` composite object consisting of components to be
142 `dict` with keys matching the components defined in
143 `self.storageClass` and values being `DatasetComponent` instances
144 describing the component.
149 A requested component can not be found in the parent using generic
152 The parent object does not match the supplied `self.storageClass`.
154 if not self.storageClass.validateInstance(composite):
155 raise TypeError(
"Unexpected type mismatch between parent and StorageClass"
156 " ({} != {})".
format(
type(composite), self.storageClass.pytype))
162 fromExposure = super().
disassemble(composite, subset=expItems)
163 components.update(fromExposure)
166 subset=expInfoItems, override=composite.getInfo())
167 components.update(fromExposureInfo)
172 """Construct an Exposure from components.
177 All the components from which to construct the Exposure.
182 exposure : `~lsst.afw.image.Exposure`
188 Some supplied components are not recognized.
190 components = components.copy()
191 maskedImageComponents = {}
192 hasMaskedImage =
False
193 for component
in (
"image",
"variance",
"mask"):
195 if component
in components:
196 hasMaskedImage =
True
197 value = components.pop(component)
198 maskedImageComponents[component] = value
201 if "wcs" in components:
202 wcs = components.pop(
"wcs")
204 pytype = self.storageClass.pytype
209 if not isinstance(exposure, pytype):
210 raise RuntimeError(
"Unexpected type created in assembly;"
211 " was {} expected {}".
format(
type(exposure), pytype))
219 exposure.setPsf(components.pop(
"psf",
None))
220 exposure.setPhotoCalib(components.pop(
"photoCalib",
None))
222 info = exposure.getInfo()
223 if "visitInfo" in components:
224 info.setVisitInfo(components.pop(
"visitInfo"))
225 info.setApCorrMap(components.pop(
"apCorrMap",
None))
226 info.setCoaddInputs(components.pop(
"coaddInputs",
None))
227 info.setMetadata(components.pop(
"metadata",
None))
228 info.setValidPolygon(components.pop(
"validPolygon",
None))
229 info.setDetector(components.pop(
"detector",
None))
230 info.setTransmissionCurve(components.pop(
"transmissionCurve",
None))
231 info.setSummaryStats(components.pop(
"summaryStats",
None))
234 info.setFilterLabel(components.pop(
"filterLabel",
None))
238 raise ValueError(
"The following components were not understood:"
244 """Modify the in-memory dataset using the supplied parameters,
245 returning a possibly new object.
249 inMemoryDataset : `object`
250 Object to modify based on the parameters.
251 parameters : `dict`, optional
252 Parameters to apply. Values are specific to the parameter.
253 Supported parameters are defined in the associated
254 `StorageClass`. If no relevant parameters are specified the
255 inMemoryDataset will be return unchanged.
259 inMemoryDataset : `object`
260 Updated form of supplied in-memory dataset, after parameters
264 understood = (
"bbox",
"origin")
265 use = self.storageClass.filterParameters(parameters, subset=understood)
267 inMemoryDataset = inMemoryDataset.subset(**use)
269 return inMemoryDataset
273 imageComponents = [
"mask",
"image",
"variance"]
275 "bbox": imageComponents,
276 "dimensions": imageComponents,
277 "xy0": imageComponents,
278 "filter": [
"filterLabel"],
280 forwarder = forwarderMap.get(readComponent)
281 if forwarder
is not None:
283 if c
in fromComponents:
285 raise ValueError(f
"Can not calculate read component {readComponent} from {fromComponents}")
dictionary EXPOSURE_READ_COMPONENTS
def disassemble(self, composite)
def getValidComponents(self, composite)
def _groupRequestedComponents(self)
str selectResponsibleComponent(cls, str readComponent, fromComponents)
def handleParameters(self, inMemoryDataset, parameters=None)
def getComponent(self, composite, componentName)
def assemble(self, components)
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 format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
daf::base::PropertyList * list
daf::base::PropertySet * set