LSST Applications g042eb84c57+730a74494b,g04e9c324dd+8c5ae1fdc5,g134cb467dc+1f1e3e7524,g199a45376c+0ba108daf9,g1fd858c14a+fa7d31856b,g210f2d0738+f66ac109ec,g262e1987ae+83a3acc0e5,g29ae962dfc+d856a2cb1f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+a1e0c9f713,g47891489e3+0d594cb711,g4d44eb3520+c57ec8f3ed,g4d7b6aa1c5+f66ac109ec,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+fd7ad03fde,g64539dfbff+f66ac109ec,g67b6fd64d1+0d594cb711,g67fd3c3899+f66ac109ec,g6985122a63+0d594cb711,g74acd417e5+3098891321,g786e29fd12+668abc6043,g81db2e9a8d+98e2ab9f28,g87389fa792+8856018cbb,g89139ef638+0d594cb711,g8d7436a09f+80fda9ce03,g8ea07a8fe4+760ca7c3fc,g90f42f885a+033b1d468d,g97be763408+a8a29bda4b,g99822b682c+e3ec3c61f9,g9d5c6a246b+0d5dac0c3d,ga41d0fce20+9243b26dd2,gbf99507273+8c5ae1fdc5,gd7ef33dd92+0d594cb711,gdab6d2f7ff+3098891321,ge410e46f29+0d594cb711,geaed405ab2+c4bbc419c6,gf9a733ac38+8c5ae1fdc5,w.2025.38
LSST Data Management Base Package
|
Classes | |
class | MatchInjectedToDiaSourceConnections |
Variables | |
injectedCat : `astropy.table.table.Table` | |
diffIm : `lsst.afw.image.Exposure` | |
diaSources : `afw.table.SourceCatalog` | |
result : `lsst.pipe.base.Struct` | |
associatedDiaSources : `pandas.DataFrame` | |
ras : `numpy.ndarray`, (N,) | |
decs : `numpy.ndarray`, (N,) | |
vectors : `numpy.ndarray`, (N, 3) | |
fakeCat : `astropy.table.table.Table` | |
image : `lsst.afw.image.exposure.exposure.ExposureF` | |
matchDiaSources : `pandas.DataFrame` | |
assocDiaSources : `pandas.DataFrame` | |
lsst.pipe.tasks.matchDiffimSourceInjected.assocDiaSources : `pandas.DataFrame` |
Definition at line 406 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.associatedDiaSources : `pandas.DataFrame` |
Definition at line 229 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.decs : `numpy.ndarray`, (N,) |
Definition at line 273 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.diaSources : `afw.table.SourceCatalog` |
Definition at line 123 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.diffIm : `lsst.afw.image.Exposure` |
Definition at line 121 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.fakeCat : `astropy.table.table.Table` |
vectors = np.empty((len(ras), 3)) vectors[:, 2] = np.sin(decs) vectors[:, 0] = np.cos(decs) * np.cos(ras) vectors[:, 1] = np.cos(decs) * np.sin(ras) return vectors def _addPixCoords(self, fakeCat, image):
wcs = image.getWcs() # Get x/y pixel coordinates for injected sources. xs, ys = wcs.skyToPixelArray( fakeCat["ra"], fakeCat["dec"], degrees=True ) fakeCat["x"] = xs fakeCat["y"] = ys return fakeCat def _trimFakeCat(self, fakeCat, image):
Definition at line 294 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.image : `lsst.afw.image.exposure.exposure.ExposureF` |
Definition at line 296 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.injectedCat : `astropy.table.table.Table` |
matchDistanceArcseconds = pexConfig.RangeField( doc="Distance in arcseconds to match within.", dtype=float, default=0.5, min=0, max=10, ) doMatchVisit = pexConfig.Field( dtype=bool, default=True, doc="Match visit to trim the fakeCat" ) trimBuffer = pexConfig.Field( doc="Size of the pixel buffer surrounding the image." "Only those fake sources with a centroid" "falling within the image+buffer region will be considered matches.", dtype=int, default=50, ) doForcedMeasurement = pexConfig.Field( dtype=bool, default=True, doc="Force measurement of the fakes at the injection locations." ) forcedMeasurement = pexConfig.ConfigurableField( target=ForcedMeasurementTask, doc="Task to force photometer difference image at injection locations.", ) class MatchInjectedToDiaSourceTask(PipelineTask): _DefaultName = "matchInjectedToDiaSource" ConfigClass = MatchInjectedToDiaSourceConfig def run(self, injectedCat, diffIm, diaSources):
if self.config.doMatchVisit: fakeCat = self._trimFakeCat(injectedCat, diffIm) else: fakeCat = injectedCat if self.config.doForcedMeasurement: self._estimateFakesSNR(fakeCat, diffIm) return self._processFakes(fakeCat, diaSources) def _estimateFakesSNR(self, injectedCat, diffIm):
# Create a schema for the forced measurement task schema = afwTable.SourceTable.makeMinimalSchema() schema.addField("x", "D", "x position in image.", units="pixel") schema.addField("y", "D", "y position in image.", units="pixel") schema.addField("deblend_nChild", "I", "Need for minimal forced phot schema") pluginList = [ "base_PixelFlags", "base_SdssCentroid", "base_CircularApertureFlux", "base_PsfFlux", "base_LocalBackground" ] forcedMeasConfig = ForcedMeasurementConfig(plugins=pluginList) forcedMeasConfig.slots.centroid = 'base_SdssCentroid' forcedMeasConfig.slots.shape = None # Create the forced measurement task forcedMeas = ForcedMeasurementTask(schema, config=forcedMeasConfig) # Specify the columns to copy from the input catalog to the output catalog forcedMeas.copyColumns = {"coord_ra": "ra", "coord_dec": "dec"} # Create an afw table from the input catalog outputCatalog = afwTable.SourceCatalog(schema) outputCatalog.reserve(len(injectedCat)) for row in injectedCat: outputRecord = outputCatalog.addNew() outputRecord.setId(row['injection_id']) outputRecord.setCoord(lsstGeom.SpherePoint(row["ra"], row["dec"], lsstGeom.degrees)) outputRecord.set("x", row["x"]) outputRecord.set("y", row["y"]) # Generate the forced measurement catalog forcedSources = forcedMeas.generateMeasCat(diffIm, outputCatalog, diffIm.getWcs()) # Attach the PSF shape footprints to the forced measurement catalog forcedMeas.attachPsfShapeFootprints(forcedSources, diffIm) # Copy the x and y positions from the forced measurement catalog back # to the input catalog for src, tgt in zip(forcedSources, outputCatalog): src.set('base_SdssCentroid_x', tgt['x']) src.set('base_SdssCentroid_y', tgt['y']) # Define the centroid for the forced measurement catalog forcedSources.defineCentroid('base_SdssCentroid') # Run the forced measurement task forcedMeas.run(forcedSources, diffIm, outputCatalog, diffIm.getWcs()) # Convert the forced measurement catalog to an astropy table forcedSources_table = forcedSources.asAstropy() # Add the forced measurement columns to the input catalog for column in forcedSources_table.columns: if "Flux" in column or "flag" in column: injectedCat["forced_"+column] = forcedSources_table[column] # Add the SNR columns to the input catalog for column in injectedCat.colnames: if column.endswith("instFlux"): flux = injectedCat[column] fluxErr = injectedCat[column+"Err"].copy() fluxErr = np.where( (fluxErr <= 0) | (np.isnan(fluxErr)), np.nanmax(fluxErr), fluxErr) injectedCat[column+"_SNR"] = flux / fluxErr def _processFakes(self, injectedCat, diaSources):
Definition at line 119 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.matchDiaSources : `pandas.DataFrame` |
# fakeCat must be processed with _addPixCoords before trimming fakeCat = self._addPixCoords(fakeCat, image) # Prefilter in ra/dec to avoid cases where the wcs incorrectly maps # input fakes which are really off the chip onto it. ras = fakeCat["ra"] * u.deg decs = fakeCat["dec"] * u.deg isContainedRaDec = image.containsSkyCoords(ras, decs, padding=0) # now use the exact pixel BBox to filter to only fakes that were inserted xs = fakeCat["x"] ys = fakeCat["y"] bbox = lsstGeom.Box2D(image.getBBox()) isContainedXy = xs - self.config.trimBuffer >= bbox.minX isContainedXy &= xs + self.config.trimBuffer <= bbox.maxX isContainedXy &= ys - self.config.trimBuffer >= bbox.minY isContainedXy &= ys + self.config.trimBuffer <= bbox.maxY return fakeCat[isContainedRaDec & isContainedXy] class MatchInjectedToAssocDiaSourceConnections( PipelineTaskConnections, defaultTemplates={"coaddName": "deep", "fakesType": "fakes_"}, dimensions=("instrument", "visit", "detector")): assocDiaSources = connTypes.Input( doc="An assocDiaSource catalog to match against fakeCat from the" "diaPipe run. Assumed to be SDMified.", name="{fakesType}{coaddName}Diff_assocDiaSrc", storageClass="DataFrame", dimensions=("instrument", "visit", "detector"), ) matchDiaSources = connTypes.Input( doc="A catalog of those fakeCat sources that have a match in " "diaSrc. The schema is the union of the schemas for " "``fakeCat`` and ``diaSrc``.", name="{fakesType}{coaddName}Diff_matchDiaSrc", storageClass="DataFrame", dimensions=("instrument", "visit", "detector"), ) matchAssocDiaSources = connTypes.Output( doc="A catalog of those fakeCat sources that have a match in " "associatedDiaSources. The schema is the union of the schemas for " "``fakeCat`` and ``associatedDiaSources``.", name="{fakesType}{coaddName}Diff_matchAssocDiaSrc", storageClass="DataFrame", dimensions=("instrument", "visit", "detector"), ) class MatchInjectedToAssocDiaSourceConfig( PipelineTaskConfig, pipelineConnections=MatchInjectedToAssocDiaSourceConnections):
class MatchInjectedToAssocDiaSourceTask(PipelineTask): _DefaultName = "matchInjectedToAssocDiaSource" ConfigClass = MatchInjectedToAssocDiaSourceConfig def run(self, assocDiaSources, matchDiaSources):
Definition at line 404 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.ras : `numpy.ndarray`, (N,) |
# First match the diaSrc to the injected fakes injectedCat = injectedCat.to_pandas() nPossibleFakes = len(injectedCat) fakeVects = self._getVectors( np.radians(injectedCat.ra), np.radians(injectedCat.dec)) diaSrcVects = self._getVectors( diaSources['coord_ra'], diaSources['coord_dec']) diaSrcTree = cKDTree(diaSrcVects) dist, idxs = diaSrcTree.query( fakeVects, distance_upper_bound=np.radians(self.config.matchDistanceArcseconds / 3600)) nFakesFound = np.isfinite(dist).sum() self.log.info("Found %d out of %d possible in diaSources.", nFakesFound, nPossibleFakes) # assign diaSourceId to the matched fakes diaSrcIds = diaSources['id'][np.where(np.isfinite(dist), idxs, 0)] matchedFakes = injectedCat.assign(diaSourceId=np.where(np.isfinite(dist), diaSrcIds, 0)) matchedFakes['dist_diaSrc'] = np.where(np.isfinite(dist), 3600*np.rad2deg(dist), -1) return Struct(matchDiaSources=matchedFakes) def _getVectors(self, ras, decs):
Definition at line 271 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.result : `lsst.pipe.base.Struct` |
Definition at line 127 of file matchDiffimSourceInjected.py.
lsst.pipe.tasks.matchDiffimSourceInjected.vectors : `numpy.ndarray`, (N, 3) |
Definition at line 278 of file matchDiffimSourceInjected.py.