How to use the pyresample.spherical_geometry.Coordinate function in pyresample

To help you get started, we’ve selected a few pyresample examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytroll / pyresample / test / test_spherical_geometry.py View on Github external
msg="this should be -pi/2")

        self.assertAlmostEqual(arc1.angle(arc3), math.pi,
                               msg="this should be pi")
        self.assertAlmostEqual(arc3.angle(arc1), math.pi,
                               msg="this should be pi")
        self.assertAlmostEqual(arc2.angle(arc4), math.pi,
                               msg="this should be pi")
        self.assertAlmostEqual(arc4.angle(arc2), math.pi,
                               msg="this should be pi")


        p5_ = Coordinate(base + 1, base + 1)
        p6_ = Coordinate(base + 1, base - 1)
        p7_ = Coordinate(base - 1, base - 1)
        p8_ = Coordinate(base - 1, base + 1)

        arc5 = Arc(p0_, p5_)
        arc6 = Arc(p0_, p6_)
        arc7 = Arc(p0_, p7_)
        arc8 = Arc(p0_, p8_)

        self.assertAlmostEqual(arc1.angle(arc5), math.pi / 4, 3,
                               msg="this should be pi/4")
        self.assertAlmostEqual(arc5.angle(arc2), math.pi / 4, 3,
                               msg="this should be pi/4")
        self.assertAlmostEqual(arc2.angle(arc6), math.pi / 4, 3,
                               msg="this should be pi/4")
        self.assertAlmostEqual(arc6.angle(arc3), math.pi / 4, 3,
                               msg="this should be pi/4")
        self.assertAlmostEqual(arc3.angle(arc7), math.pi / 4, 3,
                               msg="this should be pi/4")
github pytroll / pyresample / test / test_spherical_geometry.py View on Github external
point = Coordinate(0, 12)
        self.assertFalse(point in area)


        lons = np.array([[-179, 179], [-179, 179]])
        lats = np.array([[1, 1], [-1, -1]])
        area = geometry.SwathDefinition(lons, lats)

        point = Coordinate(180, 0)
        self.assertTrue(point in area)

        point = Coordinate(180, 12)
        self.assertFalse(point in area)

        point = Coordinate(-180, 12)
        self.assertFalse(point in area)

        self.assert_raises(ValueError, Coordinate, 0, 192)

        self.assert_raises(ValueError, Coordinate, 15, -91)

        # case of the north pole
        lons = np.array([[0, 90], [-90, 180]])
        lats = np.array([[89, 89], [89, 89]])
        area = geometry.SwathDefinition(lons, lats)

        point = Coordinate(90, 90)
        self.assertTrue(point in area)
github pytroll / pyresample / test / test_spherical_geometry.py View on Github external
def test_intersects(self):
        """Test if two arcs intersect.
        """
        p0_ = Coordinate(0, 0)
        p1_ = Coordinate(0, 1)
        p2_ = Coordinate(1, 0)
        p3_ = Coordinate(0, -1)
        p4_ = Coordinate(-1, 0)
        p5_ = Coordinate(1, 1)
        p6_ = Coordinate(1, -1)

        arc13 = Arc(p1_, p3_)
        arc24 = Arc(p2_, p4_)

        arc32 = Arc(p3_, p2_)
        arc41 = Arc(p4_, p1_)

        arc40 = Arc(p4_, p0_)
        arc56 = Arc(p5_, p6_)

        arc45 = Arc(p4_, p5_)
        arc02 = Arc(p0_, p2_)

        arc35 = Arc(p3_, p5_)
github pytroll / pyresample / test / test_spherical_geometry.py View on Github external
def test_intersects(self):
        """Test if two arcs intersect.
        """
        p0_ = Coordinate(0, 0)
        p1_ = Coordinate(0, 1)
        p2_ = Coordinate(1, 0)
        p3_ = Coordinate(0, -1)
        p4_ = Coordinate(-1, 0)
        p5_ = Coordinate(1, 1)
        p6_ = Coordinate(1, -1)

        arc13 = Arc(p1_, p3_)
        arc24 = Arc(p2_, p4_)

        arc32 = Arc(p3_, p2_)
        arc41 = Arc(p4_, p1_)

        arc40 = Arc(p4_, p0_)
        arc56 = Arc(p5_, p6_)

        arc45 = Arc(p4_, p5_)
        arc02 = Arc(p0_, p2_)
github pytroll / pyresample / test / test_spherical_geometry.py View on Github external
self.assertFalse(arc56.intersects(arc40))

        self.assertFalse(arc56.intersects(arc40))

        self.assertFalse(arc45.intersects(arc02))

        self.assertTrue(arc35.intersects(arc24))

        # case of the north pole

        p0_ = Coordinate(0, 90)
        p1_ = Coordinate(0, 89)
        p2_ = Coordinate(90, 89)
        p3_ = Coordinate(180, 89)
        p4_ = Coordinate(-90, 89)    
        p5_ = Coordinate(45, 89)
        p6_ = Coordinate(135, 89)

        arc13 = Arc(p1_, p3_)
        arc24 = Arc(p2_, p4_)

        arc32 = Arc(p3_, p2_)
        arc41 = Arc(p4_, p1_)

        arc40 = Arc(p4_, p0_)
        arc56 = Arc(p5_, p6_)

        arc45 = Arc(p4_, p5_)
        arc02 = Arc(p0_, p2_)

        arc35 = Arc(p3_, p5_)
github pytroll / pyresample / test / test_spherical_geometry.py View on Github external
msg="this should be pi/4")
        self.assertAlmostEqual(arc7.angle(arc4), math.pi / 4, 3,
                               msg="this should be pi/4")
        self.assertAlmostEqual(arc4.angle(arc8), math.pi / 4, 3,
                               msg="this should be pi/4")
        self.assertAlmostEqual(arc8.angle(arc1), math.pi / 4, 3,
                               msg="this should be pi/4")

        self.assertAlmostEqual(arc1.angle(arc6), 3 * math.pi / 4, 3,
                               msg="this should be 3pi/4")


        c0_ = Coordinate(180, 0)
        c1_ = Coordinate(180, 1)
        c2_ = Coordinate(-179, 0)
        c3_ = Coordinate(-180, -1)
        c4_ = Coordinate(179, 0)


        arc1 = Arc(c0_, c1_)
        arc2 = Arc(c0_, c2_)
        arc3 = Arc(c0_, c3_)
        arc4 = Arc(c0_, c4_)

        self.assertAlmostEqual(arc1.angle(arc2), math.pi / 2,
                               msg="this should be pi/2")
        self.assertAlmostEqual(arc2.angle(arc3), math.pi / 2,
                               msg="this should be pi/2")
        self.assertAlmostEqual(arc3.angle(arc4), math.pi / 2,
                               msg="this should be pi/2")
        self.assertAlmostEqual(arc4.angle(arc1), math.pi / 2,
                               msg="this should be pi/2")
github pytroll / pyresample / test / test_spherical_geometry.py View on Github external
def test_angle(self):
        """Testing the angle value between two arcs.
        """

        base = 0

        p0_ = Coordinate(base, base)
        p1_ = Coordinate(base, base + 1)
        p2_ = Coordinate(base + 1, base)
        p3_ = Coordinate(base, base - 1)
        p4_ = Coordinate(base - 1, base)

        arc1 = Arc(p0_, p1_)
        arc2 = Arc(p0_, p2_)
        arc3 = Arc(p0_, p3_)
        arc4 = Arc(p0_, p4_)

        self.assertAlmostEqual(arc1.angle(arc2), math.pi / 2,
                               msg="this should be pi/2")
        self.assertAlmostEqual(arc2.angle(arc3), math.pi / 2,
                               msg="this should be pi/2")
        self.assertAlmostEqual(arc3.angle(arc4), math.pi / 2,
                               msg="this should be pi/2")
        self.assertAlmostEqual(arc4.angle(arc1), math.pi / 2,
                               msg="this should be pi/2")
github pytroll / pyresample / test / test_spherical_geometry.py View on Github external
def test_inside(self):
        """Testing if a point is inside an area.
        """
        lons = np.array([[-11, 11], [-11, 11]])
        lats = np.array([[11, 11], [-11, -11]])
        area = geometry.SwathDefinition(lons, lats)
        
        point = Coordinate(0, 0)

        self.assertTrue(point in area)

        point = Coordinate(0, 12)
        self.assertFalse(point in area)


        lons = np.array([[-179, 179], [-179, 179]])
        lats = np.array([[1, 1], [-1, -1]])
        area = geometry.SwathDefinition(lons, lats)

        point = Coordinate(180, 0)
        self.assertTrue(point in area)

        point = Coordinate(180, 12)
        self.assertFalse(point in area)

        point = Coordinate(-180, 12)
        self.assertFalse(point in area)
github pytroll / pyresample / pyresample / spherical_geometry.py View on Github external
if other_arc.end.lon - other_arc.start.lon > math.pi:
            other_arc.end.lon -= 2 * math.pi
        if self.end.lon - self.start.lon < -math.pi:
            self.end.lon += 2 * math.pi
        if other_arc.end.lon - other_arc.start.lon < -math.pi:
            other_arc.end.lon += 2 * math.pi

        ea_ = self.start.cross2cart(self.end).normalize()
        eb_ = other_arc.start.cross2cart(other_arc.end).normalize()

        cross = ea_.cross(eb_)
        lat = math.atan2(cross.z__, math.sqrt(cross.x__ ** 2 + cross.y__ ** 2))
        lon = math.atan2(-cross.y__, cross.x__)

        return (Coordinate(math.degrees(lon), math.degrees(lat)),
                Coordinate(math.degrees(modpi(lon + math.pi)),
                           math.degrees(-lat)))
github pytroll / pyresample / pyresample / spherical_geometry.py View on Github external
def cross(self, point):
        """cross product with another vector.
        """
        x__ = self.y__ * point.z__ - self.z__ * point.y__
        y__ = self.z__ * point.x__ - self.x__ * point.z__
        z__ = self.x__ * point.y__ - self.y__ * point.x__

        return Coordinate(x__=x__, y__=y__, z__=z__)