LSST Applications g00d0e8bbd7+edbf708997,g03191d30f7+9ce8016dbd,g1955dfad08+0bd186d245,g199a45376c+5137f08352,g1fd858c14a+a888a50aa2,g262e1987ae+45f9aba685,g29ae962dfc+1c7d47a24f,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3fd5ace14f+eed17d2c67,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+c4107e45b5,g67b6fd64d1+6dc8069a4c,g74acd417e5+f452e9c21a,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+2025e9ce17,g7cc15d900a+2d158402f9,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d4809ba88+c4107e45b5,g8d7436a09f+e96c132b44,g8ea07a8fe4+db21c37724,g98df359435+aae6d409c1,ga2180abaac+edbf708997,gac66b60396+966efe6077,gb632fb1845+88945a90f8,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gca7fc764a6+6dc8069a4c,gd7ef33dd92+6dc8069a4c,gda68eeecaf+7d1e613a8d,gdab6d2f7ff+f452e9c21a,gdbb4c4dda9+c4107e45b5,ge410e46f29+6dc8069a4c,ge41e95a9f2+c4107e45b5,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.pipe.tasks.drpAssociationPipe Namespace Reference

Classes

class  DrpAssociationPipeConnections
 

Functions

 _stackCatalogs (self, catalogs, remove_columns=None, empty=None)
 
 runSolarSystemAssociation (self, diaCat, ssCat, visitSummary, patchBbox, patchWcs, innerTractSkyRegion, detector, visit)
 
 _addDiaObjectCoords (self, objects, sources)
 
 _trimToPatch (self, cat, patchBox, wcs, innerTractSkyRegion=None)
 
 dropDiaSourceByDiaObjectId (self, droppedDiaObjectIds, diaSources)
 
 prepareCatalogDict (dataRefList, useVisitDetector=True)
 

Variables

 diaCat = ssoAssocResult.unassociatedDiaSources
 
 nSsSrc
 
 nSsObj
 
 diaInPatch = self._trimToPatch(diaCat.to_pandas(), outerPatchBox, skyInfo.wcs)
 
 nDiaSrc = diaInPatch.sum()
 
 diaSourceHistoryCat = self._stackCatalogs(diaSourceHistory)
 
 ssSourceHistoryCat = self._stackCatalogs(ssSourceHistory, remove_columns=['ra', 'dec'])
 
int nSsSrcTotal = len(ssSourceHistoryCat) if ssSourceHistoryCat else 0
 
 unassociatedSsObjectHistoryCat = self._stackCatalogs(unassociatedSsObjectHistory)
 
int nSsObjTotal = len(unassociatedSsObjectHistoryCat) if unassociatedSsObjectHistoryCat else 0
 
 diaSourceTable = diaSourceHistoryCat.to_pandas()
 
 drop
 
 assocResult = self.associator.run(diaSourceTable, idGenerator=idGenerator)
 
 objectsInTractPatch
 
 diaObjects = assocResult.diaObjects[objectsInTractPatch]
 
 assocDiaSources
 
 diaObjectTable
 
 assocDiaSourceTable
 
 associatedSsSources
 
 unassociatedSsObjects
 

Detailed Description

Pipeline for running DiaSource association in a DRP context.

Function Documentation

◆ _addDiaObjectCoords()

lsst.pipe.tasks.drpAssociationPipe._addDiaObjectCoords ( self,
objects,
sources )
protected

Definition at line 447 of file drpAssociationPipe.py.

447 def _addDiaObjectCoords(self, objects, sources):
448 obj = objects[['ra', 'dec']].rename(columns={"ra": "coord_ra", "dec": "coord_dec"})
449 df = pd.merge(sources.reset_index(), obj, left_on='diaObjectId', right_index=True,
450 how='inner').set_index('diaSourceId')
451 return df
452

◆ _stackCatalogs()

lsst.pipe.tasks.drpAssociationPipe._stackCatalogs ( self,
catalogs,
remove_columns = None,
empty = None )
protected
Stack a list of catalogs.

Parameters
----------
catalogs : `list` of `astropy.table.Table`
    Input catalogs with the same columns to be combined.
remove_columns : `list` of `str` or None, optional
    List of column names to drop from the tables before stacking.

Returns
-------
`astropy.table.Table`
    The combined catalog.

Definition at line 341 of file drpAssociationPipe.py.

341 def _stackCatalogs(self, catalogs, remove_columns=None, empty=None):
342 """Stack a list of catalogs.
343
344 Parameters
345 ----------
346 catalogs : `list` of `astropy.table.Table`
347 Input catalogs with the same columns to be combined.
348 remove_columns : `list` of `str` or None, optional
349 List of column names to drop from the tables before stacking.
350
351 Returns
352 -------
353 `astropy.table.Table`
354 The combined catalog.
355 """
356 if catalogs:
357 sourceHistory = tb.vstack(catalogs)
358 if remove_columns is not None:
359 sourceHistory.remove_columns(remove_columns)
360 return sourceHistory
361 else:
362 return empty
363

◆ _trimToPatch()

lsst.pipe.tasks.drpAssociationPipe._trimToPatch ( self,
cat,
patchBox,
wcs,
innerTractSkyRegion = None )
protected
Create generator testing if a set of DiaSources are in the
patch/tract.

Parameters
----------
cat : `pandas.DataFrame`
    Catalog of DiaSources to test within patch/tract.
patchBox : `lsst.geom.Box2D`
    Bounding box of the patch.
wcs : `lsst.geom.SkyWcs`
    Wcs of the tract.
innerTractSkyRegion : `lsst.sphgeom.Box`, optional
    Region defining the inner non-overlapping part of a tract.

Returns
-------
isInPatch : `numpy.ndarray`, (N,)
    Booleans representing if the DiaSources are contained within the
    current patch and tract.

Definition at line 453 of file drpAssociationPipe.py.

453 def _trimToPatch(self, cat, patchBox, wcs, innerTractSkyRegion=None):
454 """Create generator testing if a set of DiaSources are in the
455 patch/tract.
456
457 Parameters
458 ----------
459 cat : `pandas.DataFrame`
460 Catalog of DiaSources to test within patch/tract.
461 patchBox : `lsst.geom.Box2D`
462 Bounding box of the patch.
463 wcs : `lsst.geom.SkyWcs`
464 Wcs of the tract.
465 innerTractSkyRegion : `lsst.sphgeom.Box`, optional
466 Region defining the inner non-overlapping part of a tract.
467
468 Returns
469 -------
470 isInPatch : `numpy.ndarray`, (N,)
471 Booleans representing if the DiaSources are contained within the
472 current patch and tract.
473 """
474 isInPatch = np.zeros(len(cat), dtype=bool)
475
476 for idx, row in cat.reset_index().iterrows():
477 spPoint = geom.SpherePoint(row["ra"], row["dec"], geom.degrees)
478 pxCoord = wcs.skyToPixel(spPoint)
479 ra_rad = np.deg2rad(row["ra"])
480 dec_rad = np.deg2rad(row["dec"])
481 isInPatch[idx] = patchBox.contains(pxCoord)
482
483 if innerTractSkyRegion is not None:
484 isInPatch[idx] &= innerTractSkyRegion.contains(ra_rad, dec_rad)
485
486 return isInPatch
487
Point in an unspecified spherical coordinate system.
Definition SpherePoint.h:57

◆ dropDiaSourceByDiaObjectId()

lsst.pipe.tasks.drpAssociationPipe.dropDiaSourceByDiaObjectId ( self,
droppedDiaObjectIds,
diaSources )
Drop diaSources with diaObject IDs in the supplied list.

Parameters
----------
droppedDiaObjectIds : `pandas.DataFrame`
    DiaObjectIds to match and drop from the list of diaSources.
diaSources : `pandas.DataFrame`
    Catalog of diaSources to check and filter.

Returns
-------
filteredDiaSources : `pandas.DataFrame`
    The input diaSources with any rows matching the listed diaObjectIds
    removed.

Definition at line 488 of file drpAssociationPipe.py.

488 def dropDiaSourceByDiaObjectId(self, droppedDiaObjectIds, diaSources):
489 """Drop diaSources with diaObject IDs in the supplied list.
490
491 Parameters
492 ----------
493 droppedDiaObjectIds : `pandas.DataFrame`
494 DiaObjectIds to match and drop from the list of diaSources.
495 diaSources : `pandas.DataFrame`
496 Catalog of diaSources to check and filter.
497
498 Returns
499 -------
500 filteredDiaSources : `pandas.DataFrame`
501 The input diaSources with any rows matching the listed diaObjectIds
502 removed.
503 """
504 toDrop = diaSources['diaObjectId'].isin(droppedDiaObjectIds)
505
506 # Keep only rows that do NOT match
507 return diaSources.loc[~toDrop].copy()
508
509

◆ prepareCatalogDict()

lsst.pipe.tasks.drpAssociationPipe.prepareCatalogDict ( dataRefList,
useVisitDetector = True )
Prepare lookup tables of the data references.

Parameters
----------
dataRefList : `list` of `lsst.daf.butler.DeferredDatasetHandle`
    The data references to make a lookup table for.
useVisitDetector : `bool`, optional
    Use both visit and detector in the dict key? If False, use only visit.

Returns
-------
`dict` of `lsst.daf.butler.DeferredDatasetHandle`
    Lookup table of the data references by visit (and optionally detector)

Definition at line 510 of file drpAssociationPipe.py.

510def prepareCatalogDict(dataRefList, useVisitDetector=True):
511 """Prepare lookup tables of the data references.
512
513 Parameters
514 ----------
515 dataRefList : `list` of `lsst.daf.butler.DeferredDatasetHandle`
516 The data references to make a lookup table for.
517 useVisitDetector : `bool`, optional
518 Use both visit and detector in the dict key? If False, use only visit.
519
520 Returns
521 -------
522 `dict` of `lsst.daf.butler.DeferredDatasetHandle`
523 Lookup table of the data references by visit (and optionally detector)
524 """
525 dataDict = {}
526
527 if useVisitDetector:
528 for dataRef in dataRefList:
529 dataDict[(dataRef.dataId["visit"], dataRef.dataId["detector"])] = dataRef
530 else:
531 for dataRef in dataRefList:
532 dataDict[dataRef.dataId["visit"]] = dataRef
533 return dataDict

◆ runSolarSystemAssociation()

lsst.pipe.tasks.drpAssociationPipe.runSolarSystemAssociation ( self,
diaCat,
ssCat,
visitSummary,
patchBbox,
patchWcs,
innerTractSkyRegion,
detector,
visit )
Run Solar System object association and filter the results.

Parameters
----------
diaCat : `pandas.DataFrame`
    Catalog of detected diaSources on the image difference.
ssCat : `astropy.table.Table`
    Catalog of predicted coordinates of known Solar System objects.
visitSummary : `lsst.afw.table.ExposureCatalog`
    Table of calibration and metadata for all detectors in a visit.
patchBbox : `lsst.geom.Box2D`
    Bounding box of the patch.
patchWcs : `lsst.geom.SkyWcs`
    Wcs of the tract containing the patch.
innerTractSkyRegion : `lsst.sphgeom.Box`
    Region defining the inner non-overlapping part of a tract.
detector : `int`
    Detector number of the science exposure.
visit : `int`
    Visit number of the science exposure.

Returns
-------
ssoAssocResult : `lsst.pipe.base.Struct`
    Results struct with attributes:

    ``associatedSsSources``
        Table of DiaSources associated with Solar System objects.
        (`astropy.table.Table`)
    ``associatedSsDiaSources``
        Table of Solar System objects associated with DiaSources.
        (`astropy.table.Table`).
    ``unassociatedSsObjects``
        Table of Solar System objects in the patch not associated with
        any DiaSource (`astropy.table.Table`).
    ``unassociatedDiaSources``
        Table of DiaSources not associated with any Solar System object
        (`astropy.table.Table`).

Definition at line 364 of file drpAssociationPipe.py.

371 ):
372 """Run Solar System object association and filter the results.
373
374 Parameters
375 ----------
376 diaCat : `pandas.DataFrame`
377 Catalog of detected diaSources on the image difference.
378 ssCat : `astropy.table.Table`
379 Catalog of predicted coordinates of known Solar System objects.
380 visitSummary : `lsst.afw.table.ExposureCatalog`
381 Table of calibration and metadata for all detectors in a visit.
382 patchBbox : `lsst.geom.Box2D`
383 Bounding box of the patch.
384 patchWcs : `lsst.geom.SkyWcs`
385 Wcs of the tract containing the patch.
386 innerTractSkyRegion : `lsst.sphgeom.Box`
387 Region defining the inner non-overlapping part of a tract.
388 detector : `int`
389 Detector number of the science exposure.
390 visit : `int`
391 Visit number of the science exposure.
392
393 Returns
394 -------
395 ssoAssocResult : `lsst.pipe.base.Struct`
396 Results struct with attributes:
397
398 ``associatedSsSources``
399 Table of DiaSources associated with Solar System objects.
400 (`astropy.table.Table`)
401 ``associatedSsDiaSources``
402 Table of Solar System objects associated with DiaSources.
403 (`astropy.table.Table`).
404 ``unassociatedSsObjects``
405 Table of Solar System objects in the patch not associated with
406 any DiaSource (`astropy.table.Table`).
407 ``unassociatedDiaSources``
408 Table of DiaSources not associated with any Solar System object
409 (`astropy.table.Table`).
410 """
411 # Get the exposure metadata from the detector's row in the visitSummary table.
412 ssoAssocResult = self.solarSystemAssociator.run(
413 diaCat,
414 ssCat,
415 visitInfo=visitSummary.find(detector).visitInfo,
416 bbox=visitSummary.find(detector).getBBox(),
417 wcs=visitSummary.find(detector).wcs,
418 )
419
420 ssInTractPatch = self._trimToPatch(ssoAssocResult.associatedSsSources.to_pandas(),
421 patchBbox,
422 patchWcs,
423 innerTractSkyRegion=innerTractSkyRegion)
424 associatedSsSources = ssoAssocResult.associatedSsSources[ssInTractPatch].copy()
425 assocDiaSrcIds = set(associatedSsSources['diaSourceId'])
426 diaSrcMask = [diaId in assocDiaSrcIds for diaId in ssoAssocResult.ssoAssocDiaSources['diaSourceId']]
427 associatedSsDiaSources = ssoAssocResult.ssoAssocDiaSources[np.array(diaSrcMask)]
428
429 ssObjInTractPatch = self._trimToPatch(ssoAssocResult.unassociatedSsObjects.to_pandas(),
430 patchBbox,
431 patchWcs,
432 innerTractSkyRegion=innerTractSkyRegion)
433 unassociatedSsObjects = ssoAssocResult.unassociatedSsObjects[ssObjInTractPatch].copy()
434 # Update the table of Solar System objects that were not found with the
435 # visit and detector where they were predicted.
436 if len(unassociatedSsObjects) > 0:
437 unassociatedSsObjects['visit'] = visit
438 unassociatedSsObjects['detector'] = detector
439
440 return pipeBase.Struct(
441 associatedSsSources=associatedSsSources,
442 associatedSsDiaSources=associatedSsDiaSources,
443 unassociatedSsObjects=unassociatedSsObjects,
444 unassociatedDiaSources=ssoAssocResult.unAssocDiaSources
445 )
446

Variable Documentation

◆ assocDiaSources

lsst.pipe.tasks.drpAssociationPipe.assocDiaSources
Initial value:
1= self.dropDiaSourceByDiaObjectId(assocResult.diaObjects[~objectsInTractPatch].index,
2 assocResult.assocDiaSources)

Definition at line 326 of file drpAssociationPipe.py.

◆ assocDiaSourceTable

lsst.pipe.tasks.drpAssociationPipe.assocDiaSourceTable

Definition at line 336 of file drpAssociationPipe.py.

◆ associatedSsSources

lsst.pipe.tasks.drpAssociationPipe.associatedSsSources

Definition at line 337 of file drpAssociationPipe.py.

◆ assocResult

lsst.pipe.tasks.drpAssociationPipe.assocResult = self.associator.run(diaSourceTable, idGenerator=idGenerator)

Definition at line 313 of file drpAssociationPipe.py.

◆ diaCat

lsst.pipe.tasks.drpAssociationPipe.diaCat = ssoAssocResult.unassociatedDiaSources

Definition at line 264 of file drpAssociationPipe.py.

◆ diaInPatch

lsst.pipe.tasks.drpAssociationPipe.diaInPatch = self._trimToPatch(diaCat.to_pandas(), outerPatchBox, skyInfo.wcs)

Definition at line 272 of file drpAssociationPipe.py.

◆ diaObjects

lsst.pipe.tasks.drpAssociationPipe.diaObjects = assocResult.diaObjects[objectsInTractPatch]

Definition at line 321 of file drpAssociationPipe.py.

◆ diaObjectTable

lsst.pipe.tasks.drpAssociationPipe.diaObjectTable

Definition at line 335 of file drpAssociationPipe.py.

◆ diaSourceHistoryCat

lsst.pipe.tasks.drpAssociationPipe.diaSourceHistoryCat = self._stackCatalogs(diaSourceHistory)

Definition at line 291 of file drpAssociationPipe.py.

◆ diaSourceTable

lsst.pipe.tasks.drpAssociationPipe.diaSourceTable = diaSourceHistoryCat.to_pandas()

Definition at line 310 of file drpAssociationPipe.py.

◆ drop

lsst.pipe.tasks.drpAssociationPipe.drop

Definition at line 311 of file drpAssociationPipe.py.

◆ nDiaSrc

lsst.pipe.tasks.drpAssociationPipe.nDiaSrc = diaInPatch.sum()

Definition at line 274 of file drpAssociationPipe.py.

◆ nSsObj

lsst.pipe.tasks.drpAssociationPipe.nSsObj

Definition at line 266 of file drpAssociationPipe.py.

◆ nSsObjTotal

int lsst.pipe.tasks.drpAssociationPipe.nSsObjTotal = len(unassociatedSsObjectHistoryCat) if unassociatedSsObjectHistoryCat else 0

Definition at line 296 of file drpAssociationPipe.py.

◆ nSsSrc

lsst.pipe.tasks.drpAssociationPipe.nSsSrc

Definition at line 266 of file drpAssociationPipe.py.

◆ nSsSrcTotal

int lsst.pipe.tasks.drpAssociationPipe.nSsSrcTotal = len(ssSourceHistoryCat) if ssSourceHistoryCat else 0

Definition at line 294 of file drpAssociationPipe.py.

◆ objectsInTractPatch

lsst.pipe.tasks.drpAssociationPipe.objectsInTractPatch
Initial value:
1= self._trimToPatch(assocResult.diaObjects,
2 innerPatchBox,
3 skyInfo.wcs,
4 innerTractSkyRegion=innerTractSkyRegion)

Definition at line 317 of file drpAssociationPipe.py.

◆ ssSourceHistoryCat

lsst.pipe.tasks.drpAssociationPipe.ssSourceHistoryCat = self._stackCatalogs(ssSourceHistory, remove_columns=['ra', 'dec'])

Definition at line 293 of file drpAssociationPipe.py.

◆ unassociatedSsObjectHistoryCat

lsst.pipe.tasks.drpAssociationPipe.unassociatedSsObjectHistoryCat = self._stackCatalogs(unassociatedSsObjectHistory)

Definition at line 295 of file drpAssociationPipe.py.

◆ unassociatedSsObjects

lsst.pipe.tasks.drpAssociationPipe.unassociatedSsObjects

Definition at line 338 of file drpAssociationPipe.py.