Esempio n. 1
0
 def compute(self,
             visit: VisitDefinitionData,
             *,
             collections: Any = None) -> Tuple[Region, Dict[int, Region]]:
     # Docstring inherited from ComputeVisitRegionsTask.
     if self.config.mergeExposures:
         detectorBounds = defaultdict(list)
         for exposure in visit.exposures:
             exposureDetectorBounds = self.computeExposureBounds(
                 exposure, collections=collections)
             for detectorId, bounds in exposureDetectorBounds.items():
                 detectorBounds[detectorId].extend(bounds)
     else:
         detectorBounds = self.computeExposureBounds(
             visit.exposures[0], collections=collections)
     visitBounds = []
     detectorRegions = {}
     for detectorId, bounds in detectorBounds.items():
         detectorRegions[detectorId] = ConvexPolygon.convexHull(bounds)
         visitBounds.extend(bounds)
     return ConvexPolygon.convexHull(visitBounds), detectorRegions
 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)
Esempio n. 3
0
def makeSkyPolygonFromBBox(bbox, wcs):
    """Make an on-sky polygon from a bbox and a SkyWcs

    Parameters
    ----------
    bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D`
        Bounding box of region, in pixel coordinates
    wcs : `lsst.afw.geom.SkyWcs`
        Celestial WCS

    Returns
    -------
    polygon : `lsst.sphgeom.ConvexPolygon`
        On-sky region
    """
    pixelPoints = Box2D(bbox).getCorners()
    skyPoints = wcs.pixelToSky(pixelPoints)
    return ConvexPolygon.convexHull([sp.getVector() for sp in skyPoints])
Esempio n. 4
0
def makeSkyPolygonFromBBox(bbox, wcs):
    """Make an on-sky polygon from a bbox and a SkyWcs

    Parameters
    ----------
    bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D`
        Bounding box of region, in pixel coordinates
    wcs : `lsst.afw.geom.SkyWcs`
        Celestial WCS

    Returns
    -------
    polygon : `lsst.sphgeom.ConvexPolygon`
        On-sky region
    """
    pixelPoints = Box2D(bbox).getCorners()
    skyPoints = wcs.pixelToSky(pixelPoints)
    return ConvexPolygon.convexHull([sp.getVector() for sp in skyPoints])
Esempio n. 5
0
 def getInnerSkyPolygon(self):
     """Get inner on-sky region as a sphgeom.ConvexPolygon.
     """
     skyUnitVectors = [sp.getVector() for sp in self.getVertexList()]
     return ConvexPolygon.convexHull(skyUnitVectors)
Esempio n. 6
0
 def getInnerSkyPolygon(self):
     """Get inner on-sky region as a sphgeom.ConvexPolygon.
     """
     skyUnitVectors = [sp.getVector() for sp in self.getVertexList()]
     return ConvexPolygon.convexHull(skyUnitVectors)
Esempio n. 7
0
def main(subset, margin=10):
    visits = {}
    regions = {}
    vertices = {}
    raw = {}
    bias = {}
    dark = {}
    flat = {}
    for ref in subset:
        visit = ref.dataId["visit"]
        sensor = ref.dataId["ccd"]
        filter = ref.dataId["filter"]
        if visit not in visits:
            info = ref.get("calexp_visitInfo")
            obsMid = info.getDate()
            expTime = info.getExposureTime()
            # convert from middle of exposure date/time to beginning,
            # by subtracting half of the exposure time in nanoseconds
            obsBegin = DateTime(obsMid.nsecs() - int(expTime)*500000000)
            visits[visit] = (filter, obsBegin, expTime)
        raw[visit, sensor] = ref.get("raw_filename")[0]
        biasUnits = selectCalibUnits("bias", sensor)
        assert biasUnits[0] <= visit and biasUnits[1] > visit
        bias[biasUnits] = ref.get("bias_filename")[0]
        darkUnits = selectCalibUnits("dark", sensor)
        assert darkUnits[0] <= visit and darkUnits[1] > visit
        dark[darkUnits] = ref.get("dark_filename")[0]
        flatUnits = selectCalibUnits("flat", sensor, filter)
        assert flatUnits[0] <= visit and flatUnits[1] > visit
        flat[flatUnits] = ref.get("flat_filename")[0]
        bbox = ref.get("calexp_bbox")
        wcs = ref.get("calexp_wcs")
        region = makeBoxWcsRegion(box=bbox, wcs=wcs, margin=margin)
        regions[visit, sensor] = region
        vertices.setdefault(visit, []).extend(region.getVertices())

    tables["Dataset"] = np.zeros(len(raw) + len(bias) + len(dark) + len(flat),
                                 dtype=dtypes["Dataset"])
    tables["Visit"] = np.zeros(len(visits), dtype=dtypes["Visit"])
    tables["Snap"] = np.zeros(len(visits), dtype=dtypes["Snap"])
    tables["ObservedSensor"] = np.zeros(len(raw), dtype=dtypes["ObservedSensor"])
    tables["ObservedSensor"] = np.zeros(len(raw), dtype=dtypes["ObservedSensor"])
    tables["SnapDatasetJoin"] = np.zeros(len(raw), dtype=dtypes["SnapDatasetJoin"])
    tables["PhysicalSensorDatasetJoin"] = np.zeros(len(raw) + len(bias) + len(dark) + len(flat),
                                                   dtype=dtypes["PhysicalSensorDatasetJoin"])
    tables["PhysicalFilterDatasetJoin"] = np.zeros(len(flat), dtype=dtypes["PhysicalFilterDatasetJoin"])
    tables["VisitRangeDatasetJoin"] = np.zeros(len(flat) + len(bias) + len(dark),
                                               dtype=dtypes["VisitRangeDatasetJoin"])

    snapIndex = 1
    cameraName = "HSC"
    for n, (visit, (filter, obsBegin, expTime)) in enumerate(visits.items()):
        visitRecord = tables["Visit"][n]
        visitRecord["visit_number"] = visit
        visitRecord["physical_filter_name"] = filter
        visitRecord["obs_begin"] = obsBegin
        visitRecord["exposure_time"] = expTime
        visitRecord["region"] = ConvexPolygon.convexHull(vertices[visit]).encode()
        visitRecord["camera_name"] = cameraName
        snapRecord = tables["Snap"][n]
        snapRecord["visit_number"] = visit
        snapRecord["snap_index"] = snapIndex
        snapRecord["obs_begin"] = obsBegin
        snapRecord["exposure_time"] = expTime
        snapRecord["camera_name"] = cameraName

    datasetId = 1
    registryId = 1
    runId = 0
    for n, ((visit, sensor), uri) in enumerate(raw.items()):
        datasetRecord = tables["Dataset"][n]
        datasetRecord["dataset_id"] = datasetId
        datasetRecord["registry_id"] = registryId
        datasetRecord["uri"] = uri
        datasetRecord["dataset_type_name"] = "raw"
        datasetRecord["run_id"] = runId
        osRecord = tables["ObservedSensor"][n]
        osRecord["visit_number"] = visit
        osRecord["physical_sensor_number"] = sensor
        osRecord["camera_name"] = cameraName
        osRecord["region"] = regions[visit, sensor].encode()
        snapJoinRecord = tables["SnapDatasetJoin"][n]
        snapJoinRecord["dataset_id"] = datasetId
        snapJoinRecord["registry_id"] = registryId
        snapJoinRecord["visit_number"] = visit
        snapJoinRecord["camera_name"] = cameraName
        snapJoinRecord["snap_index"] = snapIndex
        psJoinRecord = tables["PhysicalSensorDatasetJoin"][n]
        psJoinRecord["dataset_id"] = datasetId
        psJoinRecord["registry_id"] = registryId
        psJoinRecord["physical_sensor_number"] = sensor
        psJoinRecord["camera_name"] = cameraName
        datasetId += 1

    for n1, ((visitBegin, visitEnd, sensor), uri) in enumerate(bias.items()):
        n2 = n1 + len(raw)
        n3 = n1
        datasetRecord = tables["Dataset"][n2]
        datasetRecord["dataset_id"] = datasetId
        datasetRecord["registry_id"] = registryId
        datasetRecord["uri"] = uri
        datasetRecord["dataset_type_name"] = "bias"
        datasetRecord["run_id"] = runId
        psJoinRecord = tables["PhysicalSensorDatasetJoin"][n2]
        psJoinRecord["dataset_id"] = datasetId
        psJoinRecord["registry_id"] = registryId
        psJoinRecord["physical_sensor_number"] = sensor
        psJoinRecord["camera_name"] = cameraName
        vrJoinRecord = tables["VisitRangeDatasetJoin"][n3]
        vrJoinRecord["dataset_id"] = datasetId
        vrJoinRecord["registry_id"] = registryId
        vrJoinRecord["visit_begin"] = visitBegin
        vrJoinRecord["visit_end"] = visitEnd
        vrJoinRecord["camera_name"] = cameraName
        datasetId += 1

    for n1, ((visitBegin, visitEnd, sensor), uri) in enumerate(dark.items()):
        n2 = n1 + len(raw) + len(bias)
        n3 = n1 + len(bias)
        datasetRecord = tables["Dataset"][n2]
        datasetRecord["dataset_id"] = datasetId
        datasetRecord["registry_id"] = registryId
        datasetRecord["uri"] = uri
        datasetRecord["dataset_type_name"] = "dark"
        datasetRecord["run_id"] = runId
        psJoinRecord = tables["PhysicalSensorDatasetJoin"][n2]
        psJoinRecord["dataset_id"] = datasetId
        psJoinRecord["registry_id"] = registryId
        psJoinRecord["physical_sensor_number"] = sensor
        psJoinRecord["camera_name"] = cameraName
        vrJoinRecord = tables["VisitRangeDatasetJoin"][n3]
        vrJoinRecord["dataset_id"] = datasetId
        vrJoinRecord["registry_id"] = registryId
        vrJoinRecord["visit_begin"] = visitBegin
        vrJoinRecord["visit_end"] = visitEnd
        vrJoinRecord["camera_name"] = cameraName
        datasetId += 1

    for n1, ((visitBegin, visitEnd, sensor, filter), uri) in enumerate(flat.items()):
        n2 = n1 + len(raw) + len(bias) + len(dark)
        n3 = n1 + len(bias) + len(dark)
        datasetRecord = tables["Dataset"][n2]
        datasetRecord["dataset_id"] = datasetId
        datasetRecord["registry_id"] = registryId
        datasetRecord["uri"] = uri
        datasetRecord["dataset_type_name"] = "flat"
        datasetRecord["run_id"] = runId
        psJoinRecord = tables["PhysicalSensorDatasetJoin"][n2]
        psJoinRecord["dataset_id"] = datasetId
        psJoinRecord["registry_id"] = registryId
        psJoinRecord["physical_sensor_number"] = sensor
        psJoinRecord["camera_name"] = cameraName
        vrJoinRecord = tables["VisitRangeDatasetJoin"][n3]
        vrJoinRecord["dataset_id"] = datasetId
        vrJoinRecord["registry_id"] = registryId
        vrJoinRecord["visit_begin"] = visitBegin
        vrJoinRecord["visit_end"] = visitEnd
        vrJoinRecord["camera_name"] = cameraName
        pfJoinRecord = tables["PhysicalFilterDatasetJoin"][n1]
        pfJoinRecord["dataset_id"] = datasetId
        pfJoinRecord["registry_id"] = registryId
        pfJoinRecord["physical_filter_name"] = filter
        pfJoinRecord["camera_name"] = cameraName
        datasetId += 1

    for name, table in tables.items():
        np.save(os.path.join(DATA_ROOT, "{}.npy".format(name)), table)