def test_comparison_operators(self): self.assertEqual(Box(LonLat.fromDegrees(45, 45)), LonLat.fromDegrees(45, 45)) self.assertEqual(Box.fromDegrees(90, -45, 180, 45), Box(NormalizedAngleInterval.fromDegrees(90, 180), AngleInterval.fromDegrees(-45, 45))) self.assertNotEqual(Box(LonLat.fromDegrees(45, 45)), LonLat.fromDegrees(45, 90)) self.assertNotEqual(Box.fromDegrees(90, -45, 180, 45), Box.fromDegrees(90, -45, 180, 90))
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))
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)
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)
def testConstruction(self): v = Vector3d(1, 1, 1) u = UnitVector3d.orthogonalTo(v) self.assertAlmostEqual(u.dot(v), 0.0, places=15) a = UnitVector3d(1, 1, 1) self.assertEqual(a, UnitVector3d(Vector3d(1, 1, 1))) self.assertAlmostEqual(a.x(), math.sqrt(3.0) / 3.0, places=15) self.assertAlmostEqual(a.y(), math.sqrt(3.0) / 3.0, places=15) self.assertAlmostEqual(a.z(), math.sqrt(3.0) / 3.0, places=15) b = UnitVector3d(Angle.fromDegrees(45), Angle.fromDegrees(45)) self.assertEqual(b, UnitVector3d(LonLat.fromDegrees(45, 45))) self.assertAlmostEqual(b.x(), 0.5, places=15) self.assertAlmostEqual(b.y(), 0.5, places=15) self.assertAlmostEqual(b.z(), 0.5 * math.sqrt(2.0), places=15) c = UnitVector3d.northFrom(b) d = UnitVector3d(LonLat.fromDegrees(225, 45)) self.assertAlmostEqual(c.x(), d.x(), places=15) self.assertAlmostEqual(c.y(), d.y(), places=15) self.assertAlmostEqual(c.z(), d.z(), places=15)
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 test_relationships(self): b1 = Box.fromDegrees(90, 0, 180, 45) p = LonLat.fromDegrees(135, 10) self.assertTrue(p in b1) self.assertTrue(b1.contains(p)) b2 = Box.fromDegrees(135, 15, 135, 30) self.assertTrue(b1.contains(b2)) self.assertTrue(b2.isWithin(b1)) b3 = Box.fromDegrees(0, -45, 90, 0) u = UnitVector3d(1, 1, -1) self.assertTrue(b1.intersects(b3)) self.assertTrue(u in b3) self.assertTrue(b3.contains(u)) b4 = Box.fromDegrees(200, 10, 300, 20) self.assertTrue(b1.isDisjointFrom(b4)) r = b1.relate(LonLat.fromDegrees(135, 10)) self.assertEqual(r, CONTAINS) r = b4.relate(b1) self.assertEqual(r, DISJOINT)
def testConstruction(self): v = Vector3d(1, 1, 1) u = UnitVector3d.orthogonalTo(v) self.assertAlmostEqual(u.dot(v), 0.0, places=15) u = UnitVector3d(1, 1, 1) self.assertEqual(u, UnitVector3d(Vector3d(1, 1, 1))) self.assertAlmostEqual(u.x(), math.sqrt(3.0) / 3.0, places=15) self.assertAlmostEqual(u.y(), math.sqrt(3.0) / 3.0, places=15) self.assertAlmostEqual(u.z(), math.sqrt(3.0) / 3.0, places=15) u = UnitVector3d(Angle.fromDegrees(45), Angle.fromDegrees(45)) self.assertEqual(u, UnitVector3d(LonLat.fromDegrees(45, 45))) self.assertAlmostEqual(u.x(), 0.5, places=15) self.assertAlmostEqual(u.y(), 0.5, places=15) self.assertAlmostEqual(u.z(), 0.5 * math.sqrt(2.0), places=15) u = UnitVector3d.northFrom(u.asVector3d()) w = UnitVector3d(LonLat.fromDegrees(225, 45)) self.assertAlmostEqual(u.x(), w.x(), places=15) self.assertAlmostEqual(u.y(), w.y(), places=15) self.assertAlmostEqual(u.z(), w.z(), places=15)
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 test_expanding_and_clipping(self): a = Box.fromDegrees(0, 0, 10, 10) b = (a.expandedTo(LonLat.fromDegrees(20, 20)).expandedTo( Box.fromDegrees(0, 0, 30, 10)).clippedTo( Box.fromDegrees(10, 10, 15, 15)).clippedTo(LonLat.fromDegrees(11, 11))) a.expandTo(LonLat.fromDegrees(20, 20)) a.expandTo(Box.fromDegrees(0, 0, 30, 10)) a.clipTo(Box.fromDegrees(10, 10, 15, 15)) a.clipTo(LonLat.fromDegrees(11, 11)) self.assertEqual(a, b) self.assertEqual(a, LonLat.fromDegrees(11, 11)) a.clipTo(LonLat.fromDegrees(0, 0)) self.assertTrue(a.isEmpty())
def testComparisonOperators(self): self.assertEqual(LonLat.fromDegrees(45, 45), LonLat.fromDegrees(45, 45)) self.assertNotEqual(LonLat.fromDegrees(0, 0), LonLat.fromDegrees(45, 45))
def testComparisonOperators(self): self.assertEqual(LonLat.fromDegrees(45, 45), LonLat.fromDegrees(45, 45)) self.assertNotEqual(LonLat.fromDegrees(0, 0), LonLat.fromDegrees(45, 45))
def in_region(obj: Any) -> bool: lonLat = LonLat.fromDegrees(obj['ra'], obj['decl']) dir_obj = UnitVector3d(lonLat) return region.contains(dir_obj)