LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+f5613e8b4f,g1470d8bcf6+190ad2ba91,g14a832a312+311607e4ab,g2079a07aa2+86d27d4dc4,g2305ad1205+a8e3196225,g295015adf3+b67ee847e5,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+a761f810f3,g487adcacf7+17c8fdbcbd,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+65b5bd823e,g5a732f18d5+53520f316c,g64a986408d+f5613e8b4f,g6c1bc301e9+51106c2951,g858d7b2824+f5613e8b4f,g8a8a8dda67+585e252eca,g99cad8db69+6729933424,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e9bba80f27,gc120e1dc64+eee469a5e5,gc28159a63d+0e5473021a,gcf0d15dbbd+a761f810f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+d4c1d4bfef,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf1cff7945b+f5613e8b4f,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
lsst.ip.diffim.utils.DipoleTestImage Class Reference

Public Member Functions

 __init__ (self, w=101, h=101, xcenPos=[27.], ycenPos=[25.], xcenNeg=[23.], ycenNeg=[25.], psfSigma=2., flux=[30000.], fluxNeg=None, noise=10., gradientParams=None)
 
 fitDipoleSource (self, source, **kwds)
 
 detectDipoleSources (self, doMerge=True, diffim=None, detectSigma=5.5, grow=3, minBinSize=32)
 

Public Attributes

 w
 
 h
 
 xcenPos
 
 ycenPos
 
 xcenNeg
 
 ycenNeg
 
 psfSigma
 
 flux
 
 fluxNeg
 
 noise
 
 gradientParams
 
 diffim
 
 posImage
 
 posCatalog
 
 negImage
 

Protected Member Functions

 _makeDipoleImage (self)
 
 _makeStarImage (self, xc=[15.3], yc=[18.6], flux=[2500], schema=None, randomSeed=None)
 

Detailed Description

Utility class for dipole measurement testing.

Generate an image with simulated dipoles and noise; store the original
"pre-subtraction" images and catalogs as well.
Used to generate test data for DMTN-007 (http://dmtn-007.lsst.io).

Definition at line 709 of file utils.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.ip.diffim.utils.DipoleTestImage.__init__ ( self,
w = 101,
h = 101,
xcenPos = [27.],
ycenPos = [25.],
xcenNeg = [23.],
ycenNeg = [25.],
psfSigma = 2.,
flux = [30000.],
fluxNeg = None,
noise = 10.,
gradientParams = None )

Definition at line 717 of file utils.py.

718 psfSigma=2., flux=[30000.], fluxNeg=None, noise=10., gradientParams=None):
719 self.w = w
720 self.h = h
721 self.xcenPos = xcenPos
722 self.ycenPos = ycenPos
723 self.xcenNeg = xcenNeg
724 self.ycenNeg = ycenNeg
725 self.psfSigma = psfSigma
726 self.flux = flux
727 self.fluxNeg = fluxNeg
728 if fluxNeg is None:
729 self.fluxNeg = self.flux
730 self.noise = noise
731 self.gradientParams = gradientParams
732 self._makeDipoleImage()
733

Member Function Documentation

◆ _makeDipoleImage()

lsst.ip.diffim.utils.DipoleTestImage._makeDipoleImage ( self)
protected
Generate an exposure and catalog with the given dipole source(s).

Definition at line 734 of file utils.py.

734 def _makeDipoleImage(self):
735 """Generate an exposure and catalog with the given dipole source(s).
736 """
737 # Must seed the pos/neg images with different values to ensure they get different noise realizations
738 posImage, posCatalog = self._makeStarImage(
739 xc=self.xcenPos, yc=self.ycenPos, flux=self.flux, randomSeed=111)
740
741 negImage, negCatalog = self._makeStarImage(
742 xc=self.xcenNeg, yc=self.ycenNeg, flux=self.fluxNeg, randomSeed=222)
743
744 dipole = posImage.clone()
745 di = dipole.getMaskedImage()
746 di -= negImage.getMaskedImage()
747
748 self.diffim, self.posImage, self.posCatalog, self.negImage, self.negCatalog \
749 = dipole, posImage, posCatalog, negImage, negCatalog
750

◆ _makeStarImage()

lsst.ip.diffim.utils.DipoleTestImage._makeStarImage ( self,
xc = [15.3],
yc = [18.6],
flux = [2500],
schema = None,
randomSeed = None )
protected
Generate an exposure and catalog with the given stellar source(s).

Definition at line 751 of file utils.py.

751 def _makeStarImage(self, xc=[15.3], yc=[18.6], flux=[2500], schema=None, randomSeed=None):
752 """Generate an exposure and catalog with the given stellar source(s).
753 """
754 from lsst.meas.base.tests import TestDataset
755 bbox = geom.Box2I(geom.Point2I(0, 0), geom.Point2I(self.w - 1, self.h - 1))
756 dataset = TestDataset(bbox, psfSigma=self.psfSigma, threshold=1.)
757
758 for i in range(len(xc)):
759 dataset.addSource(instFlux=flux[i], centroid=geom.Point2D(xc[i], yc[i]))
760
761 if schema is None:
762 schema = TestDataset.makeMinimalSchema()
763 exposure, catalog = dataset.realize(noise=self.noise, schema=schema, randomSeed=randomSeed)
764
765 if self.gradientParams is not None:
766 y, x = np.mgrid[:self.w, :self.h]
767 gp = self.gradientParams
768 gradient = gp[0] + gp[1]*x + gp[2]*y
769 if len(self.gradientParams) > 3: # it includes a set of 2nd-order polynomial params
770 gradient += gp[3]*x*y + gp[4]*x*x + gp[5]*y*y
771 imgArr = exposure.image.array
772 imgArr += gradient
773
774 return exposure, catalog
775
An integer coordinate rectangle.
Definition Box.h:55

◆ detectDipoleSources()

lsst.ip.diffim.utils.DipoleTestImage.detectDipoleSources ( self,
doMerge = True,
diffim = None,
detectSigma = 5.5,
grow = 3,
minBinSize = 32 )
Utility function for detecting dipoles.

Detect pos/neg sources in the diffim, then merge them. A
bigger "grow" parameter leads to a larger footprint which
helps with dipole measurement for faint dipoles.

Parameters
----------
doMerge : `bool`
   Whether to merge the positive and negagive detections into a single
   source table.
diffim : `lsst.afw.image.exposure.exposure.ExposureF`
   Difference image on which to perform detection.
detectSigma : `float`
   Threshold for object detection.
grow : `int`
   Number of pixels to grow the footprints before merging.
minBinSize : `int`
   Minimum bin size for the background (re)estimation (only applies if
   the default leads to min(nBinX, nBinY) < fit order so the default
   config parameter needs to be decreased, but not to a value smaller
   than ``minBinSize``, in which case the fitting algorithm will take
   over and decrease the fit order appropriately.)

Returns
-------
sources : `lsst.afw.table.SourceCatalog`
   If doMerge=True, the merged source catalog is returned OR
detectTask : `lsst.meas.algorithms.SourceDetectionTask`
schema : `lsst.afw.table.Schema`
   If doMerge=False, the source detection task and its schema are
   returned.

Definition at line 781 of file utils.py.

781 def detectDipoleSources(self, doMerge=True, diffim=None, detectSigma=5.5, grow=3, minBinSize=32):
782 """Utility function for detecting dipoles.
783
784 Detect pos/neg sources in the diffim, then merge them. A
785 bigger "grow" parameter leads to a larger footprint which
786 helps with dipole measurement for faint dipoles.
787
788 Parameters
789 ----------
790 doMerge : `bool`
791 Whether to merge the positive and negagive detections into a single
792 source table.
793 diffim : `lsst.afw.image.exposure.exposure.ExposureF`
794 Difference image on which to perform detection.
795 detectSigma : `float`
796 Threshold for object detection.
797 grow : `int`
798 Number of pixels to grow the footprints before merging.
799 minBinSize : `int`
800 Minimum bin size for the background (re)estimation (only applies if
801 the default leads to min(nBinX, nBinY) < fit order so the default
802 config parameter needs to be decreased, but not to a value smaller
803 than ``minBinSize``, in which case the fitting algorithm will take
804 over and decrease the fit order appropriately.)
805
806 Returns
807 -------
808 sources : `lsst.afw.table.SourceCatalog`
809 If doMerge=True, the merged source catalog is returned OR
810 detectTask : `lsst.meas.algorithms.SourceDetectionTask`
811 schema : `lsst.afw.table.Schema`
812 If doMerge=False, the source detection task and its schema are
813 returned.
814 """
815 if diffim is None:
816 diffim = self.diffim
817
818 # Start with a minimal schema - only the fields all SourceCatalogs need
819 schema = afwTable.SourceTable.makeMinimalSchema()
820
821 # Customize the detection task a bit (optional)
822 detectConfig = measAlg.SourceDetectionConfig()
823 detectConfig.returnOriginalFootprints = False # should be the default
824
825 # code from imageDifference.py:
826 detectConfig.thresholdPolarity = "both"
827 detectConfig.thresholdValue = detectSigma
828 # detectConfig.nSigmaToGrow = psfSigma
829 detectConfig.reEstimateBackground = True # if False, will fail often for faint sources on gradients?
830 detectConfig.thresholdType = "pixel_stdev"
831 detectConfig.excludeMaskPlanes = ["EDGE"]
832 # Test images are often quite small, so may need to adjust background binSize
833 while ((min(diffim.getWidth(), diffim.getHeight()))//detectConfig.background.binSize
834 < detectConfig.background.approxOrderX and detectConfig.background.binSize > minBinSize):
835 detectConfig.background.binSize = max(minBinSize, detectConfig.background.binSize//2)
836
837 # Create the detection task. We pass the schema so the task can declare a few flag fields
838 detectTask = measAlg.SourceDetectionTask(schema, config=detectConfig)
839
840 table = afwTable.SourceTable.make(schema)
841 catalog = detectTask.run(table, diffim)
842
843 # Now do the merge.
844 if doMerge:
845 fpSet = catalog.positive
846 fpSet.merge(catalog.negative, grow, grow, False)
847 sources = afwTable.SourceCatalog(table)
848 fpSet.makeSources(sources)
849
850 return sources
851
852 else:
853 return detectTask, schema
854
855
int min
int max

◆ fitDipoleSource()

lsst.ip.diffim.utils.DipoleTestImage.fitDipoleSource ( self,
source,
** kwds )

Definition at line 776 of file utils.py.

776 def fitDipoleSource(self, source, **kwds):
777 alg = DipoleFitAlgorithm(self.diffim, self.posImage, self.negImage)
778 fitResult = alg.fitDipole(source, **kwds)
779 return fitResult
780

Member Data Documentation

◆ diffim

lsst.ip.diffim.utils.DipoleTestImage.diffim

Definition at line 748 of file utils.py.

◆ flux

lsst.ip.diffim.utils.DipoleTestImage.flux

Definition at line 726 of file utils.py.

◆ fluxNeg

lsst.ip.diffim.utils.DipoleTestImage.fluxNeg

Definition at line 727 of file utils.py.

◆ gradientParams

lsst.ip.diffim.utils.DipoleTestImage.gradientParams

Definition at line 731 of file utils.py.

◆ h

lsst.ip.diffim.utils.DipoleTestImage.h

Definition at line 720 of file utils.py.

◆ negImage

lsst.ip.diffim.utils.DipoleTestImage.negImage

Definition at line 748 of file utils.py.

◆ noise

lsst.ip.diffim.utils.DipoleTestImage.noise

Definition at line 730 of file utils.py.

◆ posCatalog

lsst.ip.diffim.utils.DipoleTestImage.posCatalog

Definition at line 748 of file utils.py.

◆ posImage

lsst.ip.diffim.utils.DipoleTestImage.posImage

Definition at line 748 of file utils.py.

◆ psfSigma

lsst.ip.diffim.utils.DipoleTestImage.psfSigma

Definition at line 725 of file utils.py.

◆ w

lsst.ip.diffim.utils.DipoleTestImage.w

Definition at line 719 of file utils.py.

◆ xcenNeg

lsst.ip.diffim.utils.DipoleTestImage.xcenNeg

Definition at line 723 of file utils.py.

◆ xcenPos

lsst.ip.diffim.utils.DipoleTestImage.xcenPos

Definition at line 721 of file utils.py.

◆ ycenNeg

lsst.ip.diffim.utils.DipoleTestImage.ycenNeg

Definition at line 724 of file utils.py.

◆ ycenPos

lsst.ip.diffim.utils.DipoleTestImage.ycenPos

Definition at line 722 of file utils.py.


The documentation for this class was generated from the following file: