def setUp(self): '''Create two calibs, one with a valid zero-point and one without. Use these to create two UnitSystem objects. ''' self.mag2Flux = lambda m: 10.0**(m/2.5) self.flux2Mag = lambda f: 2.5*np.log10(f) photoCalibNoZero = afwImage.PhotoCalib() photoCalibWithZero = afwImage.makePhotoCalibFromCalibZeroPoint(self.mag2Flux(25)) scale = 0.2 * geom.arcseconds wcs = afwGeom.makeSkyWcs(crpix=geom.Point2D(), crval=geom.SpherePoint(45.0, 45.0, geom.degrees), cdMatrix=afwGeom.makeCdMatrix(scale=scale)) self.unitNoZero = measModel.UnitSystem(wcs, photoCalibNoZero) self.unitWithZero = measModel.UnitSystem(wcs, photoCalibWithZero)
def setUp(self): '''Create two calibs, one with a valid zero-point and one without. Use these to create two UnitSystem objects. ''' self.mag2Flux = lambda m: 10.0**(m / 2.5) self.flux2Mag = lambda f: 2.5 * np.log10(f) calibNoZero = afwImage.Calib() calibWithZero = afwImage.Calib() calibWithZero.setFluxMag0(self.mag2Flux(25)) cdelt = (0.2 * afwGeom.arcseconds).asDegrees() position = afwCoord.IcrsCoord(45.0 * afwGeom.degrees, 45.0 * afwGeom.degrees) wcs = afwImage.makeWcs(position, afwGeom.Point2D(), cdelt, 0.0, 0.0, cdelt) self.unitNoZero = measModel.UnitSystem(wcs, calibNoZero) self.unitWithZero = measModel.UnitSystem(wcs, calibWithZero)
def reconstructCModel(exposure, record, config): """ Reconstruct the CModel for the given record Parameters ---------- exposure : `lsst.afw.image.Exposure` Exposure object that contains the source which was modeled record : `lsst.afw.table.SourceRecord` Record object which contains the measurements made on the source config : `lsst.meas.modelfit.CModel(SingleFrame/Forced)Config` Configuration object of the CModel plugin used in the measurement process Returns ------- devShapelet : `lsst.shapelet.MultiShapeletFunction` Multi-component shapelet model of the dev component of CModel expShapelet : `lsst.shapelet.MultiShapeletFunction` Multi-component shapelet model fo the exp component of CModel devJointShapelet : `lsst.shapelet.MultiShapeletFunction` Multi-component shapelet model of the dev component of CModel jointly fit with the exp component expJointShapelet : `lsst.shapelet.MultiShapeletFunction` Multi-component shapelet model of the exp component of Cmodel jointly fit with the dev component """ # build a unit system transformation object center = record.getCentroid() position = exposure.getWcs().pixelToSky(center) measSys = measMod.UnitSystem(exposure) approxFlux = record.get("base_PsfFlux_flux") fitSys = measMod.UnitSystem(position, exposure.getCalib(), approxFlux) fitSysToMeasSys = measMod.LocalUnitTransform(center, fitSys, measSys) # Build the Shapelet objects ctrl = config.makeControl() baseName = "modelfit_CModel" nonlinearKeys = [ "{}_{{model}}_nonlinear_{p}".format(baseName, p=p) for p in range(3) ] fixedKeys = [ "{}_{{model}}_fixed_{p}".format(baseName, p=p) for p in range(2) ] fluxKey = "{}_{{model}}_flux".format(baseName) # fetch the aperture corrections, if this fails set it to one try: apCorr = record.get("{}_apCorr".format(baseName)) except Exception: print("Warning, problem retrieving aperture correction, using a value" " of 1") apCorr = 1 # Get parameters for the dev model devNonLinearParams = np.array( [record.get(key.format(model="dev")) for key in nonlinearKeys]) devFixedParams = np.array( [record.get(key.format(model="dev")) for key in fixedKeys]) devAmp = np.array([record.get(fluxKey.format(model="dev"))]) devAmp /= apCorr devShapelet = ctrl.dev.getModel().makeShapeletFunction( devNonLinearParams, devAmp, devFixedParams) devShapelet.transformInPlace(fitSysToMeasSys.geometric) # Get parameters for the exp model expNonLinearParams = np.array( [record.get(key.format(model="exp")) for key in nonlinearKeys]) expFixedParams = np.array( [record.get(key.format(model="exp")) for key in fixedKeys]) expAmp = np.array([record.get(fluxKey.format(model="exp"))]) expAmp /= apCorr expShapelet = ctrl.exp.getModel().makeShapeletFunction( expNonLinearParams, expAmp, expFixedParams) expShapelet.transformInPlace(fitSysToMeasSys.geometric) # Get joint shapelet model fracDev = record.get("{}_fracDev".format(baseName)) jointFlux = np.array([record.get("{}_flux".format(baseName))]) jointFlux /= apCorr devJointShapelet = ctrl.dev.getModel()\ .makeShapeletFunction(devNonLinearParams, jointFlux*fracDev, devFixedParams) devJointShapelet.transformInPlace(fitSysToMeasSys.geometric) expJointShapelet = ctrl.exp.getModel()\ .makeShapeletFunction(expNonLinearParams, jointFlux*(1-fracDev), expFixedParams) expJointShapelet.transformInPlace(fitSysToMeasSys.geometric) return devShapelet, expShapelet, devJointShapelet, expJointShapelet