30 CompareWarpAssembleCoaddTask)
31 from .mockObject
import MockObjectTask
32 from .mockObservation
import MockObservationTask
33 from .mockSelect
import MockSelectImagesTask
37 makeSkyMap = lsst.pex.config.ConfigurableField(
38 doc=
"SkyMap builder subtask",
41 mockObject = lsst.pex.config.ConfigurableField(
42 doc=
"Subtask that generates and draws the objects/sources in the mock images",
45 mockObservation = lsst.pex.config.ConfigurableField(
46 doc=
"Subtask that generates the Wcs, Psf, Calib, etc. of mock images",
47 target=MockObservationTask
49 coaddName = lsst.pex.config.Field(
50 doc=
"Coadd name used as a prefix for other datasets",
55 nObservations = lsst.pex.config.Field(
56 doc=
"Number of mock observations to generate.",
61 edgeBuffer = lsst.pex.config.Field(
62 doc=(
"Number of pixels by which to grow object bounding boxes when determining whether they land " 63 " completely on a generated image"),
69 def setupSkyMapPatches(self, nPatches=2, patchSize=400, pixelScale=0.2*lsst.afw.geom.arcseconds):
71 Set the nested [discrete] skymap config parameters such that the full tract 72 has nPatches x nPatches patches of the given size and pixel scale. 74 self.
makeSkyMap.skyMap[
'discrete'].patchInnerDimensions = [patchSize, patchSize]
75 self.
makeSkyMap.skyMap[
'discrete'].pixelScale = pixelScale.asArcseconds()
78 radius = (0.5 * nPatches - 0.49) * patchSize * pixelScale.asDegrees()
79 self.
makeSkyMap.skyMap[
'discrete'].radiusList = [radius]
83 self.
makeSkyMap.skyMap[
'discrete'].raList = [90.0]
84 self.
makeSkyMap.skyMap[
'discrete'].decList = [0.0]
85 self.
makeSkyMap.skyMap[
'discrete'].patchBorder = 10
86 self.
makeSkyMap.skyMap[
'discrete'].projection =
"TAN" 87 self.
makeSkyMap.skyMap[
'discrete'].tractOverlap = 0.0
92 """MockCoaddTask is a driver task for creating mock coadds. As opposed to more realistic 93 simulations, MockCoadd generates and uses extremely simple "toy" data that can be used to more 94 rigorously test the behavior of high-level task code because the expected results are 95 more easily predicted. In particular, calexps are generated directly from the truth catalog, 96 and contain only zero-noise stars that are created using the same Psf, Calib, and Wcs that will 97 be attached to the mock calexp. 99 In addition to creating the mock calexps and truth catalogs, MockCoadd also contains driver 100 code to run the MakeSkyMap, MakeCoaddTempExp, and AssembleCoadd tasks on the mock calexps, 101 and code to directly create a mock coadd image using CoaddPsf, which can be compared to the 102 output of the regular coadd tasks to check that the coadd code and CoaddPsf are consistent. 104 Note that aside from MakeSkyMapTask, the coadd tasks are *not* subtasks of MockCoaddTasks, 105 and their configs are not part of MockCoaddConfig; these are created locally within 106 MockCoaddTask methods when needed, as not all coadd task config options are appropriate 107 for the mock data generated by MockCoadd. 110 ConfigClass = MockCoaddConfig
112 _DefaultName =
"MockCoadd" 115 """Construct a MockCoaddTask and the subtasks used for generating skymaps, objects, 116 and observations (i.e. calexp parameters). 118 lsst.pipe.base.CmdLineTask.__init__(self, **kwds)
119 self.makeSubtask(
"makeSkyMap")
120 self.makeSubtask(
"mockObject")
121 self.makeSubtask(
"mockObservation")
123 self.
objectIdKey = self.
schema.addField(
"objectId", type=
"L", doc=
"foreign key to truth catalog")
125 doc=
"foreign key to observation catalog")
127 "centroidInBBox", type=
"Flag",
128 doc=
"set if this source's center position is inside the generated image's bbox" 131 "partialOverlap", type=
"Flag",
132 doc=
"set if this source was not completely inside the generated image" 136 """Build the skymap for the mock dataset.""" 137 return self.makeSkyMap.
run(butler.dataRef(self.config.coaddName +
"Coadd_skyMap")).skyMap
140 """Create and save (if butler is not None) a truth catalog containing all the mock objects. 142 Must be run after buildSkyMap. 144 Most of the work is delegated to the mockObject subtask. 147 skyMap = butler.get(self.config.coaddName +
"Coadd_skyMap")
148 catalog = self.mockObject.
run(tractInfo=skyMap[tract])
149 if butler
is not None:
150 butler.put(catalog,
"truth", tract=tract)
154 """Create and save (if butler is not None) an ExposureCatalog of simulated observations, 155 containing the Psfs, Wcss, Calibs, etc. of the calexps to be simulated. 157 Must be run after buildSkyMap. 159 Most of the work is delegated to the mockObservation subtask. 162 skyMap = butler.get(self.config.coaddName +
"Coadd_skyMap")
164 camera = butler.get(
"camera")
165 catalog = self.mockObservation.
run(butler=butler,
166 n=self.config.nObservations, camera=camera,
167 tractInfo=skyMap[tract])
168 if butler
is not None:
169 butler.put(catalog,
"observations", tract=tract)
173 """Use the truth catalog and observation catalog to create and save (if butler is not None) 174 mock calexps and an ExposureCatalog ('simsrc') that contains information about which objects 175 appear partially or fully in each exposure. 177 Must be run after buildTruthCatalog and buildObservationCatalog. 179 if obsCatalog
is None:
180 obsCatalog = butler.get(
"observations", tract=tract)
181 if truthCatalog
is None:
182 truthCatalog = butler.get(
"truth", tract=tract)
183 ccdKey = obsCatalog.getSchema().find(
"ccd").key
184 visitKey = obsCatalog.getSchema().find(
"visit").key
186 for obsRecord
in obsCatalog:
187 ccd = obsRecord.getI(ccdKey)
188 visit = obsRecord.getI(visitKey)
189 self.log.info(
"Generating image for visit={visit}, ccd={ccd}".format(ccd=ccd, visit=visit))
190 exposure = lsst.afw.image.ExposureF(obsRecord.getBBox())
191 exposure.setCalib(obsRecord.getCalib())
192 exposure.setWcs(obsRecord.getWcs())
193 exposure.setPsf(obsRecord.getPsf())
194 exposure.getInfo().setApCorrMap(obsRecord.getApCorrMap())
195 exposure.getInfo().setTransmissionCurve(obsRecord.getTransmissionCurve())
196 for truthRecord
in truthCatalog:
197 status = self.mockObject.drawSource(truthRecord, exposure, buffer=self.config.edgeBuffer)
199 simSrcRecord = simSrcCatalog.addNew()
200 simSrcRecord.setCoord(truthRecord.getCoord())
201 simSrcRecord.setL(self.
objectIdKey, truthRecord.getId())
203 simSrcRecord.setFlag(self.
centroidInBBoxKey, obsRecord.contains(truthRecord.getCoord()))
205 self.log.info(
" added object {id}".format(id=truthRecord.getId()))
206 exposure.getMaskedImage().getVariance().set(1.0)
207 if butler
is not None:
208 butler.put(exposure,
"calexp", ccd=ccd, visit=visit)
209 if butler
is not None:
210 butler.put(simSrcCatalog,
"simsrc", tract=tract)
214 """Convenience function that calls buildSkyMap, buildObservationCatalog, buildTruthCatalog, 215 and buildInputImages. 220 simSrcCatalog = self.
buildInputImages(butler, obsCatalog=observations, truthCatalog=truth)
223 """Helper function to create a Coadd task with configuration appropriate for the simulations. 225 MockCoaddTask does not include MakeCoaddTempExpTask or AssembleCoaddTask as subtasks, because 226 we want explicit control over their configs, rather than leaving this up to the user. 227 However, we have to install our own SelectImages task for both of these, so it made sense 228 to have a single method that would create one of these two tasks, set the config values we 229 want, and install the custom SelectImagesTask. 232 config.coaddName = self.config.coaddName
233 config.select.retarget(MockSelectImagesTask)
234 if cls == MakeCoaddTempExpTask:
235 config.bgSubtracted =
True 236 config.makeDirect =
True 237 config.makePsfMatched =
True 238 config.modelPsf.defaultFwhm = 9
239 config.modelPsf.addWing =
False 240 config.warpAndPsfMatch.psfMatch.kernel[
'AL'].scaleByFwhm =
False 241 config.warpAndPsfMatch.psfMatch.kernel[
'AL'].kernelSize = 25
242 config.warpAndPsfMatch.psfMatch.kernel[
'AL'].sizeCellX = 64
243 config.warpAndPsfMatch.psfMatch.kernel[
'AL'].sizeCellY = 64
245 elif cls
in [AssembleCoaddTask, SafeClipAssembleCoaddTask, CompareWarpAssembleCoaddTask]:
246 if assemblePsfMatched:
247 config.warpType =
'psfMatched' 248 if cls != AssembleCoaddTask:
249 config.doWrite =
False 250 if cls == CompareWarpAssembleCoaddTask:
251 config.assembleStaticSkyModel.select.retarget(MockSelectImagesTask)
252 config.doAttachTransmissionCurve =
True 253 return cls(config=config)
256 """Generator that iterates over the patches in a tract, yielding dataRefs. 258 nPatchX, nPatchY = tractInfo.getNumPatches()
259 for iPatchX
in range(nPatchX):
260 for iPatchY
in range(nPatchY):
261 patchRef = butler.dataRef(self.config.coaddName +
"Coadd",
262 tract=tractInfo.getId(), patch=
"%d,%d" % (iPatchX, iPatchY),
267 """Run the coadd tasks (MakeCoaddTempExp and AssembleCoadd) on the mock data. 269 Must be run after buildInputImages. 270 Makes both direct and PSF-matched coadds 273 skyMap = butler.get(self.config.coaddName +
"Coadd_skyMap")
274 tractInfo = skyMap[tract]
275 makeCoaddTempExpTask = self.
makeCoaddTask(MakeCoaddTempExpTask)
276 directCoaddTaskList = []
277 for coaddTask
in [SafeClipAssembleCoaddTask, CompareWarpAssembleCoaddTask, AssembleCoaddTask]:
279 assemblePsfMatchedCoaddTask = self.
makeCoaddTask(AssembleCoaddTask, assemblePsfMatched=
True)
281 makeCoaddTempExpTask.run(patchRef)
283 for directCoaddTask
in directCoaddTaskList:
284 directCoaddTask.run(patchRef)
285 assemblePsfMatchedCoaddTask.run(patchRef)
288 """Directly create a simulation of the coadd, using the CoaddPsf (and ModelPsf) 289 of the direct (and psfMatched) coadd exposure and the truth catalog. 291 Must be run after buildCoadd. 293 if truthCatalog
is None:
294 truthCatalog = butler.get(
"truth", tract=tract)
296 skyMap = butler.get(self.config.coaddName +
"Coadd_skyMap")
297 tractInfo = skyMap[tract]
298 tractWcs = tractInfo.getWcs()
301 for dataProduct
in [
"Coadd",
"CoaddPsfMatched"]:
302 exposure = patchRef.get(self.config.coaddName + dataProduct, immediate=
True)
303 exposure.getMaskedImage().getImage().set(0.0)
305 exposure.getInfo().getCoaddInputs().ccds, exposure.getWcs()
307 exposure.setPsf(coaddPsf)
308 for truthRecord
in truthCatalog:
309 self.mockObject.drawSource(truthRecord, exposure, buffer=0)
310 patchRef.put(exposure, self.config.coaddName + dataProduct +
"_mock")
314 """Convenience function to create and run MockCoaddTask with default settings. 316 from .simpleMapper
import makeDataRepo
319 task.buildAllInputs(butler)
320 task.buildCoadd(butler)
321 task.buildMockCoadd(butler)
static Schema makeMinimalSchema()
def buildTruthCatalog(self, butler=None, skyMap=None, tract=0)
def buildObservationCatalog(self, butler=None, skyMap=None, tract=0, camera=None)
def makeCoaddTask(self, cls, assemblePsfMatched=False)
def buildAllInputs(self, butler)
def setupSkyMapPatches(self, nPatches=2, patchSize=400, pixelScale=0.2 *lsst.afw.geom.arcseconds)
def buildSkyMap(self, butler)
def buildInputImages(self, butler, obsCatalog=None, truthCatalog=None, tract=0)
def buildMockCoadd(self, butler, truthCatalog=None, skyMap=None, tract=0)
def iterPatchRefs(self, butler, tractInfo)
def buildCoadd(self, butler, skyMap=None, tract=0)