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
819 schema = afwTable.SourceTable.makeMinimalSchema()
820
821
822 detectConfig = measAlg.SourceDetectionConfig()
823 detectConfig.returnOriginalFootprints = False
824
825
826 detectConfig.thresholdPolarity = "both"
827 detectConfig.thresholdValue = detectSigma
828
829 detectConfig.reEstimateBackground = True
830 detectConfig.thresholdType = "pixel_stdev"
831 detectConfig.excludeMaskPlanes = ["EDGE"]
832
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
838 detectTask = measAlg.SourceDetectionTask(schema, config=detectConfig)
839
840 table = afwTable.SourceTable.make(schema)
841 catalog = detectTask.run(table, diffim)
842
843
844 if doMerge:
845 fpSet = catalog.positive
846 fpSet.merge(catalog.negative, grow, grow, False)
848 fpSet.makeSources(sources)
849
850 return sources
851
852 else:
853 return detectTask, schema
854
855