def testConstruction(self): p = LonLat.fromDegrees(45, 45) self.assertEqual(p, LonLat(NormalizedAngle.fromDegrees(45), Angle.fromDegrees(45))) u = UnitVector3d(p) q = LonLat(u) self.assertAlmostEqual( p.getLon().asRadians(), q.getLon().asRadians(), places=13) self.assertAlmostEqual( p.getLat().asRadians(), q.getLat().asRadians(), places=13) self.assertAlmostEqual(p.getLon().asRadians(), LonLat.latitudeOf(u).asRadians(), places=13) self.assertAlmostEqual(p.getLon().asRadians(), LonLat.longitudeOf(u).asRadians(), places=13)
def _region_to_columns(self, region: Optional[Region], record: Dict[str, Any]) -> None: if region is None: return # Get spatial parameters from the bounding circle. circle = region.getBoundingCircle() center = LonLat(circle.getCenter()) record["s_ra"] = center.getLon().asDegrees() record["s_dec"] = center.getLat().asDegrees() record["s_fov"] = circle.getOpeningAngle().asDegrees() * 2 if isinstance(region, ConvexPolygon): poly = ["POLYGON ICRS"] for vertex in region.getVertices(): lon_lat = LonLat(vertex) poly += [ f"{lon_lat.getLon().asDegrees():.6f}", f"{lon_lat.getLat().asDegrees():.6f}", ] record["s_region"] = " ".join(poly) else: _LOG.warning(f"Unexpected region type: {type(region)}")
def testSkyMapDimensions(self): """Test involving only skymap dimensions, no joins to instrument""" registry = self.registry # need a bunch of dimensions and datasets for test, we want # "abstract_filter" in the test so also have to add physical_filter # dimensions registry.addDimensionEntry("instrument", dict(instrument="DummyCam")) registry.addDimensionEntry("physical_filter", dict(instrument="DummyCam", physical_filter="dummy_r", abstract_filter="r")) registry.addDimensionEntry("physical_filter", dict(instrument="DummyCam", physical_filter="dummy_i", abstract_filter="i")) registry.addDimensionEntry("skymap", dict(skymap="DummyMap", hash="sha!".encode("utf8"))) for tract in range(10): registry.addDimensionEntry("tract", dict(skymap="DummyMap", tract=tract)) for patch in range(10): registry.addDimensionEntry("patch", dict(skymap="DummyMap", tract=tract, patch=patch, cell_x=0, cell_y=0, region=Box(LonLat(NormalizedAngle(0.), Angle(0.))))) # dataset types collection = "test" run = registry.makeRun(collection=collection) storageClass = StorageClass("testDataset") registry.storageClasses.registerStorageClass(storageClass) calexpType = DatasetType(name="deepCoadd_calexp", dimensions=registry.dimensions.extract(("skymap", "tract", "patch", "abstract_filter")), storageClass=storageClass) registry.registerDatasetType(calexpType) mergeType = DatasetType(name="deepCoadd_mergeDet", dimensions=registry.dimensions.extract(("skymap", "tract", "patch")), storageClass=storageClass) registry.registerDatasetType(mergeType) measType = DatasetType(name="deepCoadd_meas", dimensions=registry.dimensions.extract(("skymap", "tract", "patch", "abstract_filter")), storageClass=storageClass) registry.registerDatasetType(measType) dimensions = registry.dimensions.empty.union(calexpType.dimensions, mergeType.dimensions, measType.dimensions, implied=True) # add pre-existing datasets for tract in (1, 3, 5): for patch in (2, 4, 6, 7): dataId = dict(skymap="DummyMap", tract=tract, patch=patch) registry.addDataset(mergeType, dataId=dataId, run=run) for aFilter in ("i", "r"): dataId = dict(skymap="DummyMap", tract=tract, patch=patch, abstract_filter=aFilter) registry.addDataset(calexpType, dataId=dataId, run=run) # with empty expression builder = DataIdQueryBuilder.fromDimensions(registry, dimensions) builder.requireDataset(calexpType, collections=[collection]) builder.requireDataset(mergeType, collections=[collection]) rows = list(builder.execute()) self.assertEqual(len(rows), 3*4*2) # 4 tracts x 4 patches x 2 filters for dataId in rows: self.assertCountEqual(dataId.keys(), ("skymap", "tract", "patch", "abstract_filter")) self.assertCountEqual(set(dataId["tract"] for dataId in rows), (1, 3, 5)) self.assertCountEqual(set(dataId["patch"] for dataId in rows), (2, 4, 6, 7)) self.assertCountEqual(set(dataId["abstract_filter"] for dataId in rows), ("i", "r")) # limit to 2 tracts and 2 patches builder = DataIdQueryBuilder.fromDimensions(registry, dimensions) builder.requireDataset(calexpType, collections=[collection]) builder.requireDataset(mergeType, collections=[collection]) builder.whereParsedExpression("tract IN (1, 5) AND patch.patch IN (2, 7)") rows = list(builder.execute()) self.assertEqual(len(rows), 2*2*2) # 4 tracts x 4 patches x 2 filters self.assertCountEqual(set(dataId["tract"] for dataId in rows), (1, 5)) self.assertCountEqual(set(dataId["patch"] for dataId in rows), (2, 7)) self.assertCountEqual(set(dataId["abstract_filter"] for dataId in rows), ("i", "r")) # limit to single filter builder = DataIdQueryBuilder.fromDimensions(registry, dimensions) builder.requireDataset(calexpType, collections=[collection]) builder.requireDataset(mergeType, collections=[collection]) builder.whereParsedExpression("abstract_filter = 'i'") rows = list(builder.execute()) self.assertEqual(len(rows), 3*4*1) # 4 tracts x 4 patches x 2 filters self.assertCountEqual(set(dataId["tract"] for dataId in rows), (1, 3, 5)) self.assertCountEqual(set(dataId["patch"] for dataId in rows), (2, 4, 6, 7)) self.assertCountEqual(set(dataId["abstract_filter"] for dataId in rows), ("i",)) # expression excludes everything, specifying non-existing skymap is # not a fatal error, it's operator error builder = DataIdQueryBuilder.fromDimensions(registry, dimensions) builder.requireDataset(calexpType, collections=[collection]) builder.requireDataset(mergeType, collections=[collection]) builder.whereParsedExpression("skymap = 'Mars'") rows = list(builder.execute()) self.assertEqual(len(rows), 0)