Пример #1
0
    def testVector3dConstructor(self):
        # test poles
        for z in (-11.3, -1.1, 0.1, 2.5):  # arbitrary non-zero values
            sp = SpherePoint(lsst.sphgeom.Vector3d(0.0, 0.0, z))
            self.assertTrue(sp.atPole())
            self.assertEqual(sp.getLongitude().asRadians(), 0.0)
            if z < 0:
                self.assertAnglesAlmostEqual(sp.getLatitude(), -90 * degrees)
            else:
                self.assertAnglesAlmostEqual(sp.getLatitude(), 90 * degrees)

        spx = SpherePoint(lsst.sphgeom.Vector3d(11.1, 0.0, 0.0))
        self.assertAnglesAlmostEqual(spx.getLongitude(), 0.0 * degrees)
        self.assertAnglesAlmostEqual(spx.getLatitude(), 0.0 * degrees)

        spy = SpherePoint(lsst.sphgeom.Vector3d(0.0, 234234.5, 0.0))
        self.assertAnglesAlmostEqual(spy.getLongitude(), 90.0 * degrees)
        self.assertAnglesAlmostEqual(spy.getLatitude(), 0.0 * degrees)

        spxy = SpherePoint(lsst.sphgeom.Vector3d(7.5, -7.5, 0.0))
        self.assertAnglesAlmostEqual(spxy.getLongitude(), -45.0 * degrees)
        self.assertAnglesAlmostEqual(spxy.getLatitude(), 0.0 * degrees)

        spxz = SpherePoint(lsst.sphgeom.Vector3d(100.0, 0.0, -100.0))
        self.assertAnglesAlmostEqual(spxz.getLongitude(), 0.0 * degrees)
        self.assertAnglesAlmostEqual(spxz.getLatitude(), -45.0 * degrees)

        # Only one singularity: a vector of all zeros
        with self.assertRaises(pexEx.InvalidParameterError):
            SpherePoint(lsst.sphgeom.Vector3d(0.0, 0.0, 0.0))
Пример #2
0
    def testVector3dConstructor(self):
        # test poles
        for z in (-11.3, -1.1, 0.1, 2.5):  # arbitrary non-zero values
            sp = SpherePoint(lsst.sphgeom.Vector3d(0.0, 0.0, z))
            self.assertTrue(sp.atPole())
            self.assertEqual(sp.getLongitude().asRadians(), 0.0)
            if z < 0:
                self.assertAnglesAlmostEqual(sp.getLatitude(), -90 * degrees)
            else:
                self.assertAnglesAlmostEqual(sp.getLatitude(), 90 * degrees)

        spx = SpherePoint(lsst.sphgeom.Vector3d(11.1, 0.0, 0.0))
        self.assertAnglesAlmostEqual(spx.getLongitude(), 0.0 * degrees)
        self.assertAnglesAlmostEqual(spx.getLatitude(), 0.0 * degrees)

        spy = SpherePoint(lsst.sphgeom.Vector3d(0.0, 234234.5, 0.0))
        self.assertAnglesAlmostEqual(spy.getLongitude(), 90.0 * degrees)
        self.assertAnglesAlmostEqual(spy.getLatitude(), 0.0 * degrees)

        spxy = SpherePoint(lsst.sphgeom.Vector3d(7.5, -7.5, 0.0))
        self.assertAnglesAlmostEqual(spxy.getLongitude(), -45.0 * degrees)
        self.assertAnglesAlmostEqual(spxy.getLatitude(), 0.0 * degrees)

        spxz = SpherePoint(lsst.sphgeom.Vector3d(100.0, 0.0, -100.0))
        self.assertAnglesAlmostEqual(spxz.getLongitude(), 0.0 * degrees)
        self.assertAnglesAlmostEqual(spxz.getLatitude(), -45.0 * degrees)

        # Only one singularity: a vector of all zeros
        with self.assertRaises(pexEx.InvalidParameterError):
            SpherePoint(lsst.sphgeom.Vector3d(0.0, 0.0, 0.0))
Пример #3
0
 def testBearingToValueSameLongitude(self):
     """Test that bearingTo() returns +/- 90 for two points on the same longitude
     """
     for longDeg in (0, 55, 270):
         for lat0Deg in (-90, -5, 0, 44, 90):
             sp0 = SpherePoint(longDeg, lat0Deg, degrees)
             for lat1Deg in (-90, -41, 1, 41, 90):
                 if lat0Deg == lat1Deg:
                     continue
                 sp1 = SpherePoint(longDeg, lat1Deg, degrees)
                 if sp0.atPole() and sp1.atPole():
                     # the points are at opposite poles; any bearing may be returned
                     continue
                 bearing = sp0.bearingTo(sp1)
                 if lat1Deg > lat0Deg:
                     self.assertAnglesAlmostEqual(bearing, 90 * degrees)
                 else:
                     self.assertAnglesAlmostEqual(bearing, -90 * degrees)
Пример #4
0
 def testBearingToValueSameLongitude(self):
     """Test that bearingTo() returns +/- 90 for two points on the same longitude
     """
     for longDeg in (0, 55, 270):
         for lat0Deg in (-90, -5, 0, 44, 90):
             sp0 = SpherePoint(longDeg, lat0Deg, degrees)
             for lat1Deg in (-90, -41, 1, 41, 90):
                 if lat0Deg == lat1Deg:
                     continue
                 sp1 = SpherePoint(longDeg, lat1Deg, degrees)
                 if sp0.atPole() and sp1.atPole():
                     # the points are at opposite poles; any bearing may be returned
                     continue
                 bearing = sp0.bearingTo(sp1)
                 if lat1Deg > lat0Deg:
                     self.assertAnglesAlmostEqual(bearing, 90 * degrees)
                 else:
                     self.assertAnglesAlmostEqual(bearing, -90 * degrees)
Пример #5
0
    def testOffsetValue(self):
        """Test if offset() returns the expected value.
        """
        # This should cover arcs over the meridian, across the pole, etc.
        for lon1, lat1 in self._dataset:
            point1 = SpherePoint(lon1, lat1)
            for lon2, lat2 in self._dataset:
                if lon1 == lon2 and lat1 == lat2:
                    continue
                point2 = SpherePoint(lon2, lat2)
                bearing = point1.bearingTo(point2)
                distance = point1.separation(point2)

                # offsetting point1 by bearing and distance should produce the same result as point2
                newPoint = point1.offset(bearing, distance)
                self.assertIsInstance(newPoint, SpherePoint)
                self.assertSpherePointsAlmostEqual(point2, newPoint)
                if newPoint.atPole():
                    self.assertAnglesAlmostEqual(newPoint.getLongitude(), 0*degrees)

                # measuring the separation and bearing from point1 to the new point
                # should produce the requested separation and bearing
                measuredDistance = point1.separation(newPoint)
                self.assertAnglesAlmostEqual(measuredDistance, distance)
                if abs(measuredDistance.asDegrees() - 180) > 1e-5:
                    # The two points are not opposite each other on the sphere,
                    # so the bearing has a well defined value
                    measuredBearing = point1.bearingTo(newPoint)
                    self.assertAnglesAlmostEqual(measuredBearing, bearing)

                # offset by a negative amount in the opposite direction should produce the same result
                newPoint2 = point1.offset(bearing + 180 * degrees, -distance)
                self.assertIsInstance(newPoint2, SpherePoint)
                # check angular separation (longitude is checked below)
                self.assertSpherePointsAlmostEqual(newPoint, newPoint2)

                if point1.isFinite() and point2.isFinite():
                    if not point2.atPole():
                        self.assertAnglesAlmostEqual(
                            point2.getLongitude(), newPoint.getLongitude())
                        self.assertAnglesAlmostEqual(
                            point2.getLongitude(), newPoint2.getLongitude())
                    self.assertAnglesAlmostEqual(
                        point2.getLatitude(), newPoint.getLatitude())
                    self.assertAnglesAlmostEqual(
                        point2.getLatitude(), newPoint2.getLatitude())
                else:
                    self.assertTrue(math.isnan(
                        newPoint.getLongitude().asRadians()))
                    self.assertTrue(math.isnan(
                        newPoint2.getLongitude().asRadians()))
                    self.assertTrue(math.isnan(
                        newPoint.getLatitude().asRadians()))
                    self.assertTrue(math.isnan(
                        newPoint2.getLatitude().asRadians()))

        # Test precision near the poles
        lon = 123.0*degrees
        almostPole = SpherePoint(lon, self.nextDown(90.0*degrees))
        goSouth = almostPole.offset(-90.0*degrees, 90.0*degrees)
        self.assertAnglesAlmostEqual(lon, goSouth.getLongitude())
        self.assertAnglesAlmostEqual(0.0*degrees, goSouth.getLatitude())
        goEast = almostPole.offset(0.0*degrees, 90.0*degrees)
        self.assertAnglesAlmostEqual(lon + 90.0*degrees, goEast.getLongitude())
        self.assertAnglesAlmostEqual(0.0*degrees, goEast.getLatitude())
Пример #6
0
    def testOffsetValue(self):
        """Test if offset() returns the expected value.
        """
        # This should cover arcs over the meridian, across the pole, etc.
        for lon1, lat1 in self._dataset:
            point1 = SpherePoint(lon1, lat1)
            for lon2, lat2 in self._dataset:
                if lon1 == lon2 and lat1 == lat2:
                    continue
                point2 = SpherePoint(lon2, lat2)
                bearing = point1.bearingTo(point2)
                distance = point1.separation(point2)

                # offsetting point1 by bearing and distance should produce the same result as point2
                newPoint = point1.offset(bearing, distance)
                self.assertIsInstance(newPoint, SpherePoint)
                self.assertSpherePointsAlmostEqual(point2, newPoint)
                if newPoint.atPole():
                    self.assertAnglesAlmostEqual(newPoint.getLongitude(), 0*degrees)

                # measuring the separation and bearing from point1 to the new point
                # should produce the requested separation and bearing
                measuredDistance = point1.separation(newPoint)
                self.assertAnglesAlmostEqual(measuredDistance, distance)
                if abs(measuredDistance.asDegrees() - 180) > 1e-5:
                    # The two points are not opposite each other on the sphere,
                    # so the bearing has a well defined value
                    measuredBearing = point1.bearingTo(newPoint)
                    self.assertAnglesAlmostEqual(measuredBearing, bearing)

                # offset by a negative amount in the opposite direction should produce the same result
                newPoint2 = point1.offset(bearing + 180 * degrees, -distance)
                self.assertIsInstance(newPoint2, SpherePoint)
                # check angular separation (longitude is checked below)
                self.assertSpherePointsAlmostEqual(newPoint, newPoint2)

                if point1.isFinite() and point2.isFinite():
                    if not point2.atPole():
                        self.assertAnglesAlmostEqual(
                            point2.getLongitude(), newPoint.getLongitude())
                        self.assertAnglesAlmostEqual(
                            point2.getLongitude(), newPoint2.getLongitude())
                    self.assertAnglesAlmostEqual(
                        point2.getLatitude(), newPoint.getLatitude())
                    self.assertAnglesAlmostEqual(
                        point2.getLatitude(), newPoint2.getLatitude())
                else:
                    self.assertTrue(math.isnan(
                        newPoint.getLongitude().asRadians()))
                    self.assertTrue(math.isnan(
                        newPoint2.getLongitude().asRadians()))
                    self.assertTrue(math.isnan(
                        newPoint.getLatitude().asRadians()))
                    self.assertTrue(math.isnan(
                        newPoint2.getLatitude().asRadians()))

        # Test precision near the poles
        lon = 123.0*degrees
        almostPole = SpherePoint(lon, self.nextDown(90.0*degrees))
        goSouth = almostPole.offset(-90.0*degrees, 90.0*degrees)
        self.assertAnglesAlmostEqual(lon, goSouth.getLongitude())
        self.assertAnglesAlmostEqual(0.0*degrees, goSouth.getLatitude())
        goEast = almostPole.offset(0.0*degrees, 90.0*degrees)
        self.assertAnglesAlmostEqual(lon + 90.0*degrees, goEast.getLongitude())
        self.assertAnglesAlmostEqual(0.0*degrees, goEast.getLatitude())