orthodrome
¶

class
Loc
(lat, lon)[source]¶ Simple location representation.
Attrib lat: Latitude degree Attrib lon: Longitude degree

clip
(x, mi, ma)[source]¶ Clip values of an array.
Parameters:  x (
numpy.ndarray
) – Continunous data to be clipped  mi (float) – Clip minimum
 ma (float) – Clip maximum
Returns: Clipped data
Return type:  x (

wrap
(x, mi, ma)[source]¶ Wrapping continuous data to fundamental phase values.
Parameters:  x (
numpy.ndarray
) – Continunous data to be wrapped  mi (float) – Minimum value of wrapped data
 ma (float) – Maximum value of wrapped data
Returns: Wrapped data
Return type:  x (

cosdelta
(*args)[source]¶ Cosine of the angular distance between two points
a
andb
on a sphere.This function (find implementation below) returns the cosine of the distance angle ‘delta’ between two points
a
andb
, coordinates of which are expected to be given in geographical coordinates and in degrees. For numerical stability a maximum of 1.0 is enforced.Parameters:  a (
pyrocko.orthodrome.Loc
) – Location point A  b (
pyrocko.orthodrome.Loc
) – Location point B
Returns: cosdelta
Return type:  a (

cosdelta_numpy
(a_lats, a_lons, b_lats, b_lons)[source]¶ Cosine of the angular distance between two points
a
andb
on a sphere.This function returns the cosines of the distance angles delta between two points
a
andb
given asnumpy.ndarray
. The coordinates are expected to be given in geographical coordinates and in degrees. For numerical stability a maximum of1.0
is enforced.Please find the details of the implementation in the documentation of the function
pyrocko.orthodrome.cosdelta()
above.Parameters:  a_lats (
numpy.ndarray
) – Latitudes (degree) point A  a_lons (
numpy.ndarray
) – Longitudes (degree) point A  b_lats (
numpy.ndarray
) – Latitudes (degree) point B  b_lons (
numpy.ndarray
,(N)
) – Longitudes (degree) point B
Returns: cosdelta
 a_lats (

azimuth
(*args)[source]¶ Azimuth calculation.
This function (find implementation below) returns azimuth … between points
a
andb
, coordinates of which are expected to be given in geographical coordinates and in degrees.Parameters:  a (
pyrocko.orthodrome.Loc
) – Location point A  b (
pyrocko.orthodrome.Loc
) – Location point B
Returns: Azimuth in degree
 a (

azimuth_numpy
(a_lats, a_lons, b_lats, b_lons, _cosdelta=None)[source]¶ Calculation of the azimuth (track angle) from a location A towards B.
This function returns azimuths (track angles) from locations A towards B given in
numpy.ndarray
. Coordinates are expected to be given in geographical coordinates and in degrees.Please find the details of the implementation in the documentation of the function
pyrocko.orthodrome.azimuth()
.Parameters:  a_lats (
numpy.ndarray
,(N)
) – Latitudes (degree) point A  a_lons (
numpy.ndarray
,(N)
) – Longitudes (degree) point A  b_lats (
numpy.ndarray
,(N)
) – Latitudes (degree) point B  b_lons (
numpy.ndarray
,(N)
) – Longitudes (degree) point B
Returns: Azimuths in degrees
Return type: numpy.ndarray
,(N)
 a_lats (

azidist_numpy
(*args)[source]¶ Calculation of the azimuth (track angle) and the distance from locations A towards B on a sphere.
The assisting functions used are
pyrocko.orthodrome.cosdelta()
andpyrocko.orthodrome.azimuth()
Parameters:  a_lats (
numpy.ndarray
,(N)
) – Latitudes (degree) point A  a_lons (
numpy.ndarray
,(N)
) – Longitudes (degree) point A  b_lats (
numpy.ndarray
,(N)
) – Latitudes (degree) point B  b_lons (
numpy.ndarray
,(N)
) – Longitudes (degree) point B
Returns: Azimuths in degrees, distances in degrees
Return type: numpy.ndarray
,(2xN)
 a_lats (

distance_accurate50m
(*args, **kwargs)[source]¶ Accurate distance calculation based on a spheroid of rotation.
Function returns distance in meter between points A and B, coordinates of which must be given in geographical coordinates and in degrees. The returned distance should be accurate to 50 m using WGS84. Values for the Earth’s equator radius and the Earth’s oblateness (
f_oblate
) are defined in the pyrocko configuration filepyrocko.config
.From wikipedia (http://de.wikipedia.org/wiki/Orthodrome), based on:
Meeus, J.: Astronomical Algorithms, S 85, WillmannBell, Richmond 2000 (2nd ed., 2nd printing), ISBN 0943396611
The sphericalearth distance D between A and B, can be given with:
The oblateness of the Earth requires some correction with correction factors h1 and h2:
Parameters:  a (
pyrocko.orthodrome.Loc
) – Location point A  b (
pyrocko.orthodrome.Loc
) – Location point B
Returns: Distance in meter
Return type:  a (

distance_accurate50m_numpy
(a_lats, a_lons, b_lats, b_lons, implementation='c')[source]¶ Accurate distance calculation based on a spheroid of rotation.
Function returns distance in meter between points
a
andb
, coordinates of which must be given in geographical coordinates and in degrees. The returned distance should be accurate to 50 m using WGS84. Values for the Earth’s equator radius and the Earth’s oblateness (f_oblate
) are defined in the pyrocko configuration filepyrocko.config
.From wikipedia (http://de.wikipedia.org/wiki/Orthodrome), based on:
Meeus, J.: Astronomical Algorithms, S 85, WillmannBell, Richmond 2000 (2nd ed., 2nd printing), ISBN 0943396611
The sphericalearth distance
D
betweena
andb
, can be given with:The oblateness of the Earth requires some correction with correction factors
h1
andh2
:Parameters:  a_lats (
numpy.ndarray
,(N)
) – Latitudes (degree) point A  a_lons (
numpy.ndarray
,(N)
) – Longitudes (degree) point A  b_lats (
numpy.ndarray
,(N)
) – Latitudes (degree) point B  b_lons (
numpy.ndarray
,(N)
) – Longitudes (degree) point B
Returns: Distances in meter
Return type: numpy.ndarray
,(N)
 a_lats (

ne_to_latlon
(lat0, lon0, north_m, east_m)[source]¶ Transform local cartesian coordinates to latitude and longitude.
From east and north coordinates (
x
andy
coordinatenumpy.ndarray
) relative to a reference differences in longitude and latitude are calculated, which are effectively changes in azimuth and distance, respectively:The projection used preserves the azimuths of the input points.
Parameters:  lat0 (float) – Latitude origin of the cartesian coordinate system.
 lon0 (float) – Longitude origin of the cartesian coordinate system.
 north_m (
numpy.ndarray
,(N)
) – Northing distances from origin in meters.  east_m (
numpy.ndarray
,(N)
) – Easting distances from origin in meters.
Returns: Array with latitudes and longitudes
Return type: numpy.ndarray
,(2xN)

azidist_to_latlon_rad
(lat0, lon0, azimuth_rad, distance_rad)[source]¶ Absolute latitudes and longitudes are calculated from relative changes.
For numerical stability a range between of
1.0
and1.0
is enforced forc
andalpha
.Parameters:  lat0 (float) – Latitude origin of the cartesian coordinate system.
 lon0 (float) – Longitude origin of the cartesian coordinate system.
 distance_rad (
numpy.ndarray
,(N)
) – Distances from origin in radians.  azimuth_rad (
numpy.ndarray
,(N)
) – Azimuth from radians.
Returns: Array with latitudes and longitudes
Return type: numpy.ndarray
,(2xN)

ne_to_latlon_alternative_method
(lat0, lon0, north_m, east_m)[source]¶ Transform local cartesian coordinates to latitude and longitude.
Like
pyrocko.orthodrome.ne_to_latlon()
, but this method (implementation below), although it should be numerically more stable, suffers problems at points which are across the pole as seen from the cartesian origin.Parameters:  lat0 (float) – Latitude origin of the cartesian coordinate system.
 lon0 (float) – Longitude origin of the cartesian coordinate system.
 north_m (
numpy.ndarray
,(N)
) – Northing distances from origin in meters.  east_m (
numpy.ndarray
,(N)
) – Easting distances from origin in meters.
Returns: Array with latitudes and longitudes
Return type: numpy.ndarray
,(2xN)

latlon_to_ne
(*args)[source]¶ Relative cartesian coordinates with respect to a reference location.
For two locations, a reference location A and another location B, given in geographical coordinates in degrees, the corresponding cartesian coordinates are calculated. Assisting functions are
pyrocko.orthodrome.azimuth()
andpyrocko.orthodrome.distance_accurate50m()
.Parameters:  refloc (
pyrocko.orthodrome.Loc
) – Location reference point  loc (
pyrocko.orthodrome.Loc
) – Location of interest
Returns: Northing and easting from refloc to location
Return type:  refloc (

latlon_to_ne_numpy
(lat0, lon0, lat, lon)[source]¶ Relative cartesian coordinates with respect to a reference location.
For two locations, a reference location (
lat0
,lon0
) and another location B, given in geographical coordinates in degrees, the corresponding cartesian coordinates are calculated. Assisting functions areazimuth()
anddistance_accurate50m()
.Parameters:  lat0 – reference location latitude
 lon0 – reference location longitude
 lat – absolute location latitude
 lon – absolute location longitude
Returns: (n, e)
: relative north and east positionsReturn type: numpy.ndarray
,(2xN)
Implemented formulations:

positive_region
(region)[source]¶ Normalize parameterization of a rectangular geographical region.
Parameters: region – (west, east, south, north)
Returns: (west, east, south, north)
, wherewest <= east
and wherewest
andeast
are in the range[180., 180.+360.[

points_in_region
(p, region)[source]¶ Check what points are contained in a rectangular geographical region.
Parameters:  p – NumPy array of shape
(N, 2)
where each row is a(lat, lon)
pair [deg]  region –
(west, east, south, north)
[deg]
Returns: NumPy array of shape
(N)
, typebool
 p – NumPy array of shape

point_in_region
(p, region)[source]¶ Check if a point is contained in a rectangular geographical region.
Parameters:  p –
(lat, lon)
[deg]  region –
(west, east, south, north)
[deg]
Returns: bool
 p –

radius_to_region
(lat, lon, radius)[source]¶ Get a rectangular region which fully contains a given circular region.
Parameters:  lat,lon – center of circular region [deg]
 radius – radius of circular region [m]
Returns: rectangular region as
(east, west, south, north)
[deg]

geographic_midpoint
(lats, lons, weights=None)[source]¶ Calculate geographic midpoints by finding the center of gravity.
This method suffers from instabilities if points are centered around the poles.
Parameters:  lats (
numpy.ndarray
,(N)
) – array of latitudes  lons (
numpy.ndarray
,(N)
) – array of longitudes  weights (
numpy.ndarray
,(N)
) – array weighting factors (optional)
Returns: Latitudes and longitudes of the modpoints
Return type: numpy.ndarray
,(2xN)
 lats (

geodetic_to_ecef
(lat, lon, alt)[source]¶ Convert geodetic coordinates to EarthCentered, EarthFixed (ECEF) Cartesian coordinates. [3] [4]
Parameters: Returns: ECEF Cartesian coordinates (X, Y, Z) in [m].
Return type: [3] https://en.wikipedia.org/wiki/ECEF [4] https://en.wikipedia.org/wiki/Geographic_coordinate_conversion #From_geodetic_to_ECEF_coordinates

ecef_to_geodetic
(X, Y, Z)[source]¶ Convert EarthCentered, EarthFixed (ECEF) Cartesian coordinates to geodetic coordinates (Ferrari’s solution).
Parameters: Y, Z (X,) – Cartesian coordinates in ECEF system in [m]. Returns: Geodetic coordinates (lat, lon, alt). Latitude and longitude are in [deg] and altitude is in [m] (positive for points outside the geoid). Return type: tuple, float See also
https://en.wikipedia.org/wiki/Geographic_coordinate_conversion #The_application_of_Ferrari.27s_solution

contains_points
(polygon, points)[source]¶ Test which points are inside polygon on a sphere.
Parameters:  polygon (
numpy.ndarray
of shape (N, 2), second index 0=lat, 1=lon) – Point coordinates defining the polygon [deg].  points (
numpy.ndarray
of shape (N, 2), second index 0=lat, 1=lon) – Coordinates of points to test [deg].
Returns: Boolean mask array.
Return type: numpy.ndarray
of shape (N,)The inside of the polygon is defined as the area which is to the left hand side of an observer walking the polygon line, points in order, on the sphere. Lines between the polygon points are treated as great circle paths. The polygon may be arbitrarily complex, as long as it does not have any crossings or thin parts with zero width. The polygon may contain the poles and is allowed to wrap around the sphere multiple times.
The algorithm works by consecutive cutting of the polygon into (almost) hemispheres and subsequent Gnomonic projections to perform the pointinpolygon tests on a 2D plane.
 polygon (

contains_point
(polygon, point)[source]¶ Test if point is inside polygon on a sphere.
Parameters:  polygon (
numpy.ndarray
of shape (N, 2), second index 0=lat, 1=lon) – Point coordinates defining the polygon [deg].  point – Coordinates
(lat, lon)
of point to test [deg].
Convenience wrapper to
contains_points()
to test a single point. polygon (