def testOffset(self):
     """Test offset, angularSeparation and orientationTo for offsets over a wide range of angles
     """
     for fromPolarAng in (-87.1, -25.5, 0.43, 36.7, 87.0):
         for fromEquatAng in (0, 41.0): # should not matter
             fromCoord = Coord(fromEquatAng, fromPolarAng)
             for fromOrient in (-89.9, -45.0, 0.01, 12.5, 89.0, 90.0):
                 for dist in (0.0001, 0.01, 0.13, 5.73):
                     sideA = 90.0 - fromPolarAng
                     angB = 90.0 - fromOrient
                     sideC = dist
                     unknownAng, angA, sideB, angC = angSideAng(sideA, angB, sideC)
                     self.assertFalse(unknownAng)
                     predEquatAng = fromEquatAng + angC
                     predPolarAng = 90 - sideB
                     predAng = angA - 90
                     toCoord, toOrient = fromCoord.offset(fromOrient, dist)
                     atPole, toEquatAng, toPolarAng = toCoord.getSphPos()
                     places = 7
                     self.assertAlmostEqual(toEquatAng, predEquatAng, places=places)
                     self.assertAlmostEqual(toPolarAng, predPolarAng, places=places)
                     self.assertAlmostEqual(toOrient, predAng, places=places)
                     fromCoord = Coord(fromEquatAng, fromPolarAng)
                     toCoord = Coord(toEquatAng, toPolarAng)
                     self.assertAlmostEqual(dist, fromCoord.angularSeparation(toCoord))
                     self.assertAlmostEqual(fromOrient, fromCoord.orientationTo(toCoord))
                     self.assertAlmostEqual(toOrient, wrapNear(180 + toCoord.orientationTo(fromCoord), toOrient))
Beispiel #2
0
    def testOffsetSmall(self):
        """Test offset, angularSeparation and orientationTo for small offsets not too near the pole
        
        In this regime delta-long = dist along long / cos(lat) is a reasonable approximation
        but I have no simple way to compute toOrient, except if dist very small then toOrient = fromOrient
        """
        for fromPolarAng in (-40.0, 0.43, 36.7):
            cosPolarAng = cosd(fromPolarAng)
            for fromEquatAng in (0, 41.0):  # should not matter
                fromCoord = Coord(fromEquatAng, fromPolarAng)
                for fromOrient in (-90, -72, -45.0, -30, 0.01, 12.5, 31, 47,
                                   56, 68, 89):
                    cosFromOrient = cosd(fromOrient)
                    sinFromOrient = sind(fromOrient)
                    for dist in (0, 1e-12, 1e-11, 1e-10, 1e-9, 1e-8, 1e-7,
                                 1e-5, 0.001, 0.01, 0.13):
                        predEquatAng = fromEquatAng + (dist * cosFromOrient /
                                                       cosPolarAng)
                        predPolarAng = fromPolarAng + (dist * sinFromOrient)

                        toCoord, toOrient = fromCoord.offset(fromOrient, dist)
                        atPole, toEquatAng, toPolarAng = toCoord.getSphPos()
                        if abs(dist) > 0.1:
                            places = 3
                        else:
                            places = 5
                        if abs(dist) < 0.0001:
                            orientPlaces = 4
                        else:
                            orientPlaces = 7
                        self.assertAlmostEqual(toEquatAng,
                                               predEquatAng,
                                               places=places)
                        self.assertAlmostEqual(toPolarAng,
                                               predPolarAng,
                                               places=places)
                        fromCoord = Coord(fromEquatAng, fromPolarAng)
                        toCoord = Coord(toEquatAng, toPolarAng)
                        self.assertAlmostEqual(
                            dist, fromCoord.angularSeparation(toCoord))
                        predFromOrient = fromCoord.orientationTo(toCoord)
                        if numpy.isfinite(predFromOrient):
                            self.assertAlmostEqual(fromOrient,
                                                   predFromOrient,
                                                   places=orientPlaces)
                            self.assertAlmostEqual(
                                toOrient,
                                wrapNear(
                                    180 + toCoord.orientationTo(fromCoord),
                                    toOrient),
                                places=orientPlaces)
                        else:
                            self.assertLess(dist, 1e-7)
                            self.assertAlmostEqual(fromEquatAng, toEquatAng)
                            self.assertAlmostEqual(fromPolarAng, toPolarAng)
                            self.assertAlmostEqual(fromOrient, toOrient)
    def testOffsetSmall(self):
        """Test offset, angularSeparation and orientationTo for small offsets not too near the pole
        
        In this regime delta-long = dist along long / cos(lat) is a reasonable approximation
        but I have no simple way to compute toOrient, except if dist very small then toOrient = fromOrient
        """
        for fromPolarAng in (-40.0, 0.43, 36.7):
            cosPolarAng = cosd(fromPolarAng)
            for fromEquatAng in (0, 41.0): # should not matter
                fromCoord = Coord(fromEquatAng, fromPolarAng)
                for fromOrient in (-90, -72, -45.0, -30, 0.01, 12.5, 31, 47, 56, 68, 89):
                    cosFromOrient = cosd(fromOrient)
                    sinFromOrient = sind(fromOrient)
                    for dist in (0, 1e-12, 1e-11, 1e-10, 1e-9, 1e-8, 1e-7, 1e-5, 0.001, 0.01, 0.13):
                        predEquatAng = fromEquatAng + (dist * cosFromOrient / cosPolarAng)
                        predPolarAng = fromPolarAng + (dist * sinFromOrient)

                        toCoord, toOrient = fromCoord.offset(fromOrient, dist)
                        atPole, toEquatAng, toPolarAng = toCoord.getSphPos()
                        if abs(dist) > 0.1:
                            places = 3
                        else:
                            places = 5
                        if abs(dist) < 0.0001:
                            orientPlaces = 4
                        else:
                            orientPlaces = 7
                        self.assertAlmostEqual(toEquatAng, predEquatAng, places=places)
                        self.assertAlmostEqual(toPolarAng, predPolarAng, places=places)
                        fromCoord = Coord(fromEquatAng, fromPolarAng)
                        toCoord = Coord(toEquatAng, toPolarAng)
                        self.assertAlmostEqual(dist, fromCoord.angularSeparation(toCoord))
                        predFromOrient = fromCoord.orientationTo(toCoord)
                        if numpy.isfinite(predFromOrient):
                            self.assertAlmostEqual(fromOrient, predFromOrient, places=orientPlaces)
                            self.assertAlmostEqual(toOrient, wrapNear(180 + toCoord.orientationTo(fromCoord), toOrient), places=orientPlaces)
                        else:
                            self.assertLess(dist, 1e-7)
                            self.assertAlmostEqual(fromEquatAng, toEquatAng)
                            self.assertAlmostEqual(fromPolarAng, toPolarAng)
                            self.assertAlmostEqual(fromOrient, toOrient)
Beispiel #4
0
 def testOffset(self):
     """Test offset, angularSeparation and orientationTo for offsets over a wide range of angles
     """
     for fromPolarAng in (-87.1, -25.5, 0.43, 36.7, 87.0):
         for fromEquatAng in (0, 41.0):  # should not matter
             fromCoord = Coord(fromEquatAng, fromPolarAng)
             for fromOrient in (-89.9, -45.0, 0.01, 12.5, 89.0, 90.0):
                 for dist in (0.0001, 0.01, 0.13, 5.73):
                     sideA = 90.0 - fromPolarAng
                     angB = 90.0 - fromOrient
                     sideC = dist
                     unknownAng, angA, sideB, angC = angSideAng(
                         sideA, angB, sideC)
                     self.assertFalse(unknownAng)
                     predEquatAng = fromEquatAng + angC
                     predPolarAng = 90 - sideB
                     predAng = angA - 90
                     toCoord, toOrient = fromCoord.offset(fromOrient, dist)
                     atPole, toEquatAng, toPolarAng = toCoord.getSphPos()
                     places = 7
                     self.assertAlmostEqual(toEquatAng,
                                            predEquatAng,
                                            places=places)
                     self.assertAlmostEqual(toPolarAng,
                                            predPolarAng,
                                            places=places)
                     self.assertAlmostEqual(toOrient,
                                            predAng,
                                            places=places)
                     fromCoord = Coord(fromEquatAng, fromPolarAng)
                     toCoord = Coord(toEquatAng, toPolarAng)
                     self.assertAlmostEqual(
                         dist, fromCoord.angularSeparation(toCoord))
                     self.assertAlmostEqual(
                         fromOrient, fromCoord.orientationTo(toCoord))
                     self.assertAlmostEqual(
                         toOrient,
                         wrapNear(180 + toCoord.orientationTo(fromCoord),
                                  toOrient))