1__all__ = (
"displayReconstructedCmodel",
"displayReconstrucedCmodelMpl",
2 "buildCModelImages",
"reconstructCModel")
5import matplotlib.pyplot
as plt
14 """ Display an image, the Cmodel, and residuals
19 Exposure object that contains the source which was modeled
21 Record object which contains the measurements made on the source
22 config : `lsst.meas.modelfit.CModel(SingleFrame/Forced)Config`
23 Configuration object of the CModel plugin used in the measurement
25 display : `str`, optional
26 Display
in which to render the data, may be mpl
for matplotlib
or afw
27 for afwDisplay, defaults to mpl
32 If the display backend specified
is not implemented
37 elif display ==
"afw":
38 raise NotImplementedError(
"The afw display backend is not yet "
41 raise NotImplementedError(
"The display backend '{}' is not a supported"
46 """ Display an image, the Cmodel, and residuals using matplotlib
51 Exposure object that contains the source which was modeled
53 Record object which contains the measurements made on the source
54 config : `lsst.meas.modelfit.CModel(SingleFrame/Forced)Config`
55 Configuration object of the CModel plugin used in the measurement
62 subImMin = subImage.array.min()
63 subImMax = subImage.array.max()
66 devResidual = subImage.array-devIm.array
67 expResidual = subImage.array-expIm.array
68 jointResidual = subImage.array-jointIm.array
69 residualList = (devResidual, expResidual, jointResidual)
71 differences = [(x.max()-x.max())
for x
in residualList]
72 maxDifferenceIndex = np.argmax(differences)
73 resImMin = residualList[maxDifferenceIndex].
min()
74 resImMax = residualList[maxDifferenceIndex].
max()
77 fig, axes = plt.subplots(3, 3, sharex=
'col', sharey=
'row', figsize=(8, 5))
78 fig.subplots_adjust(left=0.25, right=0.8)
79 lCBar = fig.add_axes([0.1, 0.15, 0.05, 0.7])
80 rCBar = fig.add_axes([0.85, 0.15, 0.05, 0.7])
84 axes[i, 0].imshow(subImage.array, vmin=subImMin, vmax=subImMax)
87 axes[0, 1].imshow(devIm.array, vmin=subImMin, vmax=subImMax)
88 axes[0, 2].imshow(devResidual, vmin=resImMin, vmax=resImMax, cmap=
"BrBG")
91 axes[1, 1].imshow(expIm.array, vmin=subImMin, vmax=subImMax)
92 axes[1, 2].imshow(expResidual, vmin=resImMin, vmax=resImMax, cmap=
"BrBG")
95 axes[2, 1].imshow(jointIm.array, vmin=subImMin, vmax=subImMax)
96 axes[2, 2].imshow(jointResidual, vmin=resImMin, vmax=resImMax, cmap=
"BrBG")
98 axes[0, 0].set_title(
"Image")
99 axes[0, 1].set_title(
"Model")
100 axes[0, 2].set_title(
'Residuals')
102 axes[0, 0].set_ylabel(
"Dev")
103 axes[1, 0].set_ylabel(
"Exp")
104 axes[2, 0].set_ylabel(
"Joint")
106 fig.colorbar(axes[0, 0].get_images()[0], lCBar)
107 lCBar.yaxis.set_ticks_position(
'left')
108 fig.colorbar(axes[maxDifferenceIndex, 2].get_images()[0], rCBar)
114 """ Create Images out of the CModel for the given record
119 Exposure object that contains the source which was modeled
121 Record object which contains the measurements made on the source
122 config : `lsst.meas.modelfit.CModel(SingleFrame/Forced)Config`
123 Configuration object of the CModel plugin used in the measurement
128 subImage : `lsst.afw.image.ImageD`
129 Sub image of the original data taken
from a region defined by the
130 bounding box of the footprint
for the object defined
in the given
132 devIm : `lsst.afw.image.ImageD`
133 Image created
from the dev component of the CModel
for the supplied
134 record at the same pixel locations
as subImage
135 expIm: `lsst.afw.image.ImageD`
136 Image created
from the exp component of the CModel
for the supplied
137 record at the same pixel locations
as subImage
139 Image created
from the joint fit of the dev
and exp components of the
140 CModel
for the supplied record at the same pixel locations
as subImage
145 footBBox = record.getFootprint().getBBox()
146 subImage = afwImage.ImageD(exposure.getImage().convertD(), footBBox)
150 record.schema[config.psfName])
151 psfApprox = record.get(shapeletPsfKey)
154 devIm = afwImage.ImageD(footBBox)
155 dev = dev.convolve(psfApprox)
156 dev.evaluate().addToImage(devIm)
159 expIm = afwImage.ImageD(footBBox)
160 exp = exp.convolve(psfApprox)
161 exp.evaluate().addToImage(expIm)
164 jointIm = afwImage.ImageD(footBBox)
165 jointDev = jointDev.convolve(psfApprox)
166 jointExp = jointExp.convolve(psfApprox)
167 jointDev.evaluate().addToImage(jointIm)
168 jointExp.evaluate().addToImage(jointIm)
170 return subImage, devIm, expIm, jointIm
174 """ Reconstruct the CModel for the given record
179 Exposure object that contains the source which was modeled
181 Record object which contains the measurements made on the source
182 config : `lsst.meas.modelfit.CModel(SingleFrame/Forced)Config`
183 Configuration object of the CModel plugin used in the measurement
189 Multi-component shapelet model of the dev component of CModel
191 Multi-component shapelet model fo the exp component of CModel
193 Multi-component shapelet model of the dev component of CModel jointly
194 fit
with the exp component
196 Multi-component shapelet model of the exp component of Cmodel jointly
197 fit
with the dev component
201 center = record.getCentroid()
202 position = exposure.getWcs().pixelToSky(center)
203 measSys = measMod.UnitSystem(exposure)
204 approxFlux = record.get(
"base_PsfFlux_instFlux")
205 fitSys = measMod.UnitSystem(position, exposure.getPhotoCalib(), approxFlux)
206 fitSysToMeasSys = measMod.LocalUnitTransform(
Point2D(0, 0), fitSys, measSys)
209 ctrl = config.makeControl()
210 baseName =
"modelfit_CModel"
211 nonlinearKeys = [
"{}_{{model}}_nonlinear_{p}".
format(baseName, p=p)
213 fixedKeys = [
"{}_{{model}}_fixed_{p}".
format(baseName, p=p)
215 fluxKey =
"{}_{{model}}_instFlux".
format(baseName)
219 apCorr = record.get(
"{}_apCorr".
format(baseName))
221 print(
"Warning, problem retrieving aperture correction, using a value"
226 devNonLinearParams = np.array([record.get(key.format(model=
"dev"))
227 for key
in nonlinearKeys])
228 devFixedParams = np.array([record.get(key.format(model=
"dev"))
229 for key
in fixedKeys])
230 devAmp = np.array([record.get(fluxKey.format(model=
"dev"))])
232 devShapelet = ctrl.dev.getModel().makeShapeletFunction(devNonLinearParams,
235 devShapelet.transformInPlace(fitSysToMeasSys.geometric)
238 expNonLinearParams = np.array([record.get(key.format(model=
"exp"))
239 for key
in nonlinearKeys])
240 expFixedParams = np.array([record.get(key.format(model=
"exp"))
241 for key
in fixedKeys])
242 expAmp = np.array([record.get(fluxKey.format(model=
"exp"))])
244 expShapelet = ctrl.exp.getModel().makeShapeletFunction(expNonLinearParams,
247 expShapelet.transformInPlace(fitSysToMeasSys.geometric)
250 fracDev = record.get(
"{}_fracDev".
format(baseName))
251 jointFlux = np.array([record.get(
"{}_instFlux".
format(baseName))])
253 devJointShapelet = ctrl.dev.getModel()\
254 .makeShapeletFunction(devNonLinearParams, jointFlux*fracDev,
256 devJointShapelet.transformInPlace(fitSysToMeasSys.geometric)
258 expJointShapelet = ctrl.exp.getModel()\
259 .makeShapeletFunction(expNonLinearParams, jointFlux*(1-fracDev),
261 expJointShapelet.transformInPlace(fitSysToMeasSys.geometric)
263 return devShapelet, expShapelet, devJointShapelet, expJointShapelet
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Record class that contains measurements made on a single exposure.
A multi-scale shapelet function.
Class that maps MultiShapeletFunction objects to fields in afw::table objects.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Point< double, 2 > Point2D
def buildCModelImages(exposure, record, config)
def reconstructCModel(exposure, record, config)
def displayReconstructedCmodel(exposure, record, config, display="mpl")
def displayReconstrucedCmodelMpl(exposure, record, config)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)