示例#1
0
    def testDistortion(self):
        """Test computePixelToDistortedPixel with distortion

        pixelToDistortedPixel -> self.tanWcs should match a WCS
        created with makeDistortedTanWcs
        """
        focalPlaneToFieldAngle = afwGeom.makeRadialTransform([0.0, self.radPerMm, 0.0, self.radPerMm])
        pixelToDistortedPixel = computePixelToDistortedPixel(
            pixelToFocalPlane=self.pixelToFocalPlane,
            focalPlaneToFieldAngle=focalPlaneToFieldAngle,
        )
        # Do not try to make pixelToDistortedPixel -> self.tanWcs into a WCS
        # because the frame names will be wrong; use a TransformPoint2Tolsst.geom.SpherePoint instead
        tanWcsTransform = afwGeom.TransformPoint2ToSpherePoint(self.tanWcs.getFrameDict())
        pixelToDistortedSky = pixelToDistortedPixel.then(tanWcsTransform)

        wcs = makeDistortedTanWcs(
            tanWcs=self.tanWcs,
            pixelToFocalPlane=self.pixelToFocalPlane,
            focalPlaneToFieldAngle=focalPlaneToFieldAngle,
        )

        bboxD = lsst.geom.Box2D(self.bbox)
        pixelPoints = bboxD.getCorners()
        pixelPoints.append(bboxD.getCenter())

        skyPoints1 = pixelToDistortedSky.applyForward(pixelPoints)
        skyPoints2 = wcs.pixelToSky(pixelPoints)
        self.assertSpherePointListsAlmostEqual(skyPoints1, skyPoints2)

        pixelPoints1 = pixelToDistortedSky.applyInverse(skyPoints1)
        pixelPoints2 = wcs.skyToPixel(skyPoints1)
        assert_allclose(pixelPoints1, pixelPoints2)
示例#2
0
 def makeDesiredDistortedWcs(self):
     """Make the expected distorted WCS"""
     pixelToFocalPlane = self.detector.getTransform(PIXELS, FOCAL_PLANE)
     focalPlaneToFieldAngle = self.camera.getTransformMap().getTransform(
         FOCAL_PLANE, FIELD_ANGLE)
     return makeDistortedTanWcs(self.wcs, pixelToFocalPlane,
                                focalPlaneToFieldAngle)
示例#3
0
    def testDistortion(self):
        """Test computePixelToDistortedPixel with distortion

        pixelToDistortedPixel -> self.tanWcs should match a WCS
        created with makeDistortedTanWcs
        """
        focalPlaneToFieldAngle = afwGeom.makeRadialTransform(
            [0.0, self.radPerMm, 0.0, self.radPerMm])
        pixelToDistortedPixel = computePixelToDistortedPixel(
            pixelToFocalPlane=self.pixelToFocalPlane,
            focalPlaneToFieldAngle=focalPlaneToFieldAngle,
        )
        # Do not try to make pixelToDistortedPixel -> self.tanWcs into a WCS
        # because the frame names will be wrong; use a TransformPoint2Tolsst.geom.SpherePoint instead
        tanWcsTransform = afwGeom.TransformPoint2ToSpherePoint(
            self.tanWcs.getFrameDict())
        pixelToDistortedSky = pixelToDistortedPixel.then(tanWcsTransform)

        wcs = makeDistortedTanWcs(
            tanWcs=self.tanWcs,
            pixelToFocalPlane=self.pixelToFocalPlane,
            focalPlaneToFieldAngle=focalPlaneToFieldAngle,
        )

        bboxD = lsst.geom.Box2D(self.bbox)
        pixelPoints = bboxD.getCorners()
        pixelPoints.append(bboxD.getCenter())

        skyPoints1 = pixelToDistortedSky.applyForward(pixelPoints)
        skyPoints2 = wcs.pixelToSky(pixelPoints)
        self.assertSpherePointListsAlmostEqual(skyPoints1, skyPoints2)

        pixelPoints1 = pixelToDistortedSky.applyInverse(skyPoints1)
        pixelPoints2 = wcs.skyToPixel(skyPoints1)
        assert_allclose(pixelPoints1, pixelPoints2)
示例#4
0
    def testDistortion(self):
        """Test makeDistortedTanWcs using a non-affine transform for pixelToFocalPlane
        """
        # Compute a distorted wcs that matches self.tanWcs at the center of the field;
        # the amount of distortion is 10s of pixels over the detector
        fieldAngleToFocalPlane = afwGeom.makeRadialTransform(
            [0.0, 1 / self.radPerMm, 0.0, 1000 / self.radPerMm])
        focalPlaneToFieldAngle = fieldAngleToFocalPlane.inverted()
        focalPlaneToTanFieldAngle = self.makeAffineTransform(
            scale=self.radPerMm)
        wcs = makeDistortedTanWcs(
            tanWcs=self.tanWcs,
            pixelToFocalPlane=self.pixelToFocalPlane,
            focalPlaneToFieldAngle=focalPlaneToFieldAngle,
        )

        # At the center of the focal plane both WCS should give the same sky position
        pixelAtCtr = self.pixelToFocalPlane.applyInverse(
            lsst.geom.Point2D(0, 0))
        tanSkyAtCtr = self.tanWcs.pixelToSky(pixelAtCtr)
        skyAtCtr = wcs.pixelToSky(pixelAtCtr)
        self.assertPairsAlmostEqual(tanSkyAtCtr, skyAtCtr)

        # At all reasonable sky points the following field angles should be almost equal:
        #   sky -> tanWcs.skyToPixel -> pixelToFocalPlane -> focalPlaneToTanFieldAngle
        #   sky -> wcs.skyToPixel -> pixelToFocalPlane -> focalPlaneToFieldAngle
        # where focalPlaneToTanFieldAngle is the linear approximation to
        # focalPlaneToFieldAngle at the center of the field (where tanWcs and wcs match),
        # since for a given pointing, field angle gives position on the sky
        skyPoints = self.tanWcs.pixelToSky(self.pixelPoints)

        tanFieldAnglePoints = focalPlaneToTanFieldAngle.applyForward(
            self.pixelToFocalPlane.applyForward(
                self.tanWcs.skyToPixel(skyPoints)))
        fieldAnglePoints = focalPlaneToFieldAngle.applyForward(
            self.pixelToFocalPlane.applyForward(wcs.skyToPixel(skyPoints)))
        assert_allclose(tanFieldAnglePoints, fieldAnglePoints)

        # The inverse should also be true: for a set of field angle points
        # the following sky positions should be almost equal:
        # fieldAngle -> fieldAngleToTanFocalPlane -> focalPlaneToPixel -> tanWcs.pixelToSky
        # fieldAngle -> fieldAngleToFocalPlane -> focalPlaneToPixel -> wcs.pixelToSky
        focalPlaneToPixel = self.pixelToFocalPlane.inverted()
        fieldAngleToTanFocalPlane = focalPlaneToTanFieldAngle.inverted()
        tanSkyPoints2 = self.tanWcs.pixelToSky(
            focalPlaneToPixel.applyForward(
                fieldAngleToTanFocalPlane.applyForward(fieldAnglePoints)))

        skyPoints2 = wcs.pixelToSky(
            focalPlaneToPixel.applyForward(
                fieldAngleToFocalPlane.applyForward(fieldAnglePoints)))

        self.assertSpherePointListsAlmostEqual(tanSkyPoints2, skyPoints2)
示例#5
0
    def testNoDistortion(self):
        """Test makeDistortedTanWcs using an affine transform for pixelToFocalPlane

        Construct pixelToFocalPlane to match the plate scale used to
        generate self.tanWcs, the input to makeDistortedTanWcs. Thus the WCS
        returned by makeDistortedTanWcs should match self.tanWcs.
        """
        focalPlaneToFieldAngle = self.makeAffineTransform(scale=self.radPerMm)
        wcs = makeDistortedTanWcs(
            tanWcs=self.tanWcs,
            pixelToFocalPlane=self.pixelToFocalPlane,
            focalPlaneToFieldAngle=focalPlaneToFieldAngle,
        )
        self.assertWcsAlmostEqualOverBBox(wcs, self.tanWcs, bbox=self.bbox)
示例#6
0
    def testNoDistortion(self):
        """Test makeDistortedTanWcs using an affine transform for pixelToFocalPlane

        Construct pixelToFocalPlane to match the plate scale used to
        generate self.tanWcs, the input to makeDistortedTanWcs. Thus the WCS
        returned by makeDistortedTanWcs should match self.tanWcs.
        """
        focalPlaneToFieldAngle = self.makeAffineTransform(scale=self.radPerMm)
        wcs = makeDistortedTanWcs(
            tanWcs=self.tanWcs,
            pixelToFocalPlane=self.pixelToFocalPlane,
            focalPlaneToFieldAngle=focalPlaneToFieldAngle,
        )
        self.assertWcsAlmostEqualOverBBox(wcs, self.tanWcs, bbox=self.bbox)
示例#7
0
    def testDistortion(self):
        """Test makeDistortedTanWcs using a non-affine transform for pixelToFocalPlane
        """
        # Compute a distorted wcs that matches self.tanWcs at the center of the field;
        # the amount of distortion is 10s of pixels over the detector
        fieldAngleToFocalPlane = afwGeom.makeRadialTransform([0.0, 1/self.radPerMm, 0.0, 1000/self.radPerMm])
        focalPlaneToFieldAngle = fieldAngleToFocalPlane.inverted()
        focalPlaneToTanFieldAngle = self.makeAffineTransform(scale=self.radPerMm)
        wcs = makeDistortedTanWcs(
            tanWcs=self.tanWcs,
            pixelToFocalPlane=self.pixelToFocalPlane,
            focalPlaneToFieldAngle=focalPlaneToFieldAngle,
        )

        # At the center of the focal plane both WCS should give the same sky position
        pixelAtCtr = self.pixelToFocalPlane.applyInverse(lsst.geom.Point2D(0, 0))
        tanSkyAtCtr = self.tanWcs.pixelToSky(pixelAtCtr)
        skyAtCtr = wcs.pixelToSky(pixelAtCtr)
        self.assertPairsAlmostEqual(tanSkyAtCtr, skyAtCtr)

        # At all reasonable sky points the following field angles should be almost equal:
        #   sky -> tanWcs.skyToPixel -> pixelToFocalPlane -> focalPlaneToTanFieldAngle
        #   sky -> wcs.skyToPixel -> pixelToFocalPlane -> focalPlaneToFieldAngle
        # where focalPlaneToTanFieldAngle is the linear approximation to
        # focalPlaneToFieldAngle at the center of the field (where tanWcs and wcs match),
        # since for a given pointing, field angle gives position on the sky
        skyPoints = self.tanWcs.pixelToSky(self.pixelPoints)

        tanFieldAnglePoints = focalPlaneToTanFieldAngle.applyForward(
            self.pixelToFocalPlane.applyForward(self.tanWcs.skyToPixel(skyPoints)))
        fieldAnglePoints = focalPlaneToFieldAngle.applyForward(
            self.pixelToFocalPlane.applyForward(wcs.skyToPixel(skyPoints)))
        assert_allclose(tanFieldAnglePoints, fieldAnglePoints)

        # The inverse should also be true: for a set of field angle points
        # the following sky positions should be almost equal:
        # fieldAngle -> fieldAngleToTanFocalPlane -> focalPlaneToPixel -> tanWcs.pixelToSky
        # fieldAngle -> fieldAngleToFocalPlane -> focalPlaneToPixel -> wcs.pixelToSky
        focalPlaneToPixel = self.pixelToFocalPlane.inverted()
        fieldAngleToTanFocalPlane = focalPlaneToTanFieldAngle.inverted()
        tanSkyPoints2 = self.tanWcs.pixelToSky(
            focalPlaneToPixel.applyForward(
                fieldAngleToTanFocalPlane.applyForward(fieldAnglePoints)))

        skyPoints2 = wcs.pixelToSky(
            focalPlaneToPixel.applyForward(
                fieldAngleToFocalPlane.applyForward(fieldAnglePoints)))

        self.assertSpherePointListsAlmostEqual(tanSkyPoints2, skyPoints2)
示例#8
0
def addDistortionModel(exposure, camera):
    """!Update the WCS in exposure with a distortion model based on camera
    geometry.

    Parameters
    ----------
    exposure : `lsst.afw.image.Exposure`
        Exposure to process.  Must contain a Detector and WCS.  The
        exposure is modified.
    camera : `lsst.afw.cameraGeom.Camera`
        Camera geometry.

    Raises
    ------
    RuntimeError
        Raised if ``exposure`` is lacking a Detector or WCS, or if
        ``camera`` is None.
    Notes
    -----
    Add a model for optical distortion based on geometry found in ``camera``
    and the ``exposure``'s detector. The raw input exposure is assumed
    have a TAN WCS that has no compensation for optical distortion.
    Two other possibilities are:
    - The raw input exposure already has a model for optical distortion,
    as is the case for raw DECam data.
    In that case you should set config.doAddDistortionModel False.
    - The raw input exposure has a model for distortion, but it has known
    deficiencies severe enough to be worth fixing (e.g. because they
    cause problems for fitting a better WCS). In that case you should
    override this method with a version suitable for your raw data.

    """
    wcs = exposure.getWcs()
    if wcs is None:
        raise RuntimeError("exposure has no WCS")
    if camera is None:
        raise RuntimeError("camera is None")
    detector = exposure.getDetector()
    if detector is None:
        raise RuntimeError("exposure has no Detector")
    pixelToFocalPlane = detector.getTransform(camGeom.PIXELS,
                                              camGeom.FOCAL_PLANE)
    focalPlaneToFieldAngle = camera.getTransformMap().getTransform(
        camGeom.FOCAL_PLANE, camGeom.FIELD_ANGLE)
    distortedWcs = makeDistortedTanWcs(wcs, pixelToFocalPlane,
                                       focalPlaneToFieldAngle)
    exposure.setWcs(distortedWcs)
示例#9
0
def addDistortionModel(exposure, camera):
    """!Update the WCS in exposure with a distortion model based on camera
    geometry.

    Parameters
    ----------
    exposure : `lsst.afw.image.Exposure`
        Exposure to process.  Must contain a Detector and WCS.  The
        exposure is modified.
    camera : `lsst.afw.cameraGeom.Camera`
        Camera geometry.

    Raises
    ------
    RuntimeError
        Raised if ``exposure`` is lacking a Detector or WCS, or if
        ``camera`` is None.
    Notes
    -----
    Add a model for optical distortion based on geometry found in ``camera``
    and the ``exposure``'s detector. The raw input exposure is assumed
    have a TAN WCS that has no compensation for optical distortion.
    Two other possibilities are:
    - The raw input exposure already has a model for optical distortion,
    as is the case for raw DECam data.
    In that case you should set config.doAddDistortionModel False.
    - The raw input exposure has a model for distortion, but it has known
    deficiencies severe enough to be worth fixing (e.g. because they
    cause problems for fitting a better WCS). In that case you should
    override this method with a version suitable for your raw data.

    """
    wcs = exposure.getWcs()
    if wcs is None:
        raise RuntimeError("exposure has no WCS")
    if camera is None:
        raise RuntimeError("camera is None")
    detector = exposure.getDetector()
    if detector is None:
        raise RuntimeError("exposure has no Detector")
    pixelToFocalPlane = detector.getTransform(camGeom.PIXELS, camGeom.FOCAL_PLANE)
    focalPlaneToFieldAngle = camera.getTransformMap().getTransform(camGeom.FOCAL_PLANE,
                                                                   camGeom.FIELD_ANGLE)
    distortedWcs = makeDistortedTanWcs(wcs, pixelToFocalPlane, focalPlaneToFieldAngle)
    exposure.setWcs(distortedWcs)
 def makeDesiredDistortedWcs(self):
     """Make the expected distorted WCS"""
     pixelToFocalPlane = self.detector.getTransform(PIXELS, FOCAL_PLANE)
     focalPlaneToFieldAngle = self.camera.getTransformMap().getTransform(FOCAL_PLANE, FIELD_ANGLE)
     return makeDistortedTanWcs(self.wcs, pixelToFocalPlane, focalPlaneToFieldAngle)