LSST Applications 24.1.5,g02d81e74bb+fa3a7a026e,g180d380827+a53a32eff8,g2079a07aa2+86d27d4dc4,g2305ad1205+c0501b3732,g295015adf3+7d3e92f0ec,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+5dd1654d75,g48712c4677+3bf1020dcb,g487adcacf7+065c13d9cf,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+d7ac436cfb,g5a732f18d5+53520f316c,g64a986408d+fa3a7a026e,g858d7b2824+fa3a7a026e,g8a8a8dda67+585e252eca,g99cad8db69+a5a909b84f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+4cf350ccb2,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+f991a0b59f,gc120e1dc64+9ccbfdb8be,gc28159a63d+0e5473021a,gcf0d15dbbd+5dd1654d75,gd96a1ce819+42fd0ee607,gdaeeff99f8+f9a426f77a,ge6526c86ff+0d71447b4b,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+fa3a7a026e
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Variables
lsst.pipe.tasks.matchFakes Namespace Reference

Classes

class  MatchFakesConnections
 

Variables

 fakeCats : `pandas.DataFrame`
 
 skyMap : `lsst.skymap.SkyMap`
 
 diffIm : `lsst.afw.image.Exposure`
 
 associatedDiaSources : `pandas.DataFrame`
 
 result : `lsst.pipe.base.Struct`
 
 fakeCat : `pandas.DataFrame`
 
 combinedFakeCat : `pandas.DataFrame`
 
 exposure : `lsst.afw.image.exposure.exposure.ExposureF`
 
 movingFakeCat : `pandas.DataFrame`
 
 image : `lsst.afw.image.exposure.exposure.ExposureF`
 
 ras : `numpy.ndarray`, (N,)
 
 decs : `numpy.ndarray`, (N,)
 
 vectors : `numpy.ndarray`, (N, 3)
 
 ccdVisitFakeMagnitudes : `pandas.DataFrame`
 
 band : `str`
 

Variable Documentation

◆ associatedDiaSources

lsst.pipe.tasks.matchFakes.associatedDiaSources : `pandas.DataFrame`

Definition at line 136 of file matchFakes.py.

◆ band

lsst.pipe.tasks.matchFakes.band : `str`

Definition at line 405 of file matchFakes.py.

◆ ccdVisitFakeMagnitudes

lsst.pipe.tasks.matchFakes.ccdVisitFakeMagnitudes : `pandas.DataFrame`

Definition at line 403 of file matchFakes.py.

◆ combinedFakeCat

lsst.pipe.tasks.matchFakes.combinedFakeCat : `pandas.DataFrame`

Definition at line 210 of file matchFakes.py.

◆ decs

lsst.pipe.tasks.matchFakes.decs : `numpy.ndarray`, (N,)

Definition at line 316 of file matchFakes.py.

◆ diffIm

lsst.pipe.tasks.matchFakes.diffIm : `lsst.afw.image.Exposure`

Definition at line 134 of file matchFakes.py.

◆ exposure

lsst.pipe.tasks.matchFakes.exposure : `lsst.afw.image.exposure.exposure.ExposureF`

Definition at line 236 of file matchFakes.py.

◆ fakeCat

lsst.pipe.tasks.matchFakes.fakeCat : `pandas.DataFrame`
fakeCat = self.composeFakeCat(fakeCats, skyMap)

if self.config.doMatchVisit:
    fakeCat = self.getVisitMatchedFakeCat(fakeCat, diffIm)

return self._processFakes(fakeCat, diffIm, associatedDiaSources)

def _processFakes(self, fakeCat, diffIm, associatedDiaSources):
if len(fakeCats) == 1:
    return fakeCats[0].get()
outputCat = []
for fakeCatRef in fakeCats:
    cat = fakeCatRef.get()
    tractId = fakeCatRef.dataId["tract"]
    # Make sure all data is within the inner part of the tract.
    outputCat.append(cat[
        skyMap.findTractIdArray(cat[self.config.ra_col],
                                cat[self.config.dec_col],
                                degrees=False)
        == tractId])

return pd.concat(outputCat)

def getVisitMatchedFakeCat(self, fakeCat, exposure):
selected = exposure.getInfo().getVisitInfo().getId() == fakeCat["visit"]

return fakeCat[selected]

def _addPixCoords(self, fakeCat, image):
wcs = image.getWcs()
ras = fakeCat[self.config.ra_col].values
decs = fakeCat[self.config.dec_col].values
xs, ys = wcs.skyToPixelArray(ras, decs)
fakeCat["x"] = xs
fakeCat["y"] = ys

return fakeCat

def _trimFakeCat(self, fakeCat, image):
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


class MatchVariableFakesConnections(MatchFakesConnections):
ccdVisitFakeMagnitudes = connTypes.Input(
doc="Catalog of fakes with magnitudes scattered for this ccdVisit.",
name="{fakesType}ccdVisitFakeMagnitudes",
storageClass="DataFrame",
dimensions=("instrument", "visit", "detector"),
)


class MatchVariableFakesConfig(MatchFakesConfig,
                       pipelineConnections=MatchVariableFakesConnections):
pass


class MatchVariableFakesTask(MatchFakesTask):
_DefaultName = "matchVariableFakes"
ConfigClass = MatchVariableFakesConfig

def runQuantum(self, butlerQC, inputRefs, outputRefs):
    inputs = butlerQC.get(inputRefs)
    inputs["band"] = butlerQC.quantum.dataId["band"]

    outputs = self.run(**inputs)
    butlerQC.put(outputs, outputRefs)

def run(self, fakeCats, ccdVisitFakeMagnitudes, skyMap, diffIm, associatedDiaSources, band):
fakeCat = self.composeFakeCat(fakeCats, skyMap)
self.computeExpectedDiffMag(fakeCat, ccdVisitFakeMagnitudes, band)
return self._processFakes(fakeCat, diffIm, associatedDiaSources)

def computeExpectedDiffMag(self, fakeCat, ccdVisitFakeMagnitudes, band):

Definition at line 159 of file matchFakes.py.

◆ fakeCats

lsst.pipe.tasks.matchFakes.fakeCats : `pandas.DataFrame`
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=False,
    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=100,
)


class MatchFakesTask(PipelineTask):
_DefaultName = "matchFakes"
ConfigClass = MatchFakesConfig

def run(self, fakeCats, skyMap, diffIm, associatedDiaSources):
trimmedFakes = self._trimFakeCat(fakeCat, diffIm)
nPossibleFakes = len(trimmedFakes)

fakeVects = self._getVectors(trimmedFakes[self.config.ra_col],
                             trimmedFakes[self.config.dec_col])
diaSrcVects = self._getVectors(
    np.radians(associatedDiaSources.loc[:, "ra"]),
    np.radians(associatedDiaSources.loc[:, "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.", nFakesFound, nPossibleFakes)
diaSrcIds = associatedDiaSources.iloc[np.where(np.isfinite(dist), idxs, 0)]["diaSourceId"].to_numpy()
matchedFakes = trimmedFakes.assign(diaSourceId=np.where(np.isfinite(dist), diaSrcIds, 0))

return Struct(
    matchedDiaSources=matchedFakes.merge(
        associatedDiaSources.reset_index(drop=True), on="diaSourceId", how="left")
)

def composeFakeCat(self, fakeCats, skyMap):

Definition at line 130 of file matchFakes.py.

◆ image

lsst.pipe.tasks.matchFakes.image : `lsst.afw.image.exposure.exposure.ExposureF`

Definition at line 256 of file matchFakes.py.

◆ movingFakeCat

lsst.pipe.tasks.matchFakes.movingFakeCat : `pandas.DataFrame`

Definition at line 241 of file matchFakes.py.

◆ ras

lsst.pipe.tasks.matchFakes.ras : `numpy.ndarray`, (N,)
# fakeCat must be processed with _addPixCoords before trimming
if ('x' not in fakeCat.columns) or ('y' not in fakeCat.columns):
    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[self.config.ra_col].values * u.rad
decs = fakeCat[self.config.dec_col].values * u.rad

isContainedRaDec = image.containsSkyCoords(ras, decs, padding=0)

# now use the exact pixel BBox to filter to only fakes that were inserted
xs = fakeCat["x"].values
ys = fakeCat["y"].values

bbox = Box2D(image.getBBox())
isContainedXy = xs >= bbox.minX
isContainedXy &= xs <= bbox.maxX
isContainedXy &= ys >= bbox.minY
isContainedXy &= ys <= bbox.maxY

return fakeCat[isContainedRaDec & isContainedXy]

def _getVectors(self, ras, decs):

Definition at line 314 of file matchFakes.py.

◆ result

lsst.pipe.tasks.matchFakes.result : `lsst.pipe.base.Struct`

Definition at line 141 of file matchFakes.py.

◆ skyMap

lsst.pipe.tasks.matchFakes.skyMap : `lsst.skymap.SkyMap`

Definition at line 132 of file matchFakes.py.

◆ vectors

lsst.pipe.tasks.matchFakes.vectors : `numpy.ndarray`, (N, 3)

Definition at line 321 of file matchFakes.py.