lsst.pipe.tasks  21.0.0-21-g006371a9+8d72e8ff79
Classes | Functions | Variables
lsst.pipe.tasks.insertFakes Namespace Reference

Classes

class  InsertFakesConnections
 

Functions

def addPixCoords (self, fakeCat, wcs)
 
def trimFakeCat (self, fakeCat, image, wcs)
 
def mkFakeGalsimGalaxies (self, fakeCat, band, photoCalib, pixelScale, psf, image)
 
def mkFakeStars (self, fakeCat, band, photoCalib, psf, image)
 
def cleanCat (self, fakeCat, starCheckVal)
 
def addFakeSources (self, image, fakeImages, sourceType)
 

Variables

 correctedFlux = psf.computeApertureFlux(self.config.calibFluxRadius, xy)
 
 psfKernel = psf.computeKernelImage(xy).getArray()
 
 psfIm = galsim.InterpolatedImage(galsim.Image(psfKernel), scale=pixelScale)
 
 galsimIm = galsim.InterpolatedImage(galsim.Image(im.array), scale=pixelScale)
 
 convIm = galsim.Convolve([galsimIm, psfIm])
 
 outIm = convIm.drawImage(scale=pixelScale, method="real_space").array
 
 imSum = np.sum(outIm)
 
 divIm = outIm/imSum
 
 flux = photoCalib.magnitudeToInstFlux(mag, xy)
 
 imWithFlux = flux*divIm
 

Function Documentation

◆ addFakeSources()

def lsst.pipe.tasks.insertFakes.addFakeSources (   self,
  image,
  fakeImages,
  sourceType 
)
Add the fake sources to the given image

Parameters
----------
image : `lsst.afw.image.exposure.exposure.ExposureF`
            The image into which the fake sources should be added
fakeImages : `typing.Iterator` [`tuple` ['lsst.afw.image.ImageF`, `lsst.geom.Point2d`]]
            An iterator of tuples that contains (or generates) images of fake sources,
            and the locations they are to be inserted at.
sourceType : `str`
            The type (star/galaxy) of fake sources input

Returns
-------
image : `lsst.afw.image.exposure.exposure.ExposureF`

Notes
-----
Uses the x, y information in the ``fakeCat`` to position an image of the fake interpolated onto the
pixel grid of the image. Sets the ``FAKE`` mask plane for the pixels added with the fake source.

Definition at line 709 of file insertFakes.py.

◆ addPixCoords()

def lsst.pipe.tasks.insertFakes.addPixCoords (   self,
  fakeCat,
  wcs 
)
Add pixel coordinates to the catalog of fakes.

Parameters
----------
fakeCat : `pandas.core.frame.DataFrame`
            The catalog of fake sources to be input
wcs : `lsst.afw.geom.SkyWcs`
            WCS to use to add fake sources

Returns
-------
fakeCat : `pandas.core.frame.DataFrame`

Notes
-----
The default option is to use the WCS information from the image. If the ``useUpdatedCalibs`` config
option is set then it will use the updated WCS from jointCal.

Definition at line 469 of file insertFakes.py.

◆ cleanCat()

def lsst.pipe.tasks.insertFakes.cleanCat (   self,
  fakeCat,
  starCheckVal 
)
Remove rows from the fakes catalog which have HLR = 0 for either the buldge or disk component,
   also remove galaxies that have Sersic index outside the galsim min and max
   allowed (0.3 <= n <= 6.2).

Parameters
----------
fakeCat : `pandas.core.frame.DataFrame`
            The catalog of fake sources to be input
starCheckVal : `str`, `bytes` or `int`
            The value that is set in the sourceType column to specifiy an object is a star.

Returns
-------
fakeCat : `pandas.core.frame.DataFrame`
            The input catalog of fake sources but with the bad objects removed

Notes
-----
If the config option sourceSelectionColName is set then only objects with this column set to True
will be added.

Definition at line 658 of file insertFakes.py.

◆ mkFakeGalsimGalaxies()

def lsst.pipe.tasks.insertFakes.mkFakeGalsimGalaxies (   self,
  fakeCat,
  band,
  photoCalib,
  pixelScale,
  psf,
  image 
)
Make images of fake galaxies using GalSim.

Parameters
----------
band : `str`
pixelScale : `float`
psf : `lsst.meas.extensions.psfex.psfexPsf.PsfexPsf`
            The PSF information to use to make the PSF images
fakeCat : `pandas.core.frame.DataFrame`
            The catalog of fake sources to be input
photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`
            Photometric calibration to be used to calibrate the fake sources

Yields
-------
galImages : `generator`
            A generator of tuples of `lsst.afw.image.exposure.exposure.ExposureF` and
            `lsst.geom.Point2D` of their locations.

Notes
-----

Fake galaxies are made by combining two sersic profiles, one for the bulge and one for the disk. Each
component has an individual sersic index (n), a, b and position angle (PA). The combined profile is
then convolved with the PSF at the specified x, y position on the image.

The names of the columns in the ``fakeCat`` are configurable and are the column names from the
University of Washington simulations database as default. For more information see the doc strings
attached to the config options.

See mkFakeStars doc string for an explanation of calibration to instrumental flux.

Definition at line 528 of file insertFakes.py.

◆ mkFakeStars()

def lsst.pipe.tasks.insertFakes.mkFakeStars (   self,
  fakeCat,
  band,
  photoCalib,
  psf,
  image 
)
Make fake stars based off the properties in the fakeCat.

Parameters
----------
band : `str`
psf : `lsst.meas.extensions.psfex.psfexPsf.PsfexPsf`
            The PSF information to use to make the PSF images
fakeCat : `pandas.core.frame.DataFrame`
            The catalog of fake sources to be input
image : `lsst.afw.image.exposure.exposure.ExposureF`
            The image into which the fake sources should be added
photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`
            Photometric calibration to be used to calibrate the fake sources

Yields
-------
starImages : `generator`
            A generator of tuples of `lsst.afw.image.ImageF` of fake stars and
            `lsst.geom.Point2D` of their locations.

Notes
-----
To take a given magnitude and translate to the number of counts in the image
we use photoCalib.magnitudeToInstFlux, which returns the instrumental flux for the
given calibration radius used in the photometric calibration step.
Thus `calibFluxRadius` should be set to this same radius so that we can normalize
the PSF model to the correct instrumental flux within calibFluxRadius.

Definition at line 603 of file insertFakes.py.

◆ trimFakeCat()

def lsst.pipe.tasks.insertFakes.trimFakeCat (   self,
  fakeCat,
  image,
  wcs 
)
Trim the fake cat to about the size of the input image.

`fakeCat` must be processed with addPixCoords before using this method.

Parameters
----------
fakeCat : `pandas.core.frame.DataFrame`
            The catalog of fake sources to be input
image : `lsst.afw.image.exposure.exposure.ExposureF`
            The image into which the fake sources should be added
wcs : `lsst.afw.geom.SkyWcs`
            WCS to use to add fake sources

Returns
-------
fakeCat : `pandas.core.frame.DataFrame`
            The original fakeCat trimmed to the area of the image

Definition at line 501 of file insertFakes.py.

Variable Documentation

◆ convIm

lsst.pipe.tasks.insertFakes.convIm = galsim.Convolve([galsimIm, psfIm])

Definition at line 445 of file insertFakes.py.

◆ correctedFlux

lsst.pipe.tasks.insertFakes.correctedFlux = psf.computeApertureFlux(self.config.calibFluxRadius, xy)
raColName = pexConfig.Field(
    doc="RA column name used in the fake source catalog.",
    dtype=str,
    default="raJ2000",
)

decColName = pexConfig.Field(
    doc="Dec. column name used in the fake source catalog.",
    dtype=str,
    default="decJ2000",
)

doCleanCat = pexConfig.Field(
    doc="If true removes bad sources from the catalog.",
    dtype=bool,
    default=True,
)

diskHLR = pexConfig.Field(
    doc="Column name for the disk half light radius used in the fake source catalog.",
    dtype=str,
    default="DiskHalfLightRadius",
)

bulgeHLR = pexConfig.Field(
    doc="Column name for the bulge half light radius used in the fake source catalog.",
    dtype=str,
    default="BulgeHalfLightRadius",
)

magVar = pexConfig.Field(
    doc="The column name for the magnitude calculated taking variability into account. In the format "
        "``filter name``magVar, e.g. imagVar for the magnitude in the i band.",
    dtype=str,
    default="%smagVar",
)

nDisk = pexConfig.Field(
    doc="The column name for the sersic index of the disk component used in the fake source catalog.",
    dtype=str,
    default="disk_n",
)

nBulge = pexConfig.Field(
    doc="The column name for the sersic index of the bulge component used in the fake source catalog.",
    dtype=str,
    default="bulge_n",
)

aDisk = pexConfig.Field(
    doc="The column name for the semi major axis length of the disk component used in the fake source"
        "catalog.",
    dtype=str,
    default="a_d",
)

aBulge = pexConfig.Field(
    doc="The column name for the semi major axis length of the bulge component.",
    dtype=str,
    default="a_b",
)

bDisk = pexConfig.Field(
    doc="The column name for the semi minor axis length of the disk component.",
    dtype=str,
    default="b_d",
)

bBulge = pexConfig.Field(
    doc="The column name for the semi minor axis length of the bulge component used in the fake source "
        "catalog.",
    dtype=str,
    default="b_b",
)

paDisk = pexConfig.Field(
    doc="The column name for the PA of the disk component used in the fake source catalog.",
    dtype=str,
    default="pa_disk",
)

paBulge = pexConfig.Field(
    doc="The column name for the PA of the bulge component used in the fake source catalog.",
    dtype=str,
    default="pa_bulge",
)

sourceType = pexConfig.Field(
    doc="The column name for the source type used in the fake source catalog.",
    dtype=str,
    default="sourceType",
)

fakeType = pexConfig.Field(
    doc="What type of fake catalog to use, snapshot (includes variability in the magnitudes calculated "
        "from the MJD of the image), static (no variability) or filename for a user defined fits"
        "catalog.",
    dtype=str,
    default="static",
)

calibFluxRadius = pexConfig.Field(
    doc="Aperture radius (in pixels) that was used to define the calibration for this image+catalog. "
    "This will be used to produce the correct instrumental fluxes within the radius. "
    "This value should match that of the field defined in slot_CalibFlux_instFlux.",
    dtype=float,
    default=12.0,
)

coaddName = pexConfig.Field(
    doc="The name of the type of coadd used",
    dtype=str,
    default="deep",
)

doSubSelectSources = pexConfig.Field(
    doc="Set to True if you wish to sub select sources to be input based on the value in the column"
        "set in the sourceSelectionColName config option.",
    dtype=bool,
    default=False
)

sourceSelectionColName = pexConfig.Field(
    doc="The name of the column in the input fakes catalogue to be used to determine which sources to"
        "add, default is none and when this is used all sources are added.",
    dtype=str,
    default="templateSource"
)

insertImages = pexConfig.Field(
    doc="Insert images directly? True or False.",
    dtype=bool,
    default=False,
)

doProcessAllDataIds = pexConfig.Field(
    doc="If True, all input data IDs will be processed, even those containing no fake sources.",
    dtype=bool,
    default=False,
)


class InsertFakesTask(PipelineTask, CmdLineTask):

Definition at line 435 of file insertFakes.py.

◆ divIm

lsst.pipe.tasks.insertFakes.divIm = outIm/imSum

Definition at line 453 of file insertFakes.py.

◆ flux

int lsst.pipe.tasks.insertFakes.flux = photoCalib.magnitudeToInstFlux(mag, xy)

Definition at line 456 of file insertFakes.py.

◆ galsimIm

lsst.pipe.tasks.insertFakes.galsimIm = galsim.InterpolatedImage(galsim.Image(im.array), scale=pixelScale)

Definition at line 444 of file insertFakes.py.

◆ imSum

lsst.pipe.tasks.insertFakes.imSum = np.sum(outIm)

Definition at line 452 of file insertFakes.py.

◆ imWithFlux

lsst.pipe.tasks.insertFakes.imWithFlux = flux*divIm

Definition at line 460 of file insertFakes.py.

◆ outIm

lsst.pipe.tasks.insertFakes.outIm = convIm.drawImage(scale=pixelScale, method="real_space").array

Definition at line 448 of file insertFakes.py.

◆ psfIm

lsst.pipe.tasks.insertFakes.psfIm = galsim.InterpolatedImage(galsim.Image(psfKernel), scale=pixelScale)

Definition at line 443 of file insertFakes.py.

◆ psfKernel

lsst.pipe.tasks.insertFakes.psfKernel = psf.computeKernelImage(xy).getArray()

Definition at line 436 of file insertFakes.py.