Beispiel #1
0
    def testReadFits(self):
        """Test reading FITS files"""
        
        dataDir = eups.productDir("afwdata")
        if dataDir:
            dataDir = os.path.join(dataDir, "data")
        else:
            print >> sys.stderr, "Warning: afwdata is not set up; not running the FITS I/O tests"
            return
        
        hdus = {}
        fileName = os.path.join(dataDir, "small_MI.fits")
        hdus["img"] = 2 # an S16 fits HDU
        hdus["msk"] = 3 # an U8 fits HDU
        hdus["var"] = 4 # an F32 fits HDU

        imgU = afwImage.DecoratedImageU(fileName, hdus["img"]) # read as unsigned short
        imgF = afwImage.DecoratedImageF(fileName, hdus["img"]) # read as float

        self.assertEqual(imgU.getHeight(), 256)
        self.assertEqual(imgF.getImage().getWidth(), 256)
        self.assertEqual(imgU.getImage().get(0, 0), imgF.getImage().get(0, 0))
        #
        # Check the metadata
        #
        meta = self.trueMetadata
        for k in meta.keys():
            self.assertEqual(imgU.getMetadata().getAsDouble(k), meta[k])
            self.assertEqual(imgF.getMetadata().getAsDouble(k), meta[k])
        #
        # Read an F32 image
        #
        varU = afwImage.DecoratedImageF(fileName, hdus["var"]) # read as unsigned short
        varF = afwImage.DecoratedImageF(fileName, hdus["var"]) # read as float

        self.assertEqual(varU.getHeight(), 256)
        self.assertEqual(varF.getImage().getWidth(), 256)
        self.assertEqual(varU.getImage().get(0, 0), varF.getImage().get(0, 0))
        #
        # Read a char image
        #
        maskImg = afwImage.DecoratedImageU(fileName, hdus["msk"]).getImage() # read a char file

        self.assertEqual(maskImg.getHeight(), 256)
        self.assertEqual(maskImg.getWidth(), 256)
        self.assertEqual(maskImg.get(0, 0), 1)
        #
        # Read a U16 image
        #
        tmpFile = "foo.fits"

        imgU.writeFits(tmpFile)

        try:
            imgU16 = afwImage.DecoratedImageF(tmpFile) # read as unsigned short
        except:
            os.remove(tmpFile)
            raise

        os.remove(tmpFile)
Beispiel #2
0
    def testReadFits(self):
        """Test reading FITS files"""

        try:        
            dataDir = lsst.utils.getPackageDir("afwdata")
        except Exception:
            print >> sys.stderr, "Warning: afwdata is not set up; not running the FITS I/O tests"
            return

        dataDir = os.path.join(dataDir, "data")
        
        hdus = {}
        fileName = os.path.join(dataDir, "small_MI.fits")
        hdus["img"] = 2 # an S16 fits HDU
        hdus["msk"] = 3 # an U8 fits HDU
        hdus["var"] = 4 # an F32 fits HDU

        imgU = afwImage.DecoratedImageU(fileName, hdus["img"]) # read as unsigned short
        imgF = afwImage.DecoratedImageF(fileName, hdus["img"]) # read as float

        self.assertEqual(imgU.getHeight(), 256)
        self.assertEqual(imgF.getImage().getWidth(), 256)
        self.assertEqual(imgU.getImage().get(0, 0), imgF.getImage().get(0, 0))
        #
        # Check the metadata
        #
        meta = self.trueMetadata
        for k in meta.keys():
            self.assertEqual(imgU.getMetadata().getAsDouble(k), meta[k])
            self.assertEqual(imgF.getMetadata().getAsDouble(k), meta[k])
        #
        # Read an F32 image
        #
        varU = afwImage.DecoratedImageF(fileName, hdus["var"]) # read as unsigned short
        varF = afwImage.DecoratedImageF(fileName, hdus["var"]) # read as float

        self.assertEqual(varU.getHeight(), 256)
        self.assertEqual(varF.getImage().getWidth(), 256)
        self.assertEqual(varU.getImage().get(0, 0), varF.getImage().get(0, 0))
        #
        # Read a char image
        #
        maskImg = afwImage.DecoratedImageU(fileName, hdus["msk"]).getImage() # read a char file

        self.assertEqual(maskImg.getHeight(), 256)
        self.assertEqual(maskImg.getWidth(), 256)
        self.assertEqual(maskImg.get(0, 0), 1)
        #
        # Read a U16 image
        #
        with utilsTests.getTempFilePath(".fits") as tmpFile:
            imgU.writeFits(tmpFile)

            afwImage.DecoratedImageF(tmpFile) # read as unsigned short
Beispiel #3
0
    def testReadFits(self):
        """Test reading FITS files"""

        hdus = {}
        hdus["img"] = 1  # an S16 fits HDU
        hdus["msk"] = 2  # an U8 fits HDU
        hdus["var"] = 3  # an F32 fits HDU

        # read as unsigned short
        imgU = afwImage.DecoratedImageU(self.fileForMetadata,
                                        hdus["img"],
                                        allowUnsafe=True)
        # read as float
        imgF = afwImage.DecoratedImageF(self.fileForMetadata, hdus["img"])

        self.assertEqual(imgU.getHeight(), 256)
        self.assertEqual(imgF.image.getWidth(), 256)
        self.assertEqual(imgU.image[0, 0, afwImage.LOCAL],
                         imgF.image[0, 0, afwImage.LOCAL])
        #
        # Check the metadata
        #
        meta = self.trueMetadata
        for k in meta.keys():
            self.assertEqual(imgU.getMetadata().getAsDouble(k), meta[k])
            self.assertEqual(imgF.getMetadata().getAsDouble(k), meta[k])
        #
        # Read an F32 image
        #
        # read as unsigned short
        varU = afwImage.DecoratedImageF(self.fileForMetadata, hdus["var"])
        # read as float
        varF = afwImage.DecoratedImageF(self.fileForMetadata, hdus["var"])

        self.assertEqual(varU.getHeight(), 256)
        self.assertEqual(varF.image.getWidth(), 256)
        self.assertEqual(varU.image[0, 0, afwImage.LOCAL],
                         varF.image[0, 0, afwImage.LOCAL])
        #
        # Read a char image
        #
        maskImg = afwImage.DecoratedImageU(
            self.fileForMetadata, hdus["msk"]).image  # read a char file

        self.assertEqual(maskImg.getHeight(), 256)
        self.assertEqual(maskImg.getWidth(), 256)
        self.assertEqual(maskImg[0, 0, afwImage.LOCAL], 1)
        #
        # Read a U16 image
        #
        with lsst.utils.tests.getTempFilePath(".fits") as tmpFile:
            imgU.writeFits(tmpFile)

            afwImage.DecoratedImageF(tmpFile)  # read as unsigned short
 def bypass_raw(self, datasetType, pythonType, location, dataId):
     """Read raw image with hacked metadata"""
     filename = location.getLocations()[0]
     md = self.bypass_raw_md(datasetType, pythonType, location, dataId)
     image = afwImage.DecoratedImageU(filename)
     image.setMetadata(md)
     return self.std_raw(image, dataId)
Beispiel #5
0
def makeRampDecoratedImage(bbox, start, **metadataDict):
    """Make a DecoratedImageU that is a ramp."""
    rampArr = makeRampImage(bbox=bbox, start=start,
                            imageClass=afwImage.ImageU).getArray()
    decoratedImage = afwImage.DecoratedImageU(bbox)
    imarr = decoratedImage.getImage().getArray()
    imarr[:] = rampArr
    md = decoratedImage.getMetadata()
    for (key, val) in metadataDict.items():
        md.set(key, val)
    return decoratedImage
Beispiel #6
0
def openChannelImage(dirPath, x, y):
    """Open an LSSTSim channel raw image
    """
    globStr = os.path.join(dirPath, "imsim_*_R22_S00_C%d%d*" % (y, x))
    inDecoImagePathList = glob.glob(globStr)
    if len(inDecoImagePathList) != 1:
        raise RuntimeError("Found %s instead of 1 file" %
                           (inDecoImagePathList, ))
    inDecoImagePath = inDecoImagePathList[0]
    inDecoImageFileName = os.path.basename(inDecoImagePath)
    # calib images (which are float) have names such as imsim_2_R22_S00_C00.fits
    # raw images (which are unsigned int) have names such as imsim_890104911_R22_S00_C00_E000....
    if not re.match(r"imsim_\d\d\d\d\d", inDecoImageFileName):
        raise RuntimeError("Not raw data")

    print("loading %s as raw unsigned integer data" % (inDecoImageFileName, ))
    return afwImage.DecoratedImageU(inDecoImagePath)
Beispiel #7
0
def assembleImage(dirPath):
    """Make one image by combining half of amplifiers C00, C01, C10, C11 of lsstSim data
    """
    # views and assembly operations require a masked image, not a DecoratedImage
    inDecoImage = openChannelImage(dirPath, 0, 0)
    fullInDim = inDecoImage.getDimensions()
    yStart = fullInDim[1] - SizeY
    if yStart < 0:
        raise RuntimeError("channel image unexpectedly small")
    subDim = afwGeom.Extent2I(
        fullInDim[0],
        SizeY)  # dimensions of the portion of a channel that we use
    inSubBBox = afwGeom.Box2I(afwGeom.Point2I(0, yStart), subDim)
    outBBox = afwGeom.Box2I(afwGeom.Point2I(0, 0), subDim * 2)
    outDecoImage = afwImage.DecoratedImageU(outBBox)

    # copy metadata
    outDecoImage.setMetadata(inDecoImage.getMetadata())

    for x in (0, 1):
        for y in (0, 1):
            inDecoImage = openChannelImage(dirPath, x, y)
            inImage = inDecoImage.getImage()
            inView = inImage.Factory(inImage, inSubBBox)

            # flip image about x axis for the y = 1 channels
            if y == 1:
                arr = inView.getArray()
                if numpy.any(arr != 0):
                    arr[:, :] = numpy.flipud(arr)

            xStart = x * subDim[0]
            yStart = y * subDim[1]
            outSubBBox = afwGeom.Box2I(afwGeom.Point2I(xStart, yStart), subDim)
            outImage = outDecoImage.getImage()
            outView = outImage.Factory(outImage, outSubBBox)
            outView[:] = inView

    outDecoImage.writeFits(OutFileName)
    print("wrote assembled data as %r" % (OutFileName, ))
Beispiel #8
0
from lsst.pex.harness import Dataset

lm = dafBase.PropertySet()
lm.add("input", "tests")
lm.add("output", ".")
dafPersist.LogicalLocation.setLocationMap(lm)
ps = dafBase.PropertySet()
ps.add("field", "D4")
clip0 = {
    'inputDatasets': [
        Dataset('postIsr', visit=707911, snap=0, ccd=13, amp=0),
        Dataset('postIsr', visit=707911, snap=0, ccd=13, amp=1)
    ],
    'root':
    "raw",
    'ps':
    ps
}
policy = pexPolicy.Policy.createPolicy("tests/policy/TestIO_2.policy")
t1 = SST.SimpleStageTester(IOStage.InputStage(policy))
clip1 = t1.run(clip0, 0)
el = clip1.get("exposureSet")
assert len(el) == 2
e = afwImage.DecoratedImageU()
assert type(el[0]) == type(e)
assert type(el[1]) == type(e)
assert el[0].getWidth() == 1056
assert el[1].getHeight() == 1153
assert el[0].getMetadata().get("LSSTAMP") == 0
assert el[1].getMetadata().get("LSSTAMP") == 1