LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask Class Reference
Inheritance diagram for lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask:

Public Member Functions

def __init__ (self, **kwds)
 
def buildSkyMap (self, butler)
 
def buildTruthCatalog (self, butler=None, skyMap=None, tract=0)
 
def buildObservationCatalog (self, butler=None, skyMap=None, tract=0, camera=None)
 
def buildInputImages (self, butler, obsCatalog=None, truthCatalog=None, tract=0)
 
def buildAllInputs (self, butler)
 
def makeCoaddTask (self, cls, assemblePsfMatched=False)
 
def iterPatchRefs (self, butler, tractInfo)
 
def buildCoadd (self, butler, skyMap=None, tract=0)
 
def buildMockCoadd (self, butler, truthCatalog=None, skyMap=None, tract=0)
 

Public Attributes

 schema
 
 objectIdKey
 
 exposureIdKey
 
 centroidInBBoxKey
 
 partialOverlapKey
 

Static Public Attributes

 ConfigClass = MockCoaddConfig
 

Detailed Description

MockCoaddTask is a driver task for creating mock coadds.  As opposed to more realistic
simulations, MockCoadd generates and uses extremely simple "toy" data that can be used to more
rigorously test the behavior of high-level task code because the expected results are
more easily predicted.  In particular, calexps are generated directly from the truth catalog,
and contain only zero-noise stars that are created using the same Psf, PhotoCalib, and Wcs that will
be attached to the mock calexp.

In addition to creating the mock calexps and truth catalogs, MockCoadd also contains driver
code to run the MakeSkyMap, MakeCoaddTempExp, and AssembleCoadd tasks on the mock calexps,
and code to directly create a mock coadd image using CoaddPsf, which can be compared to the
output of the regular coadd tasks to check that the coadd code and CoaddPsf are consistent.

Note that aside from MakeSkyMapTask, the coadd tasks are *not* subtasks of MockCoaddTasks,
and their configs are not part of MockCoaddConfig; these are created locally within
MockCoaddTask methods when needed, as not all coadd task config options are appropriate
for the mock data generated by MockCoadd.

Definition at line 91 of file mockCoadd.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.__init__ (   self,
**  kwds 
)
Construct a MockCoaddTask and the subtasks used for generating skymaps, objects,
and observations (i.e. calexp parameters).

Definition at line 114 of file mockCoadd.py.

114  def __init__(self, **kwds):
115  """Construct a MockCoaddTask and the subtasks used for generating skymaps, objects,
116  and observations (i.e. calexp parameters).
117  """
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")
124  self.exposureIdKey = self.schema.addField("exposureId", type="L",
125  doc="foreign key to observation catalog")
126  self.centroidInBBoxKey = self.schema.addField(
127  "centroidInBBox", type="Flag",
128  doc="set if this source's center position is inside the generated image's bbox"
129  )
130  self.partialOverlapKey = self.schema.addField(
131  "partialOverlap", type="Flag",
132  doc="set if this source was not completely inside the generated image"
133  )
134 
static Schema makeMinimalSchema()
Return a minimal schema for Simple tables and records.
Definition: Simple.h:140

Member Function Documentation

◆ buildAllInputs()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.buildAllInputs (   self,
  butler 
)
Convenience function that calls buildSkyMap, buildObservationCatalog, buildTruthCatalog,
and buildInputImages.

Definition at line 217 of file mockCoadd.py.

217  def buildAllInputs(self, butler):
218  """Convenience function that calls buildSkyMap, buildObservationCatalog, buildTruthCatalog,
219  and buildInputImages.
220  """
221  skyMap = self.buildSkyMap(butler)
222  observations = self.buildObservationCatalog(butler, skyMap=skyMap)
223  truth = self.buildTruthCatalog(butler, skyMap=skyMap)
224  self.buildInputImages(butler, obsCatalog=observations, truthCatalog=truth)
225 

◆ buildCoadd()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.buildCoadd (   self,
  butler,
  skyMap = None,
  tract = 0 
)
Run the coadd tasks (MakeCoaddTempExp and AssembleCoadd) on the mock data.

Must be run after buildInputImages.
Makes both direct and PSF-matched coadds

Definition at line 270 of file mockCoadd.py.

270  def buildCoadd(self, butler, skyMap=None, tract=0):
271  """Run the coadd tasks (MakeCoaddTempExp and AssembleCoadd) on the mock data.
272 
273  Must be run after buildInputImages.
274  Makes both direct and PSF-matched coadds
275  """
276  if skyMap is None:
277  skyMap = butler.get(self.config.coaddName + "Coadd_skyMap")
278  tractInfo = skyMap[tract]
279  makeCoaddTempExpTask = self.makeCoaddTask(MakeCoaddTempExpTask)
280  directCoaddTaskList = []
281  for coaddTask in [SafeClipAssembleCoaddTask, CompareWarpAssembleCoaddTask, AssembleCoaddTask]:
282  directCoaddTaskList.append(self.makeCoaddTask(coaddTask))
283  assemblePsfMatchedCoaddTask = self.makeCoaddTask(AssembleCoaddTask, assemblePsfMatched=True)
284  for patchRef in self.iterPatchRefs(butler, tractInfo):
285  makeCoaddTempExpTask.runDataRef(patchRef)
286  for patchRef in self.iterPatchRefs(butler, tractInfo):
287  for directCoaddTask in directCoaddTaskList:
288  directCoaddTask.runDataRef(patchRef)
289  assemblePsfMatchedCoaddTask.runDataRef(patchRef)
290 

◆ buildInputImages()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.buildInputImages (   self,
  butler,
  obsCatalog = None,
  truthCatalog = None,
  tract = 0 
)
Use the truth catalog and observation catalog to create and save (if butler is not None)
mock calexps and an ExposureCatalog ('simsrc') that contains information about which objects
appear partially or fully in each exposure.

Must be run after buildTruthCatalog and buildObservationCatalog.

Definition at line 173 of file mockCoadd.py.

173  def buildInputImages(self, butler, obsCatalog=None, truthCatalog=None, tract=0):
174  """Use the truth catalog and observation catalog to create and save (if butler is not None)
175  mock calexps and an ExposureCatalog ('simsrc') that contains information about which objects
176  appear partially or fully in each exposure.
177 
178  Must be run after buildTruthCatalog and buildObservationCatalog.
179  """
180  if obsCatalog is None:
181  obsCatalog = butler.get("observations", tract=tract)
182  if truthCatalog is None:
183  truthCatalog = butler.get("truth", tract=tract)
184  ccdKey = obsCatalog.getSchema().find("ccd").key
185  visitKey = obsCatalog.getSchema().find("visit").key
186  simSrcCatalog = lsst.afw.table.SimpleCatalog(self.schema)
187  for obsRecord in obsCatalog:
188  ccd = obsRecord.getI(ccdKey)
189  visit = obsRecord.getI(visitKey)
190  self.log.info("Generating image for visit={visit}, ccd={ccd}".format(ccd=ccd, visit=visit))
191  exposure = lsst.afw.image.ExposureF(obsRecord.getBBox())
192  # Apply a tiny offset to the images, so that they have non-zero background.
193  # If the image background is identically zero, the calculated variance will be NaN.
194  exposure.maskedImage.image.array += 1e-8
195  exposure.setPhotoCalib(obsRecord.getPhotoCalib())
196  exposure.setWcs(obsRecord.getWcs())
197  exposure.setPsf(obsRecord.getPsf())
198  exposure.getInfo().setApCorrMap(obsRecord.getApCorrMap())
199  exposure.getInfo().setTransmissionCurve(obsRecord.getTransmissionCurve())
200  for truthRecord in truthCatalog:
201  status = self.mockObject.drawSource(truthRecord, exposure, buffer=self.config.edgeBuffer)
202  if status:
203  simSrcRecord = simSrcCatalog.addNew()
204  simSrcRecord.setCoord(truthRecord.getCoord())
205  simSrcRecord.setL(self.objectIdKey, truthRecord.getId())
206  simSrcRecord.setL(self.exposureIdKey, obsRecord.getId())
207  simSrcRecord.setFlag(self.centroidInBBoxKey, obsRecord.contains(truthRecord.getCoord()))
208  simSrcRecord.setFlag(self.partialOverlapKey, status == 1)
209  self.log.info(" added object {id}".format(id=truthRecord.getId()))
210  exposure.getMaskedImage().getVariance().set(1.0)
211  if butler is not None:
212  butler.put(exposure, "calexp", ccd=ccd, visit=visit)
213  if butler is not None:
214  butler.put(simSrcCatalog, "simsrc", tract=tract)
215  return simSrcCatalog
216 
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
Definition: SortedCatalog.h:42
daf::base::PropertySet * set
Definition: fits.cc:912
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ buildMockCoadd()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.buildMockCoadd (   self,
  butler,
  truthCatalog = None,
  skyMap = None,
  tract = 0 
)
Directly create a simulation of the coadd, using the CoaddPsf (and ModelPsf)
of the direct (and psfMatched) coadd exposure and the truth catalog.

Must be run after buildCoadd.

Definition at line 291 of file mockCoadd.py.

291  def buildMockCoadd(self, butler, truthCatalog=None, skyMap=None, tract=0):
292  """Directly create a simulation of the coadd, using the CoaddPsf (and ModelPsf)
293  of the direct (and psfMatched) coadd exposure and the truth catalog.
294 
295  Must be run after buildCoadd.
296  """
297  if truthCatalog is None:
298  truthCatalog = butler.get("truth", tract=tract)
299  if skyMap is None:
300  skyMap = butler.get(self.config.coaddName + "Coadd_skyMap")
301  tractInfo = skyMap[tract]
302  for patchRef in self.iterPatchRefs(butler, tractInfo):
303  for dataProduct in ["Coadd", "CoaddPsfMatched"]:
304  exposure = patchRef.get(self.config.coaddName + dataProduct)
305  exposure.getMaskedImage().getImage().set(0.0)
307  exposure.getInfo().getCoaddInputs().ccds, exposure.getWcs()
308  )
309  exposure.setPsf(coaddPsf)
310  for truthRecord in truthCatalog:
311  self.mockObject.drawSource(truthRecord, exposure, buffer=0)
312  patchRef.put(exposure, self.config.coaddName + dataProduct + "_mock")
313 
314 
CoaddPsf is the Psf derived to be used for non-PSF-matched Coadd images.
Definition: CoaddPsf.h:58

◆ buildObservationCatalog()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.buildObservationCatalog (   self,
  butler = None,
  skyMap = None,
  tract = 0,
  camera = None 
)
Create and save (if butler is not None) an ExposureCatalog of simulated observations,
containing the Psfs, Wcss, PhotoCalibs, etc. of the calexps to be simulated.

Must be run after buildSkyMap.

Most of the work is delegated to the mockObservation subtask.

Definition at line 153 of file mockCoadd.py.

153  def buildObservationCatalog(self, butler=None, skyMap=None, tract=0, camera=None):
154  """Create and save (if butler is not None) an ExposureCatalog of simulated observations,
155  containing the Psfs, Wcss, PhotoCalibs, etc. of the calexps to be simulated.
156 
157  Must be run after buildSkyMap.
158 
159  Most of the work is delegated to the mockObservation subtask.
160  """
161  if skyMap is None:
162  skyMap = butler.get(self.config.coaddName + "Coadd_skyMap")
163  if camera is None:
164  camera = butler.get("camera")
165  catalog = self.mockObservation.run(butler=butler,
166  n=self.config.nObservations, camera=camera,
167  tractInfo=skyMap[tract])
168  catalog.sort()
169  if butler is not None:
170  butler.put(catalog, "observations", tract=tract)
171  return catalog
172 

◆ buildSkyMap()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.buildSkyMap (   self,
  butler 
)
Build the skymap for the mock dataset.

Definition at line 135 of file mockCoadd.py.

135  def buildSkyMap(self, butler):
136  """Build the skymap for the mock dataset."""
137  return self.makeSkyMap.runDataRef(butler.dataRef(self.config.coaddName + "Coadd_skyMap")).skyMap
138 

◆ buildTruthCatalog()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.buildTruthCatalog (   self,
  butler = None,
  skyMap = None,
  tract = 0 
)
Create and save (if butler is not None) a truth catalog containing all the mock objects.

Must be run after buildSkyMap.

Most of the work is delegated to the mockObject subtask.

Definition at line 139 of file mockCoadd.py.

139  def buildTruthCatalog(self, butler=None, skyMap=None, tract=0):
140  """Create and save (if butler is not None) a truth catalog containing all the mock objects.
141 
142  Must be run after buildSkyMap.
143 
144  Most of the work is delegated to the mockObject subtask.
145  """
146  if skyMap is None:
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)
151  return catalog
152 

◆ iterPatchRefs()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.iterPatchRefs (   self,
  butler,
  tractInfo 
)
Generator that iterates over the patches in a tract, yielding dataRefs.

Definition at line 259 of file mockCoadd.py.

259  def iterPatchRefs(self, butler, tractInfo):
260  """Generator that iterates over the patches in a tract, yielding dataRefs.
261  """
262  nPatchX, nPatchY = tractInfo.getNumPatches()
263  for iPatchX in range(nPatchX):
264  for iPatchY in range(nPatchY):
265  patchRef = butler.dataRef(self.config.coaddName + "Coadd",
266  tract=tractInfo.getId(), patch="%d,%d" % (iPatchX, iPatchY),
267  filter='r')
268  yield patchRef
269 

◆ makeCoaddTask()

def lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.makeCoaddTask (   self,
  cls,
  assemblePsfMatched = False 
)
Helper function to create a Coadd task with configuration appropriate for the simulations.

MockCoaddTask does not include MakeCoaddTempExpTask or AssembleCoaddTask as subtasks, because
we want explicit control over their configs, rather than leaving this up to the user.
However, we have to install our own SelectImages task for both of these, so it made sense
to have a single method that would create one of these two tasks, set the config values we
want, and install the custom SelectImagesTask.

Definition at line 226 of file mockCoadd.py.

226  def makeCoaddTask(self, cls, assemblePsfMatched=False):
227  """Helper function to create a Coadd task with configuration appropriate for the simulations.
228 
229  MockCoaddTask does not include MakeCoaddTempExpTask or AssembleCoaddTask as subtasks, because
230  we want explicit control over their configs, rather than leaving this up to the user.
231  However, we have to install our own SelectImages task for both of these, so it made sense
232  to have a single method that would create one of these two tasks, set the config values we
233  want, and install the custom SelectImagesTask.
234  """
235  config = cls.ConfigClass()
236  config.coaddName = self.config.coaddName
237  config.select.retarget(MockSelectImagesTask)
238  if cls == MakeCoaddTempExpTask:
239  config.bgSubtracted = True
240  config.makeDirect = True
241  config.makePsfMatched = True
242  config.modelPsf.defaultFwhm = 9
243  config.modelPsf.addWing = False
244  config.warpAndPsfMatch.psfMatch.kernel['AL'].scaleByFwhm = False
245  config.warpAndPsfMatch.psfMatch.kernel['AL'].kernelSize = 25
246  config.warpAndPsfMatch.psfMatch.kernel['AL'].sizeCellX = 64
247  config.warpAndPsfMatch.psfMatch.kernel['AL'].sizeCellY = 64
248 
249  elif cls in [AssembleCoaddTask, SafeClipAssembleCoaddTask, CompareWarpAssembleCoaddTask]:
250  if assemblePsfMatched:
251  config.warpType = 'psfMatched'
252  if cls != AssembleCoaddTask:
253  config.doWrite = False
254  if cls == CompareWarpAssembleCoaddTask:
255  config.assembleStaticSkyModel.select.retarget(MockSelectImagesTask)
256  config.doAttachTransmissionCurve = True
257  return cls(config=config)
258 

Member Data Documentation

◆ centroidInBBoxKey

lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.centroidInBBoxKey

Definition at line 126 of file mockCoadd.py.

◆ ConfigClass

lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.ConfigClass = MockCoaddConfig
static

Definition at line 110 of file mockCoadd.py.

◆ exposureIdKey

lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.exposureIdKey

Definition at line 124 of file mockCoadd.py.

◆ objectIdKey

lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.objectIdKey

Definition at line 123 of file mockCoadd.py.

◆ partialOverlapKey

lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.partialOverlapKey

Definition at line 130 of file mockCoadd.py.

◆ schema

lsst.pipe.tasks.mocks.mockCoadd.MockCoaddTask.schema

Definition at line 122 of file mockCoadd.py.


The documentation for this class was generated from the following file: