Ejemplo n.º 1
0
    def readData(self, fileName = None, subImage = False):
        afwdataDir = eups.productDir("afwdata") or ""
        if not fileName or isinstance(fileName, int):
            if fileName:
                which = fileName
            else:
                which = 1

            fileName = os.path.join(afwdataDir, "med")
        elif not os.path.exists(fileName):
            fileName = os.path.join(afwdataDir, fileName)
        #
        # We could read into an Exposure, but we're going to want to determine our own WCS
        #
        hdu, metadata = 0, dafBase.PropertySet()
        if True:
            mi = afwImage.MaskedImageF(fileName, hdu, metadata) # read MaskedImage
            self.XY0 = mi.getXY0()
        else:
            if subImage:                           # use sub-image
                self.XY0 = afwImage.PointI(824, 140)
                bbox = afwImage.BBox(self.XY0, 512, 512)
            else:                       # use full image, trimmed to data section
                self.XY0 = afwImage.PointI(32, 2)
                bbox = afwImage.BBox(self.XY0, afwImage.PointI(2079, 4609))

            mi = afwImage.MaskedImageF(fileName, hdu, metadata, bbox) # read MaskedImage

            if not subImage:
                mi.setXY0(afwImage.PointI(0, 0)) # we just trimmed the overscan
            
        wcs = afwImage.makeWcs(metadata)
        self.pixscale = wcs.pixelScale().asArcseconds()
        #
        # Just an initial guess
        #
        FWHM = 5
        self.psf = measAlg.DoubleGaussianPsf(15, 15, FWHM/(2*sqrt(2*log(2))))

        mi.getMask().addMaskPlane("DETECTED")
        self.exposure = afwImage.makeExposure(mi, wcs)
        self.exposure.setPsf(self.psf)

        if self.display:
            ds9.mtv(self.exposure)
Ejemplo n.º 2
0
    def setUp(self):
        self.FWHM = 5
        self.psf = algorithms.DoubleGaussianPsf(15, 15, self.FWHM/(2*sqrt(2*log(2))))
        maskedImageFile = os.path.join(eups.productDir("afwdata"), "CFHT", "D4", "cal-53535-i-797722_1.fits")
            
        self.mi = afwImage.MaskedImageF(maskedImageFile)
        if False:                       # use sub-image?
            self.mi = self.mi.Factory(self.mi, afwImage.BBox(afwImage.PointI(760, 20), 256, 256))
        self.mi.getMask().addMaskPlane("INTERP")

        self.badPixels = defects.policyToBadRegionList(os.path.join(eups.productDir("meas_algorithms"),
                                                                    "policy", "BadPixels.paf"))
Ejemplo n.º 3
0
    def setUp(self):
        self.FWHM = 5
        self.psf = algorithms.DoubleGaussianPsf(
            15, 15, self.FWHM / (2 * math.sqrt(2 * math.log(2))))
        maskedImageFile = os.path.join(afwdataDir, "CFHT", "D4",
                                       "cal-53535-i-797722_1.fits")

        self.mi = afwImage.MaskedImageF(maskedImageFile)
        if False:  # use sub-image?
            self.mi = self.mi.Factory(
                self.mi, afwImage.BBox(afwImage.PointI(760, 20), 256, 256))
        self.mi.getMask().addMaskPlane("INTERP")

        self.badPixels = testUtils.makeDefectList()
Ejemplo n.º 4
0
    def XXXtest818(self):
        """A test case for #818; the full test is in /lsst/DC3root/ticketFiles/818"""

        badPixels = algorithms.DefectListT()
        defects = [((82, 663), 6, 8),
                   ((83, 659), 9, 6),
                   ((85, 660), 10, 11),
                   ((87, 669), 3, 3),
                   ]

        for xy0, width, height in defects:
            x0, y0 = xy0
            bbox = afwImage.BBox(afwImage.PointI(x0, y0), width, height)
            badPixels.push_back(algorithms.Defect(bbox))

        mi = afwImage.MaskedImageF(517, 800)

        algorithms.interpolateOverDefects(mi, self.psf, badPixels)
            # e.g.
            # CCDSIZE = '[1:2048,1:4612]'    / Detector imaging area size
            # bbox    = ipIsr.BboxFromDatasec(datasec)

            match = maskFormat.match(datasec)
            if match == None:
                # unable to match mask area!
                print '# WARNING: Extn', nExt, 'unable to parse', maskArea
                continue
            group = map(int, match.groups())

            # ACB : by visual inspection, the y0 values can be too
            # high by 1.  however, since some of the y0 values are '1'
            # in the mask string, i can't decrement this by 2 without
            # going off the image.  we just deal with this for dc3a.
            bbox = afwImage.BBox(afwImage.PointI(group[0] - 1, group[1] - 1),
                                 afwImage.PointI(group[2] - 1, group[3] - 1))

            fp = afwDetection.Footprint(bbox)
            afwDetection.setMaskFromFootprint(mask, fp, bitmask)

    # debugging
    #outfile0 = '%d.fits' % (i)
    #print '# Writing', outfile0
    #mask.writeFits(outfile0)

    # trim this thing!  it includes the overscan etc...

    bboxA = afwImage.BBox(afwImage.PointI(32, 0), afwImage.PointI(1055, 4611))

    bboxB = afwImage.BBox(afwImage.PointI(1055, 0),
                          afwImage.PointI(2111 - 32, 4611))
# the GNU General Public License along with this program.  If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#

import pyfits
import sys
import os
import re
import lsst.afw.image as afwImage

maskFormat = re.compile('^\[(\d+):(\d+),(\d+):(\d+)\]$')

# It looks like these masks include the biassec on the LHS.
# It also includes the secs on the top and RHS
# I need to do some trimming here.
leftBox = afwImage.BBox(afwImage.PointI(0, 0), afwImage.PointI(31, 4643))

# we actually need the bottom row of this top box
topBox0 = afwImage.BBox(afwImage.PointI(0, 4611), afwImage.PointI(2111, 4643))
topBox1 = afwImage.BBox(afwImage.PointI(0, 4611), afwImage.PointI(2111, 4611))

rightBox = afwImage.BBox(afwImage.PointI(2080, 0), afwImage.PointI(2111, 4643))

inmask = sys.argv[1]  # mask definition
inimage = sys.argv[2]  # need serial numbers
ptrM = pyfits.open(inmask)
ptrI = pyfits.open(inimage)

outfile = sys.argv[3]
buff = open(outfile, 'w')
buff.write('Defects: { \n')
Ejemplo n.º 7
0
# They need to be trimmed.

for img in sys.argv[1:]:
    root = re.sub('_img.fits', '', img)

    exp = afwImage.ExposureF(root)
    metadata = exp.getMetadata()
    amp = metadata.get('LSSTAMP')

    mi = exp.getMaskedImage()
    height = mi.getHeight()
    width = mi.getWidth()

    # don't double-trim!
    if (width == 1024) and (height == 1153):
        print '# skipping', img
        continue

    if amp < 4:
        bbox = afwImage.BBox(afwImage.PointI(32, 0),
                             afwImage.PointI(1055, 1152))

    else:
        bbox = afwImage.BBox(afwImage.PointI(0, 0),
                             afwImage.PointI(1055 - 32, 1152))

    subexp = afwImage.ExposureF(exp, bbox)
    subexp.getMetadata().combine(exp.getMetadata())
    # overwrite originals; gulp!
    subexp.writeFits(root)
Ejemplo n.º 8
0
 def lookupAmpBBox(self, ampId, ccdId):
     key = "CcdBBox.Amp%d" % ampId
     p = self.ampBBoxDb.get(key)
     return afwImage.BBox(afwImage.PointI(p.get("x0"), p.get("y0")),
                          p.get("width"), p.get("height"))
    # convert to exposure
    exp = afwImage.ExposureF(afwImage.MaskedImageF(dim.getImage()),
                             afwImage.Wcs())
    exp.setMetadata(dim.getMetadata())
    if filterid == None:
        # For biases
        exp.setFilter(afwImage.Filter("u"))
    else:
        exp.setFilter(afwImage.Filter(filterid))
    exp.getMetadata().set('DC3BPATH', outfile)
    exp.writeFits(outfile)


if __name__ == '__main__':
    bbox1 = afwImage.BBox(afwImage.PointI(0, 0), 1056, 4644)
    bbox2 = afwImage.BBox(afwImage.PointI(1056, 0), 1056, 4644)

    #print bbox1.getX0(), bbox1.getX1(), bbox1.getY0(), bbox1.getY1()
    #print bbox2.getX0(), bbox2.getX1(), bbox2.getY0(), bbox2.getY1()

    infile = sys.argv[1]
    dateid = sys.argv[2]
    #    for line in open(infile).readlines():
    if 1:
        #file = line.split()[0]
        file = infile

        # does not work for calibs
        #fields = line.split()
        #id     = fields[0]
import unittest

import eups
import lsst.daf.base as dafBase
import lsst.pex.harness as pexHarness
import lsst.pex.logging as pexLog
import lsst.pex.policy as pexPolicy
import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.coadd.pipeline as coaddPipe
from lsst.pex.harness import Clipboard, simpleStageTester

SaveDebugImages = False
Verbosity = 1

BBox = afwImage.BBox(afwImage.PointI(0, 0), 100, 100)

BackgroundCellSize = 512


def subtractBackground(maskedImage):
    """Subtract the background from a MaskedImage
    
    Note: at present the mask and variance are ignored, but they might used be someday.
    
    Returns the background object returned by afwMath.makeBackground.
    """
    bkgControl = afwMath.BackgroundControl(afwMath.Interpolate.NATURAL_SPLINE)
    bkgControl.setNxSample(
        int(maskedImage.getWidth() // BackgroundCellSize) + 1)
    bkgControl.setNySample(