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
Classes | Functions | Variables
lsst.pipe.tasks.insertFakes Namespace Reference

Classes

class  InsertFakesConnections
 

Functions

def processImagesForInsertion (self, fakeCat, wcs, psf, photoCalib, band, pixelScale)
 
def addPixCoords (self, fakeCat, image)
 
def trimFakeCat (self, fakeCat, image)
 
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

 linWcs = wcs.linearizePixelToSky(skyCoord, geom.arcseconds)
 
 mat = linWcs.getMatrix()
 
 wcs
 
 obj = galsim.InterpolatedImage(im, calculate_stepk=False)
 

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 1219 of file insertFakes.py.

1219  def addFakeSources(self, image, fakeImages, sourceType):
1220  """Add the fake sources to the given image
1221 
1222  Parameters
1223  ----------
1224  image : `lsst.afw.image.exposure.exposure.ExposureF`
1225  The image into which the fake sources should be added
1226  fakeImages : `typing.Iterator` [`tuple` ['lsst.afw.image.ImageF`, `lsst.geom.Point2d`]]
1227  An iterator of tuples that contains (or generates) images of fake sources,
1228  and the locations they are to be inserted at.
1229  sourceType : `str`
1230  The type (star/galaxy) of fake sources input
1231 
1232  Returns
1233  -------
1234  image : `lsst.afw.image.exposure.exposure.ExposureF`
1235 
1236  Notes
1237  -----
1238  Uses the x, y information in the ``fakeCat`` to position an image of the fake interpolated onto the
1239  pixel grid of the image. Sets the ``FAKE`` mask plane for the pixels added with the fake source.
1240  """
1241 
1242  imageBBox = image.getBBox()
1243  imageMI = image.maskedImage
1244 
1245  for (fakeImage, xy) in fakeImages:
1246  X0 = xy.getX() - fakeImage.getWidth()/2 + 0.5
1247  Y0 = xy.getY() - fakeImage.getHeight()/2 + 0.5
1248  self.log.debug("Adding fake source at %d, %d", xy.getX(), xy.getY())
1249  if sourceType == "galaxy":
1250  interpFakeImage = afwMath.offsetImage(fakeImage, X0, Y0, "lanczos3")
1251  else:
1252  interpFakeImage = fakeImage
1253 
1254  interpFakeImBBox = interpFakeImage.getBBox()
1255  interpFakeImBBox.clip(imageBBox)
1256 
1257  if interpFakeImBBox.getArea() > 0:
1258  imageMIView = imageMI[interpFakeImBBox]
1259  clippedFakeImage = interpFakeImage[interpFakeImBBox]
1260  clippedFakeImageMI = afwImage.MaskedImageF(clippedFakeImage)
1261  clippedFakeImageMI.mask.set(self.bitmask)
1262  imageMIView += clippedFakeImageMI
1263 
1264  return image
1265 
std::shared_ptr< ImageT > offsetImage(ImageT const &image, float dx, float dy, std::string const &algorithmName="lanczos5", unsigned int buffer=0)
Return an image offset by (dx, dy) using the specified algorithm.
Definition: offsetImage.cc:41
def addFakeSources(self, image, fakeImages, sourceType)

◆ addPixCoords()

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

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

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

Definition at line 994 of file insertFakes.py.

994  def addPixCoords(self, fakeCat, image):
995 
996  """Add pixel coordinates to the catalog of fakes.
997 
998  Parameters
999  ----------
1000  fakeCat : `pandas.core.frame.DataFrame`
1001  The catalog of fake sources to be input
1002  image : `lsst.afw.image.exposure.exposure.ExposureF`
1003  The image into which the fake sources should be added
1004 
1005  Returns
1006  -------
1007  fakeCat : `pandas.core.frame.DataFrame`
1008  """
1009  wcs = image.getWcs()
1010  ras = fakeCat['ra'].values
1011  decs = fakeCat['dec'].values
1012  xs, ys = wcs.skyToPixelArray(ras, decs)
1013  fakeCat["x"] = xs
1014  fakeCat["y"] = ys
1015 
1016  return fakeCat
1017 
def addPixCoords(self, fakeCat, image)
Definition: insertFakes.py:994

◆ 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

Definition at line 1178 of file insertFakes.py.

1178  def cleanCat(self, fakeCat, starCheckVal):
1179  """Remove rows from the fakes catalog which have HLR = 0 for either the buldge or disk component,
1180  also remove galaxies that have Sersic index outside the galsim min and max
1181  allowed (0.3 <= n <= 6.2).
1182 
1183  Parameters
1184  ----------
1185  fakeCat : `pandas.core.frame.DataFrame`
1186  The catalog of fake sources to be input
1187  starCheckVal : `str`, `bytes` or `int`
1188  The value that is set in the sourceType column to specifiy an object is a star.
1189 
1190  Returns
1191  -------
1192  fakeCat : `pandas.core.frame.DataFrame`
1193  The input catalog of fake sources but with the bad objects removed
1194  """
1195 
1196  rowsToKeep = (((fakeCat['bulge_semimajor'] != 0.0) & (fakeCat['disk_semimajor'] != 0.0))
1197  | (fakeCat[self.config.sourceType] == starCheckVal))
1198  numRowsNotUsed = len(fakeCat) - len(np.where(rowsToKeep)[0])
1199  self.log.info("Removing %d rows with HLR = 0 for either the bulge or disk", numRowsNotUsed)
1200  fakeCat = fakeCat[rowsToKeep]
1201 
1202  minN = galsim.Sersic._minimum_n
1203  maxN = galsim.Sersic._maximum_n
1204  rowsWithGoodSersic = (((fakeCat['bulge_n'] >= minN) & (fakeCat['bulge_n'] <= maxN)
1205  & (fakeCat['disk_n'] >= minN) & (fakeCat['disk_n'] <= maxN))
1206  | (fakeCat[self.config.sourceType] == starCheckVal))
1207  numRowsNotUsed = len(fakeCat) - len(np.where(rowsWithGoodSersic)[0])
1208  self.log.info("Removing %d rows of galaxies with nBulge or nDisk outside of %0.2f <= n <= %0.2f",
1209  numRowsNotUsed, minN, maxN)
1210  fakeCat = fakeCat[rowsWithGoodSersic]
1211 
1212  if self.config.doSubSelectSources:
1213  numRowsNotUsed = len(fakeCat) - len(fakeCat['select'])
1214  self.log.info("Removing %d rows which were not designated as template sources", numRowsNotUsed)
1215  fakeCat = fakeCat[fakeCat['select']]
1216 
1217  return fakeCat
1218 
def cleanCat(self, fakeCat, starCheckVal)

◆ 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 1047 of file insertFakes.py.

1047  def mkFakeGalsimGalaxies(self, fakeCat, band, photoCalib, pixelScale, psf, image):
1048  """Make images of fake galaxies using GalSim.
1049 
1050  Parameters
1051  ----------
1052  band : `str`
1053  pixelScale : `float`
1054  psf : `lsst.meas.extensions.psfex.psfexPsf.PsfexPsf`
1055  The PSF information to use to make the PSF images
1056  fakeCat : `pandas.core.frame.DataFrame`
1057  The catalog of fake sources to be input
1058  photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`
1059  Photometric calibration to be used to calibrate the fake sources
1060 
1061  Yields
1062  -------
1063  galImages : `generator`
1064  A generator of tuples of `lsst.afw.image.exposure.exposure.ExposureF` and
1065  `lsst.geom.Point2D` of their locations.
1066 
1067  Notes
1068  -----
1069 
1070  Fake galaxies are made by combining two sersic profiles, one for the bulge and one for the disk. Each
1071  component has an individual sersic index (n), a, b and position angle (PA). The combined profile is
1072  then convolved with the PSF at the specified x, y position on the image.
1073 
1074  The names of the columns in the ``fakeCat`` are configurable and are the column names from the
1075  University of Washington simulations database as default. For more information see the doc strings
1076  attached to the config options.
1077 
1078  See mkFakeStars doc string for an explanation of calibration to instrumental flux.
1079  """
1080 
1081  self.log.info("Making %d fake galaxy images", len(fakeCat))
1082 
1083  for (index, row) in fakeCat.iterrows():
1084  xy = geom.Point2D(row["x"], row["y"])
1085 
1086  # We put these two PSF calculations within this same try block so that we catch cases
1087  # where the object's position is outside of the image.
1088  try:
1089  correctedFlux = psf.computeApertureFlux(self.config.calibFluxRadius, xy)
1090  psfKernel = psf.computeKernelImage(xy).getArray()
1091  psfKernel /= correctedFlux
1092 
1093  except InvalidParameterError:
1094  self.log.info("Galaxy at %0.4f, %0.4f outside of image", row["x"], row["y"])
1095  continue
1096 
1097  try:
1098  flux = photoCalib.magnitudeToInstFlux(row['mag'], xy)
1099  except LogicError:
1100  flux = 0
1101 
1102  # GalSim convention: HLR = sqrt(a * b) = a * sqrt(b / a)
1103  bulge_gs_HLR = row['bulge_semimajor']*np.sqrt(row['bulge_axis_ratio'])
1104  bulge = galsim.Sersic(n=row['bulge_n'], half_light_radius=bulge_gs_HLR)
1105  bulge = bulge.shear(q=row['bulge_axis_ratio'], beta=((90 - row['bulge_pa'])*galsim.degrees))
1106 
1107  disk_gs_HLR = row['disk_semimajor']*np.sqrt(row['disk_axis_ratio'])
1108  disk = galsim.Sersic(n=row['disk_n'], half_light_radius=disk_gs_HLR)
1109  disk = disk.shear(q=row['disk_axis_ratio'], beta=((90 - row['disk_pa'])*galsim.degrees))
1110 
1111  gal = bulge*row['bulge_disk_flux_ratio'] + disk
1112  gal = gal.withFlux(flux)
1113 
1114  psfIm = galsim.InterpolatedImage(galsim.Image(psfKernel), scale=pixelScale)
1115  gal = galsim.Convolve([gal, psfIm])
1116  try:
1117  galIm = gal.drawImage(scale=pixelScale, method="real_space").array
1118  except (galsim.errors.GalSimFFTSizeError, MemoryError):
1119  continue
1120 
1121  yield (afwImage.ImageF(galIm), xy)
1122 
def mkFakeGalsimGalaxies(self, fakeCat, band, photoCalib, pixelScale, psf, image)

◆ 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 1123 of file insertFakes.py.

1123  def mkFakeStars(self, fakeCat, band, photoCalib, psf, image):
1124 
1125  """Make fake stars based off the properties in the fakeCat.
1126 
1127  Parameters
1128  ----------
1129  band : `str`
1130  psf : `lsst.meas.extensions.psfex.psfexPsf.PsfexPsf`
1131  The PSF information to use to make the PSF images
1132  fakeCat : `pandas.core.frame.DataFrame`
1133  The catalog of fake sources to be input
1134  image : `lsst.afw.image.exposure.exposure.ExposureF`
1135  The image into which the fake sources should be added
1136  photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`
1137  Photometric calibration to be used to calibrate the fake sources
1138 
1139  Yields
1140  -------
1141  starImages : `generator`
1142  A generator of tuples of `lsst.afw.image.ImageF` of fake stars and
1143  `lsst.geom.Point2D` of their locations.
1144 
1145  Notes
1146  -----
1147  To take a given magnitude and translate to the number of counts in the image
1148  we use photoCalib.magnitudeToInstFlux, which returns the instrumental flux for the
1149  given calibration radius used in the photometric calibration step.
1150  Thus `calibFluxRadius` should be set to this same radius so that we can normalize
1151  the PSF model to the correct instrumental flux within calibFluxRadius.
1152  """
1153 
1154  self.log.info("Making %d fake star images", len(fakeCat))
1155 
1156  for (index, row) in fakeCat.iterrows():
1157  xy = geom.Point2D(row["x"], row["y"])
1158 
1159  # We put these two PSF calculations within this same try block so that we catch cases
1160  # where the object's position is outside of the image.
1161  try:
1162  correctedFlux = psf.computeApertureFlux(self.config.calibFluxRadius, xy)
1163  starIm = psf.computeImage(xy)
1164  starIm /= correctedFlux
1165 
1166  except InvalidParameterError:
1167  self.log.info("Star at %0.4f, %0.4f outside of image", row["x"], row["y"])
1168  continue
1169 
1170  try:
1171  flux = photoCalib.magnitudeToInstFlux(row['mag'], xy)
1172  except LogicError:
1173  flux = 0
1174 
1175  starIm *= flux
1176  yield ((starIm.convertF(), xy))
1177 
def mkFakeStars(self, fakeCat, band, photoCalib, psf, image)

◆ processImagesForInsertion()

def lsst.pipe.tasks.insertFakes.processImagesForInsertion (   self,
  fakeCat,
  wcs,
  psf,
  photoCalib,
  band,
  pixelScale 
)
Process images from files into the format needed for insertion.

Parameters
----------
fakeCat : `pandas.core.frame.DataFrame`
            The catalog of fake sources to be input
wcs : `lsst.afw.geom.skyWcs.skyWcs.SkyWc`
            WCS to use to add fake sources
psf : `lsst.meas.algorithms.coaddPsf.coaddPsf.CoaddPsf` or
      `lsst.meas.extensions.psfex.psfexPsf.PsfexPsf`
            The PSF information to use to make the PSF images
photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`
            Photometric calibration to be used to calibrate the fake sources
band : `str`
            The filter band that the observation was taken in.
pixelScale : `float`
            The pixel scale of the image the sources are to be added to.

Returns
-------
galImages : `list`
            A list of tuples of `lsst.afw.image.exposure.exposure.ExposureF` and
            `lsst.geom.Point2D` of their locations.
            For sources labelled as galaxy.
starImages : `list`
            A list of tuples of `lsst.afw.image.exposure.exposure.ExposureF` and
            `lsst.geom.Point2D` of their locations.
            For sources labelled as star.

Notes
-----
The input fakes catalog needs to contain the absolute path to the image in the
band that is being used to add images to. It also needs to have the R.A. and
declination of the fake source in radians and the sourceType of the object.

Definition at line 907 of file insertFakes.py.

907  def processImagesForInsertion(self, fakeCat, wcs, psf, photoCalib, band, pixelScale):
908  """Process images from files into the format needed for insertion.
909 
910  Parameters
911  ----------
912  fakeCat : `pandas.core.frame.DataFrame`
913  The catalog of fake sources to be input
914  wcs : `lsst.afw.geom.skyWcs.skyWcs.SkyWc`
915  WCS to use to add fake sources
916  psf : `lsst.meas.algorithms.coaddPsf.coaddPsf.CoaddPsf` or
917  `lsst.meas.extensions.psfex.psfexPsf.PsfexPsf`
918  The PSF information to use to make the PSF images
919  photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`
920  Photometric calibration to be used to calibrate the fake sources
921  band : `str`
922  The filter band that the observation was taken in.
923  pixelScale : `float`
924  The pixel scale of the image the sources are to be added to.
925 
926  Returns
927  -------
928  galImages : `list`
929  A list of tuples of `lsst.afw.image.exposure.exposure.ExposureF` and
930  `lsst.geom.Point2D` of their locations.
931  For sources labelled as galaxy.
932  starImages : `list`
933  A list of tuples of `lsst.afw.image.exposure.exposure.ExposureF` and
934  `lsst.geom.Point2D` of their locations.
935  For sources labelled as star.
936 
937  Notes
938  -----
939  The input fakes catalog needs to contain the absolute path to the image in the
940  band that is being used to add images to. It also needs to have the R.A. and
941  declination of the fake source in radians and the sourceType of the object.
942  """
943  galImages = []
944  starImages = []
945 
946  self.log.info("Processing %d fake images", len(fakeCat))
947 
948  for (imFile, sourceType, mag, x, y) in zip(fakeCat[band + "imFilename"].array,
949  fakeCat["sourceType"].array,
950  fakeCat['mag'].array,
951  fakeCat["x"].array, fakeCat["y"].array):
952 
953  im = afwImage.ImageF.readFits(imFile)
954 
955  xy = geom.Point2D(x, y)
956 
957  # We put these two PSF calculations within this same try block so that we catch cases
958  # where the object's position is outside of the image.
959  try:
960  correctedFlux = psf.computeApertureFlux(self.config.calibFluxRadius, xy)
961  psfKernel = psf.computeKernelImage(xy).getArray()
962  psfKernel /= correctedFlux
963 
964  except InvalidParameterError:
965  self.log.info("%s at %0.4f, %0.4f outside of image", sourceType, x, y)
966  continue
967 
968  psfIm = galsim.InterpolatedImage(galsim.Image(psfKernel), scale=pixelScale)
969  galsimIm = galsim.InterpolatedImage(galsim.Image(im.array), scale=pixelScale)
970  convIm = galsim.Convolve([galsimIm, psfIm])
971 
972  try:
973  outIm = convIm.drawImage(scale=pixelScale, method="real_space").array
974  except (galsim.errors.GalSimFFTSizeError, MemoryError):
975  continue
976 
977  imSum = np.sum(outIm)
978  divIm = outIm/imSum
979 
980  try:
981  flux = photoCalib.magnitudeToInstFlux(mag, xy)
982  except LogicError:
983  flux = 0
984 
985  imWithFlux = flux*divIm
986 
987  if sourceType == b"galaxy":
988  galImages.append((afwImage.ImageF(imWithFlux), xy))
989  if sourceType == b"star":
990  starImages.append((afwImage.ImageF(imWithFlux), xy))
991 
992  return galImages, starImages
993 
def processImagesForInsertion(self, fakeCat, wcs, psf, photoCalib, band, pixelScale)
Definition: insertFakes.py:907

◆ trimFakeCat()

def lsst.pipe.tasks.insertFakes.trimFakeCat (   self,
  fakeCat,
  image 
)
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

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

Definition at line 1018 of file insertFakes.py.

1018  def trimFakeCat(self, fakeCat, image):
1019  """Trim the fake cat to about the size of the input image.
1020 
1021  `fakeCat` must be processed with addPixCoords before using this method.
1022 
1023  Parameters
1024  ----------
1025  fakeCat : `pandas.core.frame.DataFrame`
1026  The catalog of fake sources to be input
1027  image : `lsst.afw.image.exposure.exposure.ExposureF`
1028  The image into which the fake sources should be added
1029 
1030  Returns
1031  -------
1032  fakeCat : `pandas.core.frame.DataFrame`
1033  The original fakeCat trimmed to the area of the image
1034  """
1035 
1036  bbox = Box2D(image.getBBox()).dilatedBy(self.config.trimBuffer)
1037  xs = fakeCat["x"].values
1038  ys = fakeCat["y"].values
1039 
1040  isContained = xs >= bbox.minX
1041  isContained &= xs <= bbox.maxX
1042  isContained &= ys >= bbox.minY
1043  isContained &= ys <= bbox.maxY
1044 
1045  return fakeCat[isContained]
1046 
def trimFakeCat(self, fakeCat, image)

Variable Documentation

◆ linWcs

lsst.pipe.tasks.insertFakes.linWcs = wcs.linearizePixelToSky(skyCoord, geom.arcseconds)
# Unchanged

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

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
)

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,
)

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 for fake source injection.",
    dtype=int,
    default=100,
)

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

fits_alignment = pexConfig.ChoiceField(
    doc="How should injections from FITS files be aligned?",
    dtype=str,
    allowed={
        "wcs": (
            "Input image will be transformed such that the local WCS in "
            "the FITS header matches the local WCS in the target image. "
            "I.e., North, East, and angular distances in the input image "
            "will match North, East, and angular distances in the target "
            "image."
        ),
        "pixel": (
            "Input image will _not_ be transformed.  Up, right, and pixel "
            "distances in the input image will match up, right and pixel "
            "distances in the target image."
        )
    },
    default="pixel"
)

# New source catalog config variables

ra_col = pexConfig.Field(
    doc="Source catalog column name for RA (in radians).",
    dtype=str,
    default="ra",
)

dec_col = pexConfig.Field(
    doc="Source catalog column name for dec (in radians).",
    dtype=str,
    default="dec",
)

bulge_semimajor_col = pexConfig.Field(
    doc="Source catalog column name for the semimajor axis (in arcseconds) "
        "of the bulge half-light ellipse.",
    dtype=str,
    default="bulge_semimajor",
)

bulge_axis_ratio_col = pexConfig.Field(
    doc="Source catalog column name for the axis ratio of the bulge "
        "half-light ellipse.",
    dtype=str,
    default="bulge_axis_ratio",
)

bulge_pa_col = pexConfig.Field(
    doc="Source catalog column name for the position angle (measured from "
        "North through East in degrees) of the semimajor axis of the bulge "
        "half-light ellipse.",
    dtype=str,
    default="bulge_pa",
)

bulge_n_col = pexConfig.Field(
    doc="Source catalog column name for the Sersic index of the bulge.",
    dtype=str,
    default="bulge_n",
)

disk_semimajor_col = pexConfig.Field(
    doc="Source catalog column name for the semimajor axis (in arcseconds) "
        "of the disk half-light ellipse.",
    dtype=str,
    default="disk_semimajor",
)

disk_axis_ratio_col = pexConfig.Field(
    doc="Source catalog column name for the axis ratio of the disk "
        "half-light ellipse.",
    dtype=str,
    default="disk_axis_ratio",
)

disk_pa_col = pexConfig.Field(
    doc="Source catalog column name for the position angle (measured from "
        "North through East in degrees) of the semimajor axis of the disk "
        "half-light ellipse.",
    dtype=str,
    default="disk_pa",
)

disk_n_col = pexConfig.Field(
    doc="Source catalog column name for the Sersic index of the disk.",
    dtype=str,
    default="disk_n",
)

bulge_disk_flux_ratio_col = pexConfig.Field(
    doc="Source catalog column name for the bulge/disk flux ratio.",
    dtype=str,
    default="bulge_disk_flux_ratio",
)

mag_col = pexConfig.Field(
    doc="Source catalog column name template for magnitudes, in the format "
        "``filter name``_mag_col.  E.g., if this config variable is set to "
        "``%s_mag``, then the i-band magnitude will be searched for in the "
        "``i_mag`` column of the source catalog.",
    dtype=str,
    default="%s_mag"
)

select_col = pexConfig.Field(
    doc="Source catalog column name to be used to select which sources to "
        "add.",
    dtype=str,
    default="select",
)

# Deprecated config variables

raColName = pexConfig.Field(
    doc="RA column name used in the fake source catalog.",
    dtype=str,
    default="raJ2000",
    deprecated="Use `ra_col` instead."
)

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

diskHLR = pexConfig.Field(
    doc="Column name for the disk half light radius used in the fake source catalog.",
    dtype=str,
    default="DiskHalfLightRadius",
    deprecated=(
        "Use `disk_semimajor_col`, `disk_axis_ratio_col`, and `disk_pa_col`"
        " to specify disk half-light ellipse."
    )
)

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",
    deprecated=(
        "Use `disk_semimajor_col`, `disk_axis_ratio_col`, and `disk_pa_col`"
        " to specify disk half-light ellipse."
    )
)

bDisk = pexConfig.Field(
    doc="The column name for the semi minor axis length of the disk component.",
    dtype=str,
    default="b_d",
    deprecated=(
        "Use `disk_semimajor_col`, `disk_axis_ratio_col`, and `disk_pa_col`"
        " to specify disk half-light ellipse."
    )
)

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",
    deprecated=(
        "Use `disk_semimajor_col`, `disk_axis_ratio_col`, and `disk_pa_col`"
        " to specify disk half-light ellipse."
    )
)

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",
    deprecated="Use `disk_n` instead."
)

bulgeHLR = pexConfig.Field(
    doc="Column name for the bulge half light radius used in the fake source catalog.",
    dtype=str,
    default="BulgeHalfLightRadius",
    deprecated=(
        "Use `bulge_semimajor_col`, `bulge_axis_ratio_col`, and "
        "`bulge_pa_col` to specify disk half-light ellipse."
    )
)

aBulge = pexConfig.Field(
    doc="The column name for the semi major axis length of the bulge component.",
    dtype=str,
    default="a_b",
    deprecated=(
        "Use `bulge_semimajor_col`, `bulge_axis_ratio_col`, and "
        "`bulge_pa_col` to specify disk half-light ellipse."
    )
)

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",
    deprecated=(
        "Use `bulge_semimajor_col`, `bulge_axis_ratio_col`, and "
        "`bulge_pa_col` to specify disk half-light ellipse."
    )
)

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",
    deprecated=(
        "Use `bulge_semimajor_col`, `bulge_axis_ratio_col`, and "
        "`bulge_pa_col` to specify disk half-light ellipse."
    )
)

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",
    deprecated="Use `bulge_n` instead."
)

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",
    deprecated="Use `mag_col` instead."
)

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",
    deprecated="Use `select_col` instead."
)


class InsertFakesTask(PipelineTask, CmdLineTask):

Definition at line 893 of file insertFakes.py.

◆ mat

lsst.pipe.tasks.insertFakes.mat = linWcs.getMatrix()

Definition at line 894 of file insertFakes.py.

◆ obj

lsst.pipe.tasks.insertFakes.obj = galsim.InterpolatedImage(im, calculate_stepk=False)

Definition at line 903 of file insertFakes.py.

◆ wcs

lsst.pipe.tasks.insertFakes.wcs

Definition at line 895 of file insertFakes.py.