pymap3d Library
pymap3d is a pure Python library (with no external prerequisites) providing various coordinate conversions. It follows the conventions of several popular Matlab routines for geospatial and attitude transformations. The current version is 3.2.0, and it maintains an active development status with regular updates.
Warnings
- breaking The entire `pymap3d.aer` module was removed in v3.0.0. Functions like `aer2enu` and `enu2aer` must now be imported and used directly from `pymap3d`.
- breaking The sign for altitude in `aer2enu` was corrected in v3.1.0. If you relied on the incorrect sign in previous versions, your altitude results will now be inverted.
- gotcha pymap3d explicitly follows Matlab's coordinate convention. This means input/output order (e.g., lat, lon, alt vs. lon, lat, alt), units (degrees vs. radians), and specific frame definitions might differ from other Python geospatial libraries.
- gotcha In v3.0.0, the default value for the `height` parameter in `geodetic2ecef` changed from `NaN` to `0.0`. This can silently alter results if code implicitly relied on the previous `NaN` behavior without explicitly passing a `height` value.
Install
-
pip install pymap3d
Imports
- geodetic2ecef
from pymap3d import geodetic2ecef
- ecef2geodetic
from pymap3d import ecef2geodetic
- ecef2eci
from pymap3d import ecef2eci
- enu2uvw
from pymap3d import enu2uvw
Quickstart
import pymap3d as pm
import datetime
# Example Geodetic (Lat, Lon, Alt) to ECEF (Earth-Centered, Earth-Fixed) conversion
lat, lon, alt = 42.0, -82.0, 200.0 # Latitude (deg), Longitude (deg), Altitude (meters)
x, y, z = pm.geodetic2ecef(lat, lon, alt)
print(f"ECEF coordinates: x={x:.2f}m, y={y:.2f}m, z={z:.2f}m")
# Example ECEF to Geodetic conversion
lat2, lon2, alt2 = pm.ecef2geodetic(x, y, z)
print(f"Geodetic coordinates: lat={lat2:.2f}deg, lon={lon2:.2f}deg, alt={alt2:.2f}m")
# Example ECEF to ECI (Earth-Centered Inertial) conversion (requires datetime)
# For a specific time, you need the corresponding position and velocity.
time = datetime.datetime(2023, 1, 20, 12, 0, 0, tzinfo=datetime.timezone.utc)
x_eci, y_eci, z_eci = pm.ecef2eci(x, y, z, time)
print(f"ECI coordinates (at {time}): x={x_eci:.2f}m, y={y_eci:.2f}m, z={z_eci:.2f}m")