pyresample.spherical module
Some generalized spherical functions.
base type is a numpy array of size (n, 2) (2 for lon and lats)
- class pyresample.spherical.Arc(start, end)
Bases:
objectAn arc of the great circle between two points.
- __init__(start, end)
- angle(other_arc)
Oriented angle between two arcs.
- Returns:
Angle in radians. A straight line will be 0. A clockwise path will be a negative angle and counter-clockwise will be positive.
- get_next_intersection(arcs, known_inter=None)
Get the next intersection between the current arc and arcs.
- intersection(other_arc)
Return where, if the current arc and the other_arc intersect.
None is returned if there is not intersection. An arc is defined as the shortest tracks between two points.
- intersections(other_arc)
Give the two intersections of the greats circles defined by the current arc and other_arc.
- intersects(other_arc)
Check if the current arc and the other_arc intersect.
An arc is defined as the shortest tracks between two points.
- class pyresample.spherical.CCoordinate(cart)
Bases:
objectCartesian coordinates.
- __init__(cart)
- cross(point)
Get cross product with another vector.
The cross product of the same vector gives a zero vector.
- dot(point)
Get dot product with another vector.
- norm()
Get Euclidean norm of the vector.
- normalize(inplace=False)
Normalize the vector.
If self.cart == [0,0,0], norm=0, and cart becomes [nan, nan, nan]: Note that self.cart == [0,0,0] can occurs when computing: - the cross product of the same point. - the cross product between points lying at the equator. - the cross product between points lying at the poles.
- to_spherical()
Convert to SPoint/SMultiPoint object.
- class pyresample.spherical.SCoordinate(lon, lat)
Bases:
objectSpherical coordinates.
The
lonandlatcoordinates must be provided in radians.- __init__(lon, lat)
- cross2cart(point)
Compute the cross product, and convert to cartesian coordinates.
Note: - the cross product of the same point gives a zero vector. - the cross product between points lying at the equator gives a zero vector. - the cross product between points lying at the poles.
- distance(point)
Get distance using Vincenty formula.
The result must be multiplied by Earth radius to obtain distance in m or km.
- hdistance(point)
Get distance using Haversine formula.
The result must be multiplied by Earth radius to obtain distance in m or km.
- plot(ax=None, projection_crs=None, add_coastlines=True, add_gridlines=True, add_background=True, **plot_kwargs)
Plot the point(s) using Cartopy.
Assume vertices to be in radians.
- to_cart()
Convert to cartesian.
- property vertices
Return point(s) radians vertices in a ndarray of shape [n,2].
- property vertices_in_degrees
Return point(s) degrees vertices in a ndarray of shape [n,2].
- class pyresample.spherical.SphPolygon(vertices, radius=1)
Bases:
objectSpherical polygon.
Represents a polygon on a spherical geoid. Initialise with an ndarray of shape
[N, 2]where the first column contains longitudes and the second column contains latitudes. The units should be in radians. The inside of the polygon is defined by the vertices being defined clockwise around it.The optional second argument
radiusindicates the radius of the spherical geoid on which calculations occur.Initialise SphPolygon object.
- Parameters:
vertices (np.ndarray) – ndarray of shape
[N, 2]withNpoints describing a polygon clockwise. First column describes longitudes, second column describes latitudes. Units should be in radians.radius (optional, number) – Radius of spherical planet.
- __init__(vertices, radius=1)
Initialise SphPolygon object.
- Parameters:
vertices (np.ndarray) – ndarray of shape
[N, 2]withNpoints describing a polygon clockwise. First column describes longitudes, second column describes latitudes. Units should be in radians.radius (optional, number) – Radius of spherical planet.
- aedges()
Get generator over the edges, in arcs of Coordinates.
- area()
Find the area of a polygon.
The inside of the polygon is defined by having the vertices enumerated clockwise around it.
Uses the algorithm described in [bev1987].
[bev1987], Michael Bevis and Greg Cambareri, “Computing the area of a spherical polygon of arbitrary shape”, in Mathematical Geology, May 1987, Volume 19, Issue 4, pp 335-346.
Note: The article mixes up longitudes and latitudes in equation 3! Look at the fortran code appendix for the correct version.
The units are the square of the radius passed to the constructor. For example, to calculate the area in km² of a polygon near the equator of a spherical planet with a radius of 6371 km (similar to Earth):
>>> pol = SphPolygon(np.deg2rad(np.array([[0., 0.], [0., 1.], [1., 1.], [1., 0.]])), radius=6371) >>> print(pol.area()) 12363.997753690213
If SphPolygon was constructed without passing any units, the result has units of square radii (i.e., the polygon containing the entire planet would have area 4π).
- edges()
Get generator over the edges, in geographical coordinates.
- intersection(other)
Return the intersection of this and other polygon.
- inverse()
Return an inverse of the polygon.
- invert()
Invert the polygon.
- union(other)
Return the union of this and other polygon.
NB! If the two polygons do not overlap (they have nothing in common) None is returned.