def testConstruction(self):
     points = [UnitVector3d.Z(), UnitVector3d.X(), UnitVector3d.Y()]
     p1 = ConvexPolygon(points)
     self.assertEqual(points, p1.getVertices())
     p2 = ConvexPolygon.cast(p1.clone())
     self.assertEqual(p1, p2)
     p3 = ConvexPolygon([-UnitVector3d.Z(), UnitVector3d.X(), UnitVector3d.Y()])
     self.assertNotEqual(p1, p3)
Example #2
0
 def insertObservationRegions(self, registry, datastore):
     """Add spatial regions for visit-detector combinations.
     """
     sql = (
         "SELECT wcs.instrument AS instrument, wcs.visit AS visit, wcs.detector AS detector, "
         "        wcs.dataset_id AS wcs, metadata.dataset_id AS metadata "
         "    FROM dataset wcs "
         "        INNER JOIN dataset_collection wcs_collection "
         "            ON (wcs.dataset_id = wcs_collection.dataset_id) "
         "        INNER JOIN dataset metadata "
         "            ON (wcs.instrument = metadata.instrument "
         "                AND wcs.visit = metadata.visit "
         "                AND wcs.detector = metadata.detector) "
         "        INNER JOIN dataset_collection metadata_collection "
         "            ON (metadata.dataset_id = metadata_collection.dataset_id) "
         "    WHERE wcs_collection.collection = :collection "
         "          AND metadata_collection.collection = :collection "
         "          AND wcs.dataset_type_name = :wcs_name"
         "          AND metadata.dataset_type_name = :metadata_name")
     log = Log.getLogger("lsst.daf.butler.gen2convert")
     for config in self.config["regions"]:
         log.info("Adding observation regions using %s from %s.",
                  config["DatasetType"], config["collection"])
         visits = {}
         for row in registry.query(
                 sql,
                 collection=config["collection"],
                 wcs_name="{}.wcs".format(config["DatasetType"]),
                 metadata_name="{}.metadata".format(config["DatasetType"])):
             wcsRef = registry.getDataset(row["wcs"])
             metadataRef = registry.getDataset(row["metadata"])
             wcs = datastore.get(wcsRef)
             metadata = datastore.get(metadataRef)
             bbox = Box2D(bboxFromMetadata(metadata))
             bbox.grow(config["padding"])
             region = ConvexPolygon([
                 sp.getVector() for sp in wcs.pixelToSky(bbox.getCorners())
             ])
             registry.setDimensionRegion(
                 {k: row[k]
                  for k in ("instrument", "visit", "detector")},
                 region=region,
                 update=False)
             visits.setdefault((row["instrument"], row["visit"]),
                               []).extend(region.getVertices())
         for (instrument, visit), vertices in visits.items():
             region = ConvexPolygon(vertices)
             registry.setDimensionRegion(instrument=instrument,
                                         visit=visit,
                                         region=region)
Example #3
0
def poly_area(polygon: sph.ConvexPolygon) -> float:
    """Calculate area of a convex polygon.

    Parameters
    ----------
    polygon : `lsst.sphgeom.ConvexPolygon`

    Returns
    -------
    area : `float`
    """

    vertices = polygon.getVertices()
    area = 0.
    for i in range(2, len(vertices)):
        area += triangle_area(vertices[0], vertices[i - 1], vertices[i])
    return area
 def testConstruction(self):
     points = [UnitVector3d.Z(), UnitVector3d.X(), UnitVector3d.Y()]
     p1 = ConvexPolygon(points)
     self.assertEqual(points, p1.getVertices())
     p2 = p1.clone()
     self.assertEqual(p1, p2)
     p3 = ConvexPolygon(
         [-UnitVector3d.Z(),
          UnitVector3d.X(),
          UnitVector3d.Y()])
     self.assertNotEqual(p1, p3)
     p4 = ConvexPolygon.convexHull([
         UnitVector3d.Y(),
         UnitVector3d.X(),
         UnitVector3d(1, 1, 1),
         UnitVector3d.Z()
     ])
     self.assertEqual(p1, p4)