Ejemplo n.º 1
0
 def setUp(self):
     # Test geometry:
     #
     # -100,99                99,99
     #     +--------------------+
     #     |AAAAAAAAAACCCCCDDDDD|    A == only in epoch A
     #     |AAAAAAAAAACCCCCDDDDD|    B == only in epoch B
     #     |AAAAAAAAAACCCCCDDDDD|    C == in both epoch A and epoch B
     #     |AAAAAAAAAACCCCCDDDDD|    D == in epoch A; in B's bbox but outside its ValidPolygon
     #     |AAAAAAAAAACCCCCDDDDD|
     #     |          BBBBBBBBBB|    All WCSs have the same CRVAL and CD.
     #     |          BBBBBBBBBB|
     #     |          BBBBBBBBBB|    Coadd has CRPIX=(0, 0)
     #     |          BBBBBBBBBB|    Epoch A has CRPIX=(0, -50)
     #     |          BBBBBBBBBB|    Epoch B has CRPIX=(-50, 0)
     #     +--------------------+
     # -100,-100             99,-100
     #
     self.rng = np.random.RandomState(50)
     crval = SpherePoint(45.0, 45.0, degrees)
     cdMatrix = makeCdMatrix(scale=5E-5 * degrees, flipX=True)
     self.wcsCoadd = makeSkyWcs(crpix=Point2D(0.0, 0.0),
                                crval=crval,
                                cdMatrix=cdMatrix)
     self.wcsA = makeSkyWcs(crpix=Point2D(0.0, -50.0),
                            crval=crval,
                            cdMatrix=cdMatrix)
     self.wcsB = makeSkyWcs(crpix=Point2D(-50.0, 0.0),
                            crval=crval,
                            cdMatrix=cdMatrix)
     self.bboxCoadd = Box2I(Point2I(-100, -100), Point2I(99, 99))
     self.bboxA = Box2I(Point2I(-100, -50), Point2I(99, 49))
     self.bboxB = Box2I(Point2I(-50, -100), Point2I(49, 99))
     self.polygonA = None
     polygonD = Polygon(Box2D(Box2I(Point2I(0, 0), Point2I(49, 99))))
     self.polygonB, = polygonD.symDifference(Polygon(Box2D(self.bboxB)))
     self.curveA = makeRandomTransmissionCurve(self.rng)
     self.curveB = makeRandomTransmissionCurve(self.rng)
     self.weightA = 0.6
     self.weightB = 0.2
     schema = ExposureTable.makeMinimalSchema()
     weightKey = schema.addField("weight",
                                 type=float,
                                 doc="relative weight of image in Coadd")
     catalog = ExposureCatalog(schema)
     recordA = catalog.addNew()
     recordA[weightKey] = self.weightA
     recordA.setWcs(self.wcsA)
     recordA.setValidPolygon(self.polygonA)
     recordA.setBBox(self.bboxA)
     recordA.setTransmissionCurve(self.curveA)
     recordB = catalog.addNew()
     recordB[weightKey] = self.weightB
     recordB.setWcs(self.wcsB)
     recordB.setValidPolygon(self.polygonB)
     recordB.setBBox(self.bboxB)
     recordB.setTransmissionCurve(self.curveB)
     self.curveCoadd = makeCoaddTransmissionCurve(self.wcsCoadd, catalog)
 def setUp(self):
     # Test geometry:
     #
     # -100,99                99,99
     #     +--------------------+
     #     |AAAAAAAAAACCCCCDDDDD|    A == only in epoch A
     #     |AAAAAAAAAACCCCCDDDDD|    B == only in epoch B
     #     |AAAAAAAAAACCCCCDDDDD|    C == in both epoch A and epoch B
     #     |AAAAAAAAAACCCCCDDDDD|    D == in epoch A; in B's bbox but outside its ValidPolygon
     #     |AAAAAAAAAACCCCCDDDDD|
     #     |          BBBBBBBBBB|    All WCSs have the same CRVAL and CD.
     #     |          BBBBBBBBBB|
     #     |          BBBBBBBBBB|    Coadd has CRPIX=(0, 0)
     #     |          BBBBBBBBBB|    Epoch A has CRPIX=(0, -50)
     #     |          BBBBBBBBBB|    Epoch B has CRPIX=(-50, 0)
     #     +--------------------+
     # -100,-100             99,-100
     #
     self.rng = np.random.RandomState(50)
     crval = SpherePoint(45.0, 45.0, degrees)
     cdMatrix = makeCdMatrix(scale=5E-5*degrees, flipX=True)
     self.wcsCoadd = makeSkyWcs(crpix=Point2D(0.0, 0.0), crval=crval, cdMatrix=cdMatrix)
     self.wcsA = makeSkyWcs(crpix=Point2D(0.0, -50.0), crval=crval, cdMatrix=cdMatrix)
     self.wcsB = makeSkyWcs(crpix=Point2D(-50.0, 0.0), crval=crval, cdMatrix=cdMatrix)
     self.bboxCoadd = Box2I(Point2I(-100, -100), Point2I(99, 99))
     self.bboxA = Box2I(Point2I(-100, -50), Point2I(99, 49))
     self.bboxB = Box2I(Point2I(-50, -100), Point2I(49, 99))
     self.polygonA = None
     polygonD = Polygon(Box2D(Box2I(Point2I(0, 0), Point2I(49, 99))))
     self.polygonB, = polygonD.symDifference(Polygon(Box2D(self.bboxB)))
     self.curveA = makeRandomTransmissionCurve(self.rng)
     self.curveB = makeRandomTransmissionCurve(self.rng)
     self.weightA = 0.6
     self.weightB = 0.2
     schema = ExposureTable.makeMinimalSchema()
     weightKey = schema.addField("weight", type=float, doc="relative weight of image in Coadd")
     catalog = ExposureCatalog(schema)
     recordA = catalog.addNew()
     recordA[weightKey] = self.weightA
     recordA.setWcs(self.wcsA)
     recordA.setValidPolygon(self.polygonA)
     recordA.setBBox(self.bboxA)
     recordA.setTransmissionCurve(self.curveA)
     recordB = catalog.addNew()
     recordB[weightKey] = self.weightB
     recordB.setWcs(self.wcsB)
     recordB.setValidPolygon(self.polygonB)
     recordB.setBBox(self.bboxB)
     recordB.setTransmissionCurve(self.curveB)
     self.curveCoadd = makeCoaddTransmissionCurve(self.wcsCoadd, catalog)
Ejemplo n.º 3
0
 def testMultiPlaneFitsReaders(self):
     """Run tests for MaskedImageFitsReader and ExposureFitsReader.
     """
     metadata = PropertyList()
     metadata.add("FIVE", 5)
     metadata.add("SIX", 6.0)
     wcs = makeSkyWcs(Point2D(2.5, 3.75),
                      SpherePoint(40.0 * degrees, 50.0 * degrees),
                      np.array([[1E-5, 0.0], [0.0, -1E-5]]))
     defineFilter("test_readers_filter", lambdaEff=470.0)
     calib = PhotoCalib(2.5E4)
     psf = GaussianPsf(21, 21, 8.0)
     polygon = Polygon(Box2D(self.bbox))
     apCorrMap = ApCorrMap()
     visitInfo = VisitInfo(exposureTime=5.0)
     transmissionCurve = TransmissionCurve.makeIdentity()
     coaddInputs = CoaddInputs(ExposureTable.makeMinimalSchema(),
                               ExposureTable.makeMinimalSchema())
     detector = DetectorWrapper().detector
     record = coaddInputs.ccds.addNew()
     record.setWcs(wcs)
     record.setPhotoCalib(calib)
     record.setPsf(psf)
     record.setValidPolygon(polygon)
     record.setApCorrMap(apCorrMap)
     record.setVisitInfo(visitInfo)
     record.setTransmissionCurve(transmissionCurve)
     record.setDetector(detector)
     for n, dtypeIn in enumerate(self.dtypes):
         with self.subTest(dtypeIn=dtypeIn):
             exposureIn = Exposure(self.bbox, dtype=dtypeIn)
             shape = exposureIn.image.array.shape
             exposureIn.image.array[:, :] = np.random.randint(low=1,
                                                              high=5,
                                                              size=shape)
             exposureIn.mask.array[:, :] = np.random.randint(low=1,
                                                             high=5,
                                                             size=shape)
             exposureIn.variance.array[:, :] = np.random.randint(low=1,
                                                                 high=5,
                                                                 size=shape)
             exposureIn.setMetadata(metadata)
             exposureIn.setWcs(wcs)
             exposureIn.setFilter(Filter("test_readers_filter"))
             exposureIn.setFilterLabel(
                 FilterLabel(physical="test_readers_filter"))
             exposureIn.setPhotoCalib(calib)
             exposureIn.setPsf(psf)
             exposureIn.getInfo().setValidPolygon(polygon)
             exposureIn.getInfo().setApCorrMap(apCorrMap)
             exposureIn.getInfo().setVisitInfo(visitInfo)
             exposureIn.getInfo().setTransmissionCurve(transmissionCurve)
             exposureIn.getInfo().setCoaddInputs(coaddInputs)
             exposureIn.setDetector(detector)
             with lsst.utils.tests.getTempFilePath(".fits") as fileName:
                 exposureIn.writeFits(fileName)
                 self.checkMaskedImageFitsReader(exposureIn, fileName,
                                                 self.dtypes[n:])
                 self.checkExposureFitsReader(exposureIn, fileName,
                                              self.dtypes[n:])
Ejemplo n.º 4
0
    def testUnion(self):
        """Test Polygon.union"""
        poly1 = self.square(2.0, -1.0, -1.0)
        poly2 = self.square(2.0, +1.0, +1.0)
        poly3 = Polygon([
            afwGeom.Point2D(x, y)
            for x, y in ((-3.0, -3.0), (-3.0, +1.0), (-1.0, +1.0),
                         (-1.0, +3.0), (+3.0, +3.0), (+3.0, -1.0),
                         (+1.0, -1.0), (+1.0, -3.0))
        ])
        poly4 = self.square(1.0, +5.0, +5.0)

        # unionSingle: assumes there's a single union (intersecting polygons)
        self.assertEqual(poly1.unionSingle(poly2), poly3)
        self.assertEqual(poly2.unionSingle(poly1), poly3)
        self.assertRaises(SinglePolygonException, poly1.unionSingle, poly4)
        self.assertRaises(SinglePolygonException, poly4.unionSingle, poly1)

        # union: no assumptions
        polyList1 = poly1.union(poly2)
        polyList2 = poly2.union(poly1)
        self.assertEqual(polyList1, polyList2)
        self.assertEqual(len(polyList1), 1)
        self.assertEqual(polyList1[0], poly3)
        polyList3 = poly1.union(poly4)
        polyList4 = poly4.union(poly1)
        self.assertEqual(len(polyList3), 2)
        self.assertEqual(len(polyList3), len(polyList4))
        self.assertTrue(
            (polyList3[0] == polyList4[0] and polyList3[1] == polyList4[1])
            or (polyList3[0] == polyList4[1] and polyList3[1] == polyList4[0]))
        self.assertTrue((polyList3[0] == poly1 and polyList3[1] == poly4)
                        or (polyList3[0] == poly4 and polyList3[1] == poly1))
Ejemplo n.º 5
0
 def testFromBox(self):
     size = 1.0
     poly1 = self.square(size=size)
     box = afwGeom.Box2D(afwGeom.Point2D(-1.0, -1.0),
                         afwGeom.Point2D(1.0, 1.0))
     poly2 = Polygon(box)
     self.assertEqual(poly1, poly2)
Ejemplo n.º 6
0
    def square(self, size=1.0, x0=0, y0=0):
        """Generate a square

        @param size: Half-length of the sides
        @param x0,y0: Offset of center
        """
        return Polygon([
            afwGeom.Point2D(size * x + x0, size * y + y0)
            for x, y in ((-1, -1), (-1, 1), (1, 1), (1, -1))
        ])
Ejemplo n.º 7
0
 def testConvexHull(self):
     """Test Polygon.convexHull"""
     poly1 = self.square(2.0, -1.0, -1.0)
     poly2 = self.square(2.0, +1.0, +1.0)
     poly = poly1.unionSingle(poly2)
     expected = Polygon([
         afwGeom.Point2D(x, y)
         for x, y in ((-3.0, -3.0), (-3.0, +1.0), (-1.0, +3.0),
                      (+3.0, +3.0), (+3.0, -1.0), (+1.0, -3.0))
     ])
     self.assertEqual(poly.convexHull(), expected)
Ejemplo n.º 8
0
    def polygon(self, num, radius=1.0, x0=None, y0=None):
        """Generate a polygon

        @param num: Number of points
        @param radius: Radius of polygon
        @param x0,y0: Offset of center
        @return polygon
        """
        if x0 is None:
            x0 = self.x0
        if y0 is None:
            y0 = self.y0
        points = circle(radius, num, x0=x0, y0=y0)
        return Polygon([afwGeom.Point2D(x, y) for x, y in reversed(points)])
Ejemplo n.º 9
0
    def testTransform(self):
        """Test constructor for Polygon involving transforms"""
        box = afwGeom.Box2D(afwGeom.Point2D(0.0, 0.0),
                            afwGeom.Point2D(123.4, 567.8))
        poly1 = Polygon(box)
        scale = (0.2 * afwGeom.arcseconds).asDegrees()
        wcs = afwImage.makeWcs(
            afwCoord.Coord(0.0 * afwGeom.degrees, 0.0 * afwGeom.degrees),
            afwGeom.Point2D(0.0, 0.0), scale, 0.0, 0.0, scale)
        transform = afwImage.XYTransformFromWcsPair(wcs, wcs)
        poly2 = Polygon(box, transform)

        # We lose some very small precision in the XYTransformFromWcsPair
        # so we can't compare the polygons directly.
        self.assertEqual(poly1.getNumEdges(), poly2.getNumEdges())
        for p1, p2 in zip(poly1.getVertices(), poly2.getVertices()):
            self.assertAlmostEqual(p1.getX(), p2.getX())
            self.assertAlmostEqual(p1.getY(), p2.getY())

        transform = afwGeom.AffineTransform.makeScaling(1.0)
        poly3 = Polygon(box, transform)
        self.assertEqual(poly1, poly3)
Ejemplo n.º 10
0
    def testTransform(self):
        """Test constructor for Polygon involving transforms"""
        box = afwGeom.Box2D(afwGeom.Point2D(0.0, 0.0), afwGeom.Point2D(123.4, 567.8))
        poly1 = Polygon(box)
        scale = (0.2*afwGeom.arcseconds).asDegrees()
        wcs = afwImage.makeWcs(afwCoord.Coord(0.0*afwGeom.degrees, 0.0*afwGeom.degrees),
                               afwGeom.Point2D(0.0, 0.0), scale, 0.0, 0.0, scale)
        transform = afwImage.XYTransformFromWcsPair(wcs, wcs)
        poly2 = Polygon(box, transform)

        # We lose some very small precision in the XYTransformFromWcsPair
        # so we can't compare the polygons directly.
        self.assertEqual(poly1.getNumEdges(), poly2.getNumEdges())
        for p1, p2 in zip(poly1.getVertices(), poly2.getVertices()):
            self.assertAlmostEqual(p1.getX(), p2.getX())
            self.assertAlmostEqual(p1.getY(), p2.getY())

        transform = afwGeom.AffineTransform.makeScaling(1.0)
        poly3 = Polygon(box, transform)
        self.assertEqual(poly1, poly3)
Ejemplo n.º 11
0
 def makePolygon():
     return Polygon([Point2D(1, 2), Point2D(2, 1)])