Пример #1
0
 def _createSkyWcsFromMetadata(self):
     # We need to know which direction the chip is "flipped" in order to
     # make a sensible WCS from the header metadata.
     wcs = makeSkyWcs(self.metadata, strip=True)
     dimensions = bboxFromMetadata(self.metadata).getDimensions()
     center = Point2D(dimensions / 2.0)
     return makeFlippedWcs(wcs, self.FLIP_LR, self.FLIP_TB, center)
Пример #2
0
def prepareWcsData(wcs, amp, isTrimmed=True):
    """Put Wcs from an Amp image into CCD coordinates

    Parameters
    ----------
    wcs : `lsst.afw.geom.SkyWcs`
        The WCS object to start from.
    amp : `lsst.afw.table.AmpInfoRecord`
        Amp object to use
    isTrimmed : `bool`
        Is the image to which the WCS refers trimmed of non-imaging pixels?

    Returns
    -------
    ampWcs : `lsst.afw.geom.SkyWcs`
        The modified WCS.
    """
    if not amp.getHasRawInfo():
        raise RuntimeError("Cannot modify wcs without raw amp information")
    if isTrimmed:
        ampBox = amp.getRawDataBBox()
    else:
        ampBox = amp.getRawBBox()
    ampCenter = lsst.geom.Point2D(ampBox.getDimensions() / 2.0)
    wcs = afwGeom.makeFlippedWcs(wcs, amp.getRawFlipX(), amp.getRawFlipY(),
                                 ampCenter)
    # Shift WCS for trimming
    if isTrimmed:
        trim_shift = ampBox.getMin() - amp.getBBox().getMin()
        wcs = wcs.copyAtShiftedPixelOrigin(
            lsst.geom.Extent2D(-trim_shift.getX(), -trim_shift.getY()))
    # Account for shift of amp data in larger ccd matrix
    offset = amp.getRawXYOffset()
    return wcs.copyAtShiftedPixelOrigin(lsst.geom.Extent2D(offset))
Пример #3
0
    def checkMakeFlippedWcs(self, skyWcs, skyAtol=1e-7 * arcseconds):
        """Check makeFlippedWcs on the provided WCS
        """
        # make an arbitrary bbox, but one that includes zero in one axis
        # and does not include zero in the other axis
        # the center of the bbox is used as the center of flipping
        # and the corners of the bbox are the input positions that are tested
        bbox = Box2D(Point2D(-100, 1000), Extent2D(2000, 1501))
        # dict of (isRight, isTop): position
        minPos = bbox.getMin()
        maxPos = bbox.getMax()
        center = bbox.getCenter()
        cornerDict = {
            (False, False): minPos,
            (False, True): Point2D(minPos[0], maxPos[1]),
            (True, False): Point2D(maxPos[0], minPos[1]),
            (True, True): maxPos,
        }
        for flipLR, flipTB in itertools.product((False, True), (False, True)):
            flippedWcs = makeFlippedWcs(wcs=skyWcs,
                                        flipLR=flipLR,
                                        flipTB=flipTB,
                                        center=center)
            # the center is unchanged
            self.assertSpherePointsAlmostEqual(skyWcs.pixelToSky(center),
                                               flippedWcs.pixelToSky(center),
                                               maxSep=skyAtol)

            for isR, isT in itertools.product((False, True), (False, True)):
                origPos = cornerDict[(isR, isT)]
                flippedPos = cornerDict[(isR ^ flipLR, isT ^ flipTB)]
                self.assertSpherePointsAlmostEqual(
                    skyWcs.pixelToSky(origPos),
                    flippedWcs.pixelToSky(flippedPos),
                    maxSep=skyAtol)
Пример #4
0
def prepareWcsData(wcs, amp, isTrimmed=True):
    """Put Wcs from an Amp image into CCD coordinates

    Parameters
    ----------
    wcs : `lsst.afw.geom.SkyWcs`
        The WCS object to start from.
    amp : `lsst.afw.table.AmpInfoRecord`
        Amp object to use
    isTrimmed : `bool`
        Is the image to which the WCS refers trimmed of non-imaging pixels?

    Returns
    -------
    ampWcs : `lsst.afw.geom.SkyWcs`
        The modified WCS.
    """
    if not amp.getHasRawInfo():
        raise RuntimeError("Cannot modify wcs without raw amp information")
    if isTrimmed:
        ampBox = amp.getRawDataBBox()
    else:
        ampBox = amp.getRawBBox()
    ampCenter = lsst.geom.Point2D(ampBox.getDimensions()/2.0)
    wcs = afwGeom.makeFlippedWcs(wcs, amp.getRawFlipX(), amp.getRawFlipY(), ampCenter)
    # Shift WCS for trimming
    if isTrimmed:
        trim_shift = ampBox.getMin() - amp.getBBox().getMin()
        wcs = wcs.copyAtShiftedPixelOrigin(lsst.geom.Extent2D(-trim_shift.getX(), -trim_shift.getY()))
    # Account for shift of amp data in larger ccd matrix
    offset = amp.getRawXYOffset()
    return wcs.copyAtShiftedPixelOrigin(lsst.geom.Extent2D(offset))
Пример #5
0
    def _flipChipsLR(exp, wcs, detectorId, dims=None):
        """Flip the chip left/right or top/bottom. Process either/and the pixels and wcs

        Most chips are flipped L/R, but the rotated ones (100..103) are flipped T/B
        """
        flipLR, flipTB = (False, True) if detectorId in (100, 101, 102, 103) else (True, False)
        if exp:
            exp.setMaskedImage(afwMath.flipImage(exp.getMaskedImage(), flipLR, flipTB))
        if wcs:
            ampDimensions = exp.getDimensions() if dims is None else dims
            ampCenter = geom.Point2D(ampDimensions/2.0)
            wcs = afwGeom.makeFlippedWcs(wcs, flipLR, flipTB, ampCenter)

        return exp, wcs
Пример #6
0
    def _flipChipsLR(exp, wcs, dataId, dims=None):
        """Flip the chip left/right or top/bottom. Process either/and the pixels and wcs

        Most chips are flipped L/R, but the rotated ones (100..103) are flipped T/B
        """
        flipLR, flipTB = (False, True) if dataId['ccd'] in (100, 101, 102, 103) else (True, False)
        if exp:
            exp.setMaskedImage(afwMath.flipImage(exp.getMaskedImage(), flipLR, flipTB))
        if wcs:
            ampDimensions = exp.getDimensions() if dims is None else dims
            ampCenter = afwGeom.Point2D(ampDimensions/2.0)
            wcs = afwGeom.makeFlippedWcs(wcs, flipLR, flipTB, ampCenter)

        return exp, wcs
Пример #7
0
 def makeWcs(self, metadata):
     wcs = makeSkyWcs(metadata, strip=True)
     dimensions = bboxFromMetadata(metadata).getDimensions()
     center = Point2D(dimensions/2.0)
     return makeFlippedWcs(wcs, self.FLIP_LR, self.FLIP_TB, center)