def getBackground(image, backgroundConfig, nx=0, ny=0, algorithm=None): """ Make a new Exposure which is exposure - background """ backgroundConfig.validate() if not nx: nx = image.getWidth() // backgroundConfig.binSize + 1 if not ny: ny = image.getHeight() // backgroundConfig.binSize + 1 sctrl = afwMath.StatisticsControl() sctrl.setAndMask( reduce(lambda x, y: x | image.getMask().getPlaneBitMask(y), backgroundConfig.ignoredPixelMask, 0x0)) sctrl.setNanSafe(backgroundConfig.isNanSafe) pl = pexLogging.Debug("meas.utils.sourceDetection.getBackground") pl.debug( 3, "Ignoring mask planes: %s" % ", ".join(backgroundConfig.ignoredPixelMask)) if not algorithm: algorithm = backgroundConfig.algorithm bctrl = afwMath.BackgroundControl(algorithm, nx, ny, backgroundConfig.undersampleStyle, sctrl, backgroundConfig.statisticsProperty) return afwMath.makeBackground(image, bctrl)
def _assignClusters(yvec, centers): """Return a vector of centerIds based on their distance to the centers""" assert len(centers) > 0 minDist = numpy.nan*numpy.ones_like(yvec) clusterId = numpy.empty_like(yvec) clusterId.dtype = int # zeros_like(..., dtype=int) isn't in numpy 1.5 dbl = log.Debug("objectSizeStarSelector._assignClusters", 0) # Make sure we are logging aall numpy warnings... oldSettings = numpy.seterr(all="warn") with warnings.catch_warnings(record = True) as w: warnings.simplefilter("always") for i, mean in enumerate(centers): dist = abs(yvec - mean) if i == 0: update = dist == dist # True for all points else: update = dist < minDist if w: # Only do if w is not empty i.e. contains a warning message dbl.debug(2, str(w[-1])) minDist[update] = dist[update] clusterId[update] = i numpy.seterr(**oldSettings) return clusterId
def __init__(self, config): """ @param[in] config: instance of PolypixPsfDeterminerConfig """ self.config = config # N.b. name of component is meas.algorithms.psfDeterminer so you can turn on psf debugging # independent of which determiner is active self.debugLog = pexLog.Debug("meas.algorithms.psfDeterminer") self.warnLog = pexLog.Log(pexLog.getDefaultLog(), "meas.algorithms.psfDeterminer")
def getBackground(image, backgroundConfig, nx=0, ny=0, algorithm=None): """ Make a new Exposure which is exposure - background """ backgroundConfig.validate() if not nx: nx = image.getWidth() // backgroundConfig.binSize + 1 if not ny: ny = image.getHeight() // backgroundConfig.binSize + 1 displayBackground = lsstDebug.Info(__name__).displayBackground if displayBackground: import itertools ds9.mtv(image, frame=1) xPosts = numpy.rint( numpy.linspace(0, image.getWidth() + 1, num=nx, endpoint=True)) yPosts = numpy.rint( numpy.linspace(0, image.getHeight() + 1, num=ny, endpoint=True)) with ds9.Buffering(): for (xMin, xMax), (yMin, yMax) in itertools.product( zip(xPosts[:-1], xPosts[1:]), zip(yPosts[:-1], yPosts[1:])): ds9.line([(xMin, yMin), (xMin, yMax), (xMax, yMax), (xMax, yMin), (xMin, yMin)], frame=1) sctrl = afwMath.StatisticsControl() sctrl.setAndMask( reduce(lambda x, y: x | image.getMask().getPlaneBitMask(y), backgroundConfig.ignoredPixelMask, 0x0)) sctrl.setNanSafe(backgroundConfig.isNanSafe) pl = pexLogging.Debug("meas.utils.sourceDetection.getBackground") pl.debug( 3, "Ignoring mask planes: %s" % ", ".join(backgroundConfig.ignoredPixelMask)) if not algorithm: algorithm = backgroundConfig.algorithm bctrl = afwMath.BackgroundControl(algorithm, nx, ny, backgroundConfig.undersampleStyle, sctrl, backgroundConfig.statisticsProperty) if backgroundConfig.useApprox: actrl = afwMath.ApproximateControl( afwMath.ApproximateControl.CHEBYSHEV, backgroundConfig.approxOrder) bctrl.setApproximateControl(actrl) return afwMath.makeBackground(image, bctrl)
# import itertools import math import unittest import numpy import lsst.afw.geom as afwGeom import lsst.afw.math as afwMath import lsst.utils.tests as utilsTests import lsst.pex.logging as pexLog VERBOSITY = 0 # increase to see trace pexLog.Debug("lsst.afwMath", VERBOSITY) #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- def nrange(num, start, delta): """Return an array of num floats starting with start and incrementing by delta """ return numpy.arange(start, start + (delta * (num - 0.1)), delta) def sinc(x): """Return the normalized sinc function: sinc(x) = sin(pi * x) / (pi * x) """ if abs(x) < 1.0e-15: return 1.0
# the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. # import math import sys import os import time import lsst.utils import lsst.pex.logging as pexLog import lsst.afw.image as afwImage import lsst.afw.math as afwMath import lsst.afw.geom as afwGeom pexLog.Debug("lsst.afw", 0) MaxIter = 20 MaxTime = 1.0 # seconds afwdataDir = lsst.utils.getPackageDir("afwdata") InputMaskedImagePath = os.path.join(afwdataDir, "data", "med.fits") def getSpatialParameters(nKernelParams, func): """Get basic spatial parameters list You may wish to tweak it up for specific cases (especially the lower order terms) """ nCoeff = func.getNParameters() spParams = [[0.0]*nCoeff]*nKernelParams
import numpy as np import os import unittest import lsst.utils.tests as tests import lsst.pex.logging as logging import lsst.afw.image as afwImage import lsst.afw.detection as afwDetect import lsst.afw.geom as afwGeom import lsst.afw.display.ds9 as ds9 try: type(verbose) except NameError: verbose = 0 logging.Debug("afwDetect.Footprint", verbose) try: type(display) except NameError: display = False #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- class HeavyFootprintTestCase(tests.TestCase): """A test case for HeavyFootprint""" def setUp(self): self.mi = afwImage.MaskedImageF(20, 10) self.objectPixelVal = (10, 0x1, 100) self.foot = afwDetect.Footprint()
import unittest import numpy import lsst.utils.tests as utilsTests import lsst.pex.logging as pexLog import lsst.pex.policy as pexPolicy import lsst.daf.base as dafBase import lsst.daf.persistence as dafPersist import lsst.afw.image as afwImage import lsst.afw.math as afwMath import lsst.afw.geom as afwGeom import lsst.afw.image.testUtils as imTestUtils Verbosity = 0 # increase to see trace pexLog.Debug("lsst.afw", Verbosity) # pexLog.Debug("afw.math.KernelFormatter", 30) #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- class KernelIOTestCase(unittest.TestCase): """A test case for Kernel I/O""" def kernelCheck(self, k1, k2): self.assertEqual(k1.getWidth(), k2.getWidth()) self.assertEqual(k1.getHeight(), k2.getHeight()) self.assertEqual(k1.getCtrX(), k2.getCtrX()) self.assertEqual(k1.getCtrY(), k2.getCtrY()) self.assertEqual(k1.getNKernelParameters(), k2.getNKernelParameters()) self.assertEqual(k1.getNSpatialParameters(), k2.getNSpatialParameters()) self.assertEqual(k1.getKernelParameters(), k2.getKernelParameters())
# import math import unittest import numpy import lsst.utils.tests as utilsTests import lsst.pex.logging as pexLog import lsst.afw.geom as afwGeom import lsst.afw.image as afwImage import lsst.afw.math as afwMath import lsst.afw.math.detail as mathDetail VERBOSITY = 0 # increase to see trace pexLog.Debug("lsst.afw", VERBOSITY) #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- LocNameDict = { mathDetail.KernelImagesForRegion.BOTTOM_LEFT: "BOTTOM_LEFT", mathDetail.KernelImagesForRegion.BOTTOM_RIGHT: "BOTTOM_RIGHT", mathDetail.KernelImagesForRegion.TOP_LEFT: "TOP_LEFT", mathDetail.KernelImagesForRegion.TOP_RIGHT: "TOP_RIGHT", } NameLocDict = dict((name, loc) for (loc, name) in LocNameDict.iteritems()) class KernelImagesForRegion(utilsTests.TestCase): def setUp(self):
import lsst.afw.coord as afwCoord import lsst.afw.table as afwTable import lsst.afw.cameraGeom as cameraGeom import lsst.utils.tests as utilsTests import lsst.pex.exceptions as pexExcept import lsst.pex.logging as pexLog import lsst.pex.policy as pexPolicy import lsst.afw.fits from testTableArchivesLib import DummyPsf try: type(VERBOSITY) except: VERBOSITY = 0 # increase to see trace pexLog.Debug("lsst.afw.image", VERBOSITY) try: dataDir = os.path.join(eups.productDir("afwdata"), "data") except Exception: raise RuntimeError("Must set up afwdata to run these tests") InputMaskedImageName = "871034p_1_MI.fits" InputMaskedImageNameSmall = "small_MI.fits" InputImageNameSmall = "small" OutputMaskedImageName = "871034p_1_MInew.fits" currDir = os.path.abspath(os.path.dirname(__file__)) inFilePath = os.path.join(dataDir, InputMaskedImageName) inFilePathSmall = os.path.join(dataDir, InputMaskedImageNameSmall) inFilePathSmallImage = os.path.join(dataDir, InputImageNameSmall)
def __init__(self, config): self.config = config self.debugLog = pexLog.Debug("meas.algorithms.psfDeterminer") self.warnLog = pexLog.Log(pexLog.getDefaultLog(), "meas.algorithms.psfDeterminer")