Example #1
0
    def std_raw(self, image, dataId):
        """Fix missing header keywords"""

        md = image.getMetadata()
        md.add('CRVAL2', 0.0)
        if md.exists("BACKMEAN") and md.exists("ARAWGAIN"):
           backmean = md.get("BACKMEAN")
           gain = md.get("ARAWGAIN")
        else:
           backmean = 0.0
           gain = 1.0
        filterName = md.get("FILTER")[0]
        if filterName == "Y":
            filterName = "z"

        # Not until the camera part gets worked out
        #return super(DecamMapper, self).std_raw(image, dataId)

        # we have to deal with the variance ourselves, at least for the test data I got # ACB
        exp = exposureFromImage(image)
        mi  = exp.getMaskedImage()
        var = mi.getVariance().Factory(mi.getImage())
        var += backmean
        var /= gain
        mi2 = mi.Factory(mi.getImage(), mi.getMask(), var)
        exp2 = exp.Factory(mi2, exp.getWcs())

        # hacking around filter issues
        exp2.setFilter(afwImage.Filter(filterName))
        
        return exp2
 def _standardizeDetrend(self, detrend, image, dataId, filter=False):
     """Hack up detrend images to remove troublesome keyword"""
     md = image.getMetadata()
     removeKeyword(
         md, 'RADECSYS')  # Irrelevant, and use of "GAPPT" breaks wcslib
     exp = exposureFromImage(image)
     return self._standardizeExposure(self.calibrations[detrend],
                                      exp,
                                      dataId,
                                      filter=filter,
                                      trimmed=False)
    def _standardizeExposure(self, mapping, item, dataId, filter=True,
            trimmed=True):

        """Default standardization function for images.
        @param mapping (lsst.daf.butlerUtils.Mapping)
        @param[in,out] item (lsst.afw.image.Exposure)
        @param dataId (dict) Dataset identifier
        @param filter (bool) Set filter?
        @param trimmed (bool) Should detector be marked as trimmed?
        @return (lsst.afw.image.Exposure) the standardized Exposure"""

        if (re.search(r'Exposure', mapping.python) and re.search(r'Image',mapping.persistable)):
            item = exposureFromImage(item)
        return item
Example #4
0
    def bypass_raw(self, datasetType, pythonType, location, dataId):
        ccd = dataId['ccd']
        x, y = ccd % 6, ccd // 6
        xSize, ySize = 2048, 4096

        filename = location.getLocations()[0]
        bbox = afwGeom.Box2I(afwGeom.Point2I(x * xSize, y * ySize),
                             afwGeom.Extent2I(xSize, ySize))
        if False:
            # XXX seems to be some sort of bug here for ccd=11
            # cfitsio returns: READ_ERROR 108 /* error reading from FITS file */
            hdu = 0
            image = afwImage.DecoratedImageF(filename, hdu, bbox)
        else:
            # XXX this can't be at all efficient, but it works
            raw = afwImage.ImageF(filename)
            sub = raw.Factory(raw, bbox, True)
            del raw
            sub.setXY0(afwGeom.Point2I(0, 0))
            image = afwImage.DecoratedImageF(sub)
            del sub

        exp = exposureFromImage(image)
        del image

        md = exp.getMetadata()
        md.add("EXPTIME", 1.0)
        md.add("FILTER", "OPEN")

        # Install a basic (wrong, apart from pixel scale) WCS so the pixel scale can be used
        md.add("RA", "00:00:00.00")
        md.add("DEC", "00:00:00.0")
        coord = afwCoord.IcrsCoord(afwGeom.Point2D(0, 0), afwGeom.radians)
        point = afwGeom.Point2D(0, 0)
        pixScale = (0.9 * afwGeom.arcseconds).asDegrees()
        wcs = afwImage.makeWcs(coord, point, pixScale, 0, 0, pixScale)
        wcsMd = wcs.getFitsMetadata()
        for key in wcsMd.names():
            md.add(key, wcsMd.get(key))
        exp.setWcs(wcs)

        return self._standardizeExposure(self.exposures['raw'],
                                         exp,
                                         dataId,
                                         filter=True,
                                         trimmed=False)
Example #5
0
    def bypass_raw(self, datasetType, pythonType, location, dataId):
        ccd = dataId['ccd']
        x, y = ccd % 6, ccd // 6
        xSize, ySize = 2048, 4096
    
        filename = location.getLocations()[0]
        bbox = afwGeom.Box2I(afwGeom.Point2I(x * xSize, y * ySize), afwGeom.Extent2I(xSize, ySize))
        if False:
            # XXX seems to be some sort of bug here for ccd=11
            # cfitsio returns: READ_ERROR 108 /* error reading from FITS file */
            hdu = 0
            image = afwImage.DecoratedImageF(filename, hdu, bbox)
        else:
            # XXX this can't be at all efficient, but it works
            raw = afwImage.ImageF(filename)
            sub = raw.Factory(raw, bbox, True)
            del raw
            sub.setXY0(afwGeom.Point2I(0,0))
            image = afwImage.DecoratedImageF(sub)
            del sub

        exp = exposureFromImage(image)
        del image

        md = exp.getMetadata()
        md.add("EXPTIME", 1.0)
        md.add("FILTER", "OPEN")

        # Install a basic (wrong, apart from pixel scale) WCS so the pixel scale can be used
        md.add("RA", "00:00:00.00")
        md.add("DEC", "00:00:00.0")
        coord = afwCoord.IcrsCoord(afwGeom.Point2D(0, 0), afwGeom.radians)
        point = afwGeom.Point2D(0, 0)
        pixScale = (0.9 * afwGeom.arcseconds).asDegrees()
        wcs = afwImage.makeWcs(coord, point, pixScale, 0, 0, pixScale)
        wcsMd = wcs.getFitsMetadata()
        for key in wcsMd.names():
            md.add(key, wcsMd.get(key))
        exp.setWcs(wcs)

        return self._standardizeExposure(self.exposures['raw'], exp, dataId, filter=True, trimmed=False)
Example #6
0
    def std_raw(self, item, dataId):
        """Standardize a raw dataset by converting it to an Exposure.

        Raw images are MEF files with one HDU for each detector.
        Header keywords EXPTIME and MJD-OBS exist only in the zeroth
        extension and are copied to metadata.

        @param item: The image read by the butler
        @param dataId: Data identifier
        @return (lsst.afw.image.Exposure) the standardized Exposure
        """
        # Convert the raw DecoratedImage to an Exposure, set metadata and wcs.
        exp = exposureFromImage(item)
        md = exp.getMetadata()
        rawPath = self.map_raw(dataId).getLocations()[0]
        headerPath = re.sub(r'[\[](\d+)[\]]$', "[0]", rawPath)
        md0 = afwImage.readMetadata(headerPath)
        # Keywords EXPTIME and MJD-OBS are used to set the calib object.
        for kw in ('EXPTIME', 'MJD-OBS'):
            if kw in md0.paramNames() and kw not in md.paramNames():
                md.add(kw, md0.get(kw))
        # As TPV is not supported yet, the wcs keywords are not pruned
        # from the metadata. Once TPV is supported, the following keyword
        # removal may not be necessary here and would probably be done at
        # makeWcs() when the raw image is converted to an Exposure.
        for kw in exp.getWcs().getFitsMetadata().paramNames():
            md.remove(kw)
        for kw in ('LTV1', 'LTV2'):
            md.remove(kw)
        # Currently the existence of some PV cards in the metadata combined
        # with a CTYPE of TAN is interpreted as TPV (DM-2883).
        for kw in md.paramNames():
            if re.match(r'PV\d_\d', kw):
                md.remove(kw)
        # Standardize an Exposure, including setting the calib object
        return self._standardizeExposure(self.exposures['raw'],
                                         exp,
                                         dataId,
                                         trimmed=False)
Example #7
0
    def std_raw(self, item, dataId):
        """Standardize a raw dataset by converting it to an Exposure.

        Raw images are MEF files with one HDU for each detector.
        Header keywords EXPTIME and MJD-OBS exist only in the zeroth
        extension and are copied to metadata.

        @param item: The image read by the butler
        @param dataId: Data identifier
        @return (lsst.afw.image.Exposure) the standardized Exposure
        """
        # Convert the raw DecoratedImage to an Exposure, set metadata and wcs.
        exp = exposureFromImage(item)
        md = exp.getMetadata()
        rawPath = self.map_raw(dataId).getLocations()[0]
        headerPath = re.sub(r'[\[](\d+)[\]]$', "[0]", rawPath)
        md0 = afwImage.readMetadata(headerPath)
        # Keywords EXPTIME and MJD-OBS are used to set the calib object.
        for kw in ('EXPTIME', 'MJD-OBS'):
            if kw in md0.paramNames() and kw not in md.paramNames():
                md.add(kw, md0.get(kw))
        # As TPV is not supported yet, the wcs keywords are not pruned
        # from the metadata. Once TPV is supported, the following keyword
        # removal may not be necessary here and would probably be done at
        # makeWcs() when the raw image is converted to an Exposure.
        for kw in exp.getWcs().getFitsMetadata().paramNames():
            md.remove(kw)
        for kw in ('LTV1', 'LTV2'):
            md.remove(kw)
        # Currently the existence of some PV cards in the metadata combined
        # with a CTYPE of TAN is interpreted as TPV (DM-2883).
        for kw in md.paramNames():
            if re.match(r'PV\d_\d', kw):
                md.remove(kw)
        # Standardize an Exposure, including setting the calib object
        return self._standardizeExposure(self.exposures['raw'], exp, dataId,
                                         trimmed=False)
Example #8
0
 def _standardizeDetrend(self, detrend, image, dataId, filter=False):
     """Hack up detrend images to remove troublesome keyword"""
     md = image.getMetadata()
     removeKeyword(md, 'RADECSYS') # Irrelevant, and use of "GAPPT" breaks wcslib
     exp = exposureFromImage(image)
     return self._standardizeExposure(self.calibrations[detrend], exp, dataId, filter=filter, trimmed=False)