Exemplo n.º 1
0
 def testComparisonOperators(self):
     a1 = NormalizedAngle(1)
     a2 = NormalizedAngle(2)
     self.assertNotEqual(a1, a2)
     self.assertLess(a1, a2)
     self.assertLessEqual(a1, a2)
     self.assertGreater(a2, a1)
     self.assertGreaterEqual(a2, a1)
Exemplo n.º 2
0
 def test_center_and_dimensions(self):
     b = Box.fromDegrees(-90, -45, 90, 45)
     self.assertEqual(b.getCenter(), LonLat.fromDegrees(0, 0))
     self.assertEqual(b.getWidth(), Angle.fromDegrees(180))
     self.assertEqual(b.getHeight(), Angle.fromDegrees(90))
     self.assertEqual(b.getLon().getA(), NormalizedAngle.fromDegrees(-90))
     self.assertEqual(b.getLat().getB(), Angle.fromDegrees(45))
Exemplo n.º 3
0
 def testArithmeticOperators(self):
     a = NormalizedAngle(1)
     b = -a
     self.assertEqual(a + b, Angle(0))
     self.assertEqual(a - b, 2.0 * a)
     self.assertEqual(a - b, a * 2.0)
     self.assertEqual(a / 1.0, a)
     self.assertEqual(a / a, 1.0)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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 testConstruction(self):
     a1 = NormalizedAngle(1.0)
     a2 = NormalizedAngle.fromRadians(1.0)
     a3 = NormalizedAngle.fromDegrees(57.29577951308232)
     self.assertEqual(a1, a2)
     self.assertEqual(a1.asRadians(), 1.0)
     self.assertEqual(a1, a3)
     self.assertEqual(a1.asDegrees(), 57.29577951308232)
     self.assertEqual(NormalizedAngle.between(NormalizedAngle(0), NormalizedAngle(1)),
                      NormalizedAngle(1))
     a = NormalizedAngle.center(NormalizedAngle(0), NormalizedAngle(1))
     self.assertAlmostEqual(a.asRadians(), 0.5, places=15)
     a = NormalizedAngle(LonLat.fromDegrees(45, 0), LonLat.fromDegrees(90, 0))
     self.assertAlmostEqual(a.asDegrees(), 45.0, places=13)
     a = NormalizedAngle(UnitVector3d.Y(), UnitVector3d.Z())
     self.assertAlmostEqual(a.asDegrees(), 90.0, places=13)        
Exemplo n.º 7
0
 def testPickle(self):
     a = NormalizedAngle(1.5)
     b = pickle.loads(pickle.dumps(a))
     self.assertEqual(a, b)
Exemplo n.º 8
0
 def testString(self):
     self.assertEqual(str(NormalizedAngle(1)), '1.0')
     self.assertEqual(repr(NormalizedAngle(1)), 'NormalizedAngle(1.0)')
     a = NormalizedAngle(0.5)
     self.assertEqual(a, eval(repr(a),
                              dict(NormalizedAngle=NormalizedAngle)))
Exemplo n.º 9
0
 def testAngleTo(self):
     self.assertEqual(
         NormalizedAngle(1).getAngleTo(NormalizedAngle(2)),
         NormalizedAngle(1))
Exemplo n.º 10
0
 def testConstruction(self):
     a1 = NormalizedAngle(1.0)
     a2 = NormalizedAngle.fromRadians(1.0)
     a3 = NormalizedAngle.fromDegrees(57.29577951308232)
     self.assertEqual(a1, a2)
     self.assertEqual(a1.asRadians(), 1.0)
     self.assertEqual(a1, a3)
     self.assertEqual(a1.asDegrees(), 57.29577951308232)
     self.assertEqual(
         NormalizedAngle.between(NormalizedAngle(0), NormalizedAngle(1)),
         NormalizedAngle(1))
     a = NormalizedAngle.center(NormalizedAngle(0), NormalizedAngle(1))
     self.assertAlmostEqual(a.asRadians(), 0.5, places=15)
     a = NormalizedAngle(LonLat.fromDegrees(45, 0),
                         LonLat.fromDegrees(90, 0))
     self.assertAlmostEqual(a.asDegrees(), 45.0, places=13)
     a = NormalizedAngle(UnitVector3d.Y(), UnitVector3d.Z())
     self.assertAlmostEqual(a.asDegrees(), 90.0, places=13)
Exemplo n.º 11
0
    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)