22 """Support for assembling and disassembling afw Exposures."""
28 from lsst.daf.butler
import CompositeAssembler
33 EXPOSURE_COMPONENTS =
set((
"image",
"variance",
"mask",
"wcs",
"psf"))
34 EXPOSURE_INFO_COMPONENTS =
set((
"apCorrMap",
"coaddInputs",
"photoCalib",
"metadata",
35 "filter",
"transmissionCurve",
"visitInfo"))
37 def _groupRequestedComponents(self):
38 """Group requested components into top level and ExposureInfo.
43 Components associated with the top level Exposure.
45 Components associated with the ExposureInfo
50 There are components defined in the storage class that are not
51 expected by this assembler.
53 requested =
set(self.storageClass.components.keys())
58 raise ValueError(
"Asking for unrecognized component: {}".
format(unknown))
62 return expItems, expInfoItems
65 """Get a component from an Exposure
69 composite : `~lsst.afw.image.Exposure`
70 `Exposure` to access component.
72 Name of component to retrieve.
77 The component. Can be None.
82 The component can not be found.
87 if hasattr(composite,
"getInfo"):
91 composite = composite.getInfo()
94 raise AttributeError(
"Do not know how to retrieve component {} from {}".
format(componentName,
98 """Extract all non-None components from a composite.
103 Composite from which to extract components.
108 Non-None components extracted from the composite, indexed by the
109 component name as derived from the `self.storageClass`.
117 components.update(infoComps)
121 """Disassemble an afw Exposure.
123 This implementation attempts to extract components from the parent
124 by looking for attributes of the same name or getter methods derived
125 from the component name.
129 composite : `~lsst.afw.image.Exposure`
130 `Exposure` composite object consisting of components to be
136 `dict` with keys matching the components defined in
137 `self.storageClass` and values being `DatasetComponent` instances
138 describing the component.
143 A requested component can not be found in the parent using generic
146 The parent object does not match the supplied `self.storageClass`.
148 if not self.storageClass.validateInstance(composite):
149 raise TypeError(
"Unexpected type mismatch between parent and StorageClass"
150 " ({} != {})".
format(
type(composite), self.storageClass.pytype))
156 fromExposure = super().
disassemble(composite, subset=expItems)
157 components.update(fromExposure)
160 subset=expInfoItems, override=composite.getInfo())
161 components.update(fromExposureInfo)
166 """Construct an Exposure from components.
171 All the components from which to construct the Exposure.
176 exposure : `~lsst.afw.image.Exposure`
182 Some supplied components are not recognized.
184 components = components.copy()
185 maskedImageComponents = {}
186 hasMaskedImage =
False
187 for component
in (
"image",
"variance",
"mask"):
189 if component
in components:
190 hasMaskedImage =
True
191 value = components.pop(component)
192 maskedImageComponents[component] = value
195 if "wcs" in components:
196 wcs = components.pop(
"wcs")
198 pytype = self.storageClass.pytype
203 if not isinstance(exposure, pytype):
204 raise RuntimeError(
"Unexpected type created in assembly;"
205 " was {} expected {}".
format(
type(exposure), pytype))
213 exposure.setPsf(components.pop(
"psf",
None))
214 exposure.setPhotoCalib(components.pop(
"photoCalib",
None))
216 info = exposure.getInfo()
217 if "visitInfo" in components:
218 info.setVisitInfo(components.pop(
"visitInfo"))
219 info.setApCorrMap(components.pop(
"apCorrMap",
None))
220 info.setCoaddInputs(components.pop(
"coaddInputs",
None))
221 info.setMetadata(components.pop(
"metadata",
None))
225 raise ValueError(
"The following components were not understood:"
231 """Modify the in-memory dataset using the supplied parameters,
232 returning a possibly new object.
236 inMemoryDataset : `object`
237 Object to modify based on the parameters.
238 parameters : `dict`, optional
239 Parameters to apply. Values are specific to the parameter.
240 Supported parameters are defined in the associated
241 `StorageClass`. If no relevant parameters are specified the
242 inMemoryDataset will be return unchanged.
246 inMemoryDataset : `object`
247 Updated form of supplied in-memory dataset, after parameters
251 understood = (
"bbox",
"origin")
252 use = self.storageClass.filterParameters(parameters, subset=understood)
254 inMemoryDataset = inMemoryDataset.subset(**use)
256 return inMemoryDataset