API reference
earthcarekit.geo
Geospatial utilities for handling coordinates, coordinate transformations, distance calculation, and interpolation.
create_spherical_grid
Generate a spherical gird with regular, sinusoidal or gaussian latitudes and uniform or reduced longitudes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nlat
|
int
|
Number of latitude. |
required |
nlon
|
int | None
|
Nuber of longitudes at the equator. If None, set to |
None
|
reduced
|
bool
|
If True, reduces longitudes near poles using |
False
|
lat_spacing
|
regular or sinusoidal or gaussian
|
Method used to place latitudes. Defaults to "regular". |
'regular'
|
Returns:
| Name | Type | Description |
|---|---|---|
SphericalGrid |
SphericalGrid
|
A container storing |
SphericalGrid
|
|
|
SphericalGrid
|
|
|
SphericalGrid
|
|
|
SphericalGrid
|
|
|
SphericalGrid
|
|
Source code in earthcarekit/utils/geo/grid/_create_global_grid.py
ecef_to_geo
ecef_to_geo(
x,
y,
z,
target_radius=1.0,
perfect_sphere=True,
semi_major=SEMI_MAJOR_AXIS_METERS,
semi_minor=SEMI_MINOR_AXIS_METERS,
)
Converts Earth-centered, Earth-fixed (ECEF) coordinates (x, y, z) back to geodetic coordinates (latitude, longitude, altitude).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x, y, z
|
float
|
Cartesian ECEF coordinates. |
required |
target_radius
|
float
|
Target mean radius of the Earth ellipsoid in the new cartesian coordinate system. Defaults to 1. |
1.0
|
perfect_sphere
|
bool
|
If True, assume a spherical Earth, else ellipsoidal (WGS-84). |
True
|
semi_major
|
float
|
Semi-major axis of the Earth ellipsoid in meters. Defaults to 6378137 (WGS 84). |
SEMI_MAJOR_AXIS_METERS
|
semi_minor
|
float
|
Semi-minor axis of the Earth ellipsoid in meters. Defaults to 6356752.314245 (WGS 84). |
SEMI_MINOR_AXIS_METERS
|
Returns:
| Name | Type | Description |
|---|---|---|
coords |
tuple[float, float, float]
|
|
Source code in earthcarekit/utils/geo/convertsions.py
geo_to_ecef
geo_to_ecef(
lat,
lon,
alt=None,
target_radius=1.0,
perfect_sphere=True,
semi_major=SEMI_MAJOR_AXIS_METERS,
semi_minor=SEMI_MINOR_AXIS_METERS,
)
Converts geodetic coordinates (i.e. latitude, longitude and altitude above ellipsoid) to Earth-centered, Earth-fixed (ECEF) coordinates (i.e. x, y and z in cartesian coordinates).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Latitude angle north (positive) and south (negative) of the equator in degrees. |
required |
lon
|
float
|
Longitude angle east (positive) and west (negative) of the prime meridian in degrees. |
required |
alt
|
float
|
Height above above the Earth ellipsoid in meters. |
None
|
target_radius
|
float
|
Target mean radius of the Earth ellipsoid in the new cartesian coordinate system. Defaults to 1. |
1.0
|
semi_major
|
float
|
Semi-major axis of the Earth ellipsoid in meters. Defaults to 6378137 (WGS 84). |
SEMI_MAJOR_AXIS_METERS
|
semi_minor
|
float
|
Semi-minor axis of the Earth ellipsoid in meters. Defaults to 6356752.314245 (WGS 84). |
SEMI_MINOR_AXIS_METERS
|
Returns:
| Name | Type | Description |
|---|---|---|
coords |
tuple[float, float, float]
|
3D coordinates in meters (ECEF: A right-handed cartesian coordinate system that has its origin at the Earth's center and is fixed with respect to the Earth's rotation).
|
Source code in earthcarekit/utils/geo/convertsions.py
geodesic
Calculates the geodesic distances between points on Earth (i.e. WSG 84 ellipsoid) using Vincenty's inverse method.
Supports single or sequences of coordiates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ArrayLike
|
Coordinates [lat, lon] or array of shape (N, 2), in decimal degrees. |
required |
b
|
ArrayLike
|
Second coordinates, same format/shape as |
required |
units
|
str
|
Output units, "km" (default) or "m". |
'km'
|
tolerance
|
float
|
Convergence threshold in radians. Default is 1e-12. |
1e-12
|
max_iterations
|
int
|
Maximum iterations before failure. Default is 10. |
10
|
Returns:
| Type | Description |
|---|---|
float64 | NDArray[float64]
|
float or np.ndarray: The geodesic distance or distances between the point in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input shapes are incompatible or units are invalid. |
Note
Uses WGS84 (a=6378137.0 m, f=1/298.257223563). May fail for nearly antipodal points.
Examples:
>>> geodesic([51.352757, 12.43392], [38.559, 68.856])
4548.675334434374
>>> geodesic([0,0], [[0,0], [10,0], [20,0]])
array([ 0. , 1105.85483324, 2212.36625417])
>>> geodesic([[0,0], [10,0], [20,0]], [[0,0], [10,0], [20,0]])
array([0., 0., 0.])
References
Vincenty, T. (1975). "Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations." Survey Review, 23(176), 88-93. https://doi.org/10.1179/sre.1975.23.176.88
Source code in earthcarekit/utils/geo/distance/_vincenty.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
get_central_coords
Calculates the central lat/lon coordinates.
Source code in earthcarekit/utils/geo/coordinates.py
get_central_latitude
Calculates the central latitude coordinate.
Source code in earthcarekit/utils/geo/coordinates.py
get_central_longitude
Calculates the central longitude coordinate.
Source code in earthcarekit/utils/geo/coordinates.py
get_coord_between
Interpolates between two coordinates by fraction f (0 to 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coord1
|
ArrayLike
|
The first lat/lon point. |
required |
coord2
|
ArrayLike
|
The second lat/lon point. |
required |
f
|
float
|
A fractional value between 0 and 1. Defaults to 0.5, i.e., the mid point between coord1 and coord2. |
0.5
|
Returns:
| Name | Type | Description |
|---|---|---|
NDArray |
NDArray
|
A 2-element |
Source code in earthcarekit/utils/geo/interpolate.py
get_coords
Takes a xarray.Dataset and returns the lat/lon coordinates as a numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_var
|
str
|
Name of the latitude variable. Defaults to TRACK_LAT_VAR. |
TRACK_LAT_VAR
|
lon_var
|
str
|
Name of the longitude variable. Defaults to TRACK_LON_VAR. |
TRACK_LON_VAR
|
flatten
|
bool
|
If True, the coordinates will be flattened to a 2D array
|
False
|
Returns:
| Type | Description |
|---|---|
NDArray
|
numpy.array: The extracted lat/lon coordinates. |
Source code in earthcarekit/utils/geo/coordinates.py
haversine
Calculates the great-circle (spherical) distance between pairs of latitude/longitude coordinates using the haversine formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ArrayLike
|
An array-like object of shape (..., 2) containing latitude and longitude coordinates in degrees. The last dimension must be 2: (lat, lon). |
required |
b
|
ArrayLike
|
An array-like object of the same shape as |
required |
units
|
Literal['m', 'km']
|
Unit of the output distance. Must be either "km" for kilometers or "m" for meters. Defaults to "km". |
'km'
|
radius
|
float
|
Radius of the sphere to use for distance calculation.
Defaults to MEAN_EARTH_RADIUS_METERS (based on WSG 84 ellipsoid: ~6371008.77 meters).
Note: If |
required |
Returns:
| Type | Description |
|---|---|
|
np.ndarray: Array of great-circle distances between |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the shapes of |
Examples:
>>> haversine([51.352757, 12.43392], [38.559, 68.856])
4537.564747442274
>>> haversine([0,0], [[0,0], [10,0], [20,0]])
array([ 0. , 1111.95079735, 2223.90159469])
>>> haversine([[0,0], [10,0], [20,0]], [[0,0], [10,0], [20,0]])
array([0., 0., 0.])
Source code in earthcarekit/utils/geo/distance/_haversine.py
interpgeo
Interpolates along the geodesic from (lon1, lat1) to (lon2, lat2) by fraction f (0 to 1) and returns interpolated (lon, lat).
Source code in earthcarekit/utils/geo/interpolate.py
vincenty
Calculates the geodesic distances between points on Earth (i.e. WSG 84 ellipsoid) using Vincenty's inverse method.
Supports single or sequences of coordiates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ArrayLike
|
Coordinates [lat, lon] or array of shape (N, 2), in decimal degrees. |
required |
b
|
ArrayLike
|
Second coordinates, same format/shape as |
required |
units
|
str
|
Output units, "km" (default) or "m". |
'km'
|
tolerance
|
float
|
Convergence threshold in radians. Default is 1e-12. |
1e-12
|
max_iterations
|
int
|
Maximum iterations before failure. Default is 10. |
10
|
Returns:
| Type | Description |
|---|---|
float64 | NDArray[float64]
|
float or np.ndarray: The geodesic distance or distances between the point in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input shapes are incompatible or units are invalid. |
Note
Uses WGS84 (a=6378137.0 m, f=1/298.257223563). May fail for nearly antipodal points.
Examples:
>>> geodesic([51.352757, 12.43392], [38.559, 68.856])
4548.675334434374
>>> geodesic([0,0], [[0,0], [10,0], [20,0]])
array([ 0. , 1105.85483324, 2212.36625417])
>>> geodesic([[0,0], [10,0], [20,0]], [[0,0], [10,0], [20,0]])
array([0., 0., 0.])
References
Vincenty, T. (1975). "Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations." Survey Review, 23(176), 88-93. https://doi.org/10.1179/sre.1975.23.176.88
Source code in earthcarekit/utils/geo/distance/_vincenty.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |