Skip to main content

GeoSol Research Logo

Utils

Utility functions available for any project.

This library is a general collection of utility functions and constants with minimal requirements. Requires Python 3.12+.

Installation

pip install gri-utils

For development:

git clone https://gitlab.com/geosol-foss/python/gri-utils.git
cd gri-utils
uv sync

Quick Start

from gri_utils import conversion, distance, constants

# Convert LLA (lat, lon, alt) to ECEF XYZ
xyz = conversion.lla_to_xyz([40.0, -105.0, 1600.0])

# Surface distance between two points (Vincenty, accurate to ~0.5 mm)
d_m = distance.vincenty([40.0, -105.0], [41.0, -104.0])

# Coordinate deltas
enu = conversion.get_enu(xyz_from, xyz_to)
aer = conversion.get_aer(xyz_from, xyz_to)

# Earth constants
print(constants.ER_M)   # Earth equatorial radius (meters)
print(constants.C)       # Speed of light (m/s)

Constants

Common geolocation constants including Earth's equatorial and polar radii, eccentricity, flattening, and statistical scaling factors for sigma to 95% confidence conversions. Also provides a GeoEllipsoid dataclass and a pre-built WGS84 instance exposing .a, .b, .f, .e2, .n(lat_rad) (prime vertical) and .m(lat_rad) (meridional) radii of curvature.

See Constants README

Conversion

Coordinate system transformations between XYZ (ECEF), LLA (Lat/Lon/Alt), ENU, NED, AER, CCR, and ECI. Includes:

  • ECEF <-> ECI: Time-dependent transformations between Earth-fixed and inertial frames via GMST
  • Julian Date: Unix timestamp and datetime conversions to/from Julian Date
  • GMST: Greenwich Mean Sidereal Time calculations (IAU 2006 precession model)
  • Rotation matrices: xyz_enu_rotation, enu_xyz_rotation, xyz_ned_rotation, ned_xyz_rotation
  • Delta operations: get_*, translate_*, xyz_to_*, *_to_xyz for each coordinate type
  • Covariance matrix transformations: xyz_to_enu_cov, enu_to_xyz_cov, xyz_to_ned_cov, ned_to_xyz_cov
  • DMS conversions: Degrees/Minutes/Seconds <-> decimal degrees

All conversion functions support vectorized inputs for efficient batch processing of (N, 3) arrays. Covariance matrix functions support stacked (N, 3, 3) matrices.

See Conversion README

Distance

Surface distance calculations with multiple formulas: simple spherical approximation (fast, good for relative distances <500km), Haversine (standard spherical, ~0.5% error), and Vincenty (iterative oblate spheroid, accurate to ~0.5mm). Also includes central angle calculations and osculating sphere computations.

Most distance functions support vectorized inputs for efficient batch processing of (N, 2+) LLA or (N, 3) XYZ arrays.

See Distance README

Ellipsoids

Conversions between 2D/3D ellipse parameters (SMA, SMI, ORI, ALT) and covariance matrices. Includes sigma <-> 95% confidence scaling for scalars, vectors, and matrices.

See Ellipsoids README

Matrices

Matrix and vector rotation utilities for 2D and 3D operations around one or more axes. Also includes block diagonal matrix construction and decomposition utilities.

See Matrices README

Resources

Programming utilities including a memory/CPU usage measuring decorator and a Thread subclass that returns values from its target function.

See Resources README

Stats

Statistical utilities for confidence intervals and scale factor analysis. Includes Poisson CI (Garwood method), quantile CI (normal approximation to binomial), ratio CI (Walters logarithm method), and scale factor analysis for ellipse calibration.

See Stats README

Geolocation

Mathematical building blocks for geolocation solvers:

  • Whitened least squares: Generic Cholesky-whitened nonlinear solver with correlated measurement support
  • Predicted covariance: Analytical GDOP computation from Jacobian and measurement noise (no solver iteration needed)
  • Default initial guess: Projects collector centroid onto Earth surface for solver initialization

Observable-specific locators (TDOA, AOA, FDOA, hybrid) that wrap these primitives live in gri-geosim.

See Geolocation README

Observables

Sensor measurement simulation (forward problem - state to measurements):

  • Range: Euclidean distance from collector to emitter
  • AOA: Angle of Arrival direction cosines (ENU-based and quaternion-based for arbitrary sensor orientation)
  • TDOA: Time Difference of Arrival between two collectors
  • TDOA-dot: Time derivative of TDOA (s/s, frequency-independent form of FDOA)
  • FDOA: Frequency Difference of Arrival (Doppler)
  • PDOA: Phase Difference of Arrival for interferometer arrays
  • Gradients: Jacobians available for optimization workflows
  • Residual factories: Each observable provides a get_*_residual function for use with terrain intersection algorithms

Quaternions use scipy convention [x, y, z, w] (scalar-last).

See Observables README

Orbit

Two-body Keplerian orbit mechanics for orbital propagation and analysis:

  • Orbital Elements: Classical Keplerian parameters (SMA, eccentricity, inclination, RAAN, arg_periapsis, true_anomaly)
  • State Vectors: Position, velocity, acceleration at specific times
  • TLE Parsing: Two-Line Element data conversion to orbital elements
  • Orbit Fitting: Fit elements from position/velocity state or multiple observations
  • Propagation: elements_to_state for forward propagation
  • Properties: Period, apogee, perigee, specific energy, angular momentum

Note: Pure Keplerian mechanics only (no perturbations). For TLE propagation with J2/drag, use SGP4 library.

See Orbit README

Geoid

EGM96 geoid model and conversion between orthometric (mean sea level) and ellipsoidal height, h = H + N. Terrain and mapping products publish orthometric height; every coordinate transform here consumes ellipsoidal height, and the two differ by up to about -107 m to +85 m depending on location. Convert terrain elevations on the way in, not inside lla_to_xyz.

See Geoid README

Terrain

Pure math functions for terrain represented as XYZ surface grids (sheets) in ECEF coordinates:

  • Sheet operations: LLA-to-XYZ conversion, bicubic interpolation, resolution measurement
  • Grid sampling: GridSampler prefilters a scalar grid once for repeated bicubic lookups, and confines void (NaN) cells to the queries whose stencil reaches them
  • Sheet bounds: Radial bounding surfaces for fast ray rejection
  • Ray intersection: Adaptive-step ray-sheet intersection
  • Specular reflection: Bounce point between two positions over terrain, with exact delay sensitivities to both endpoints and to DEM height error
  • Visibility/shadow: Shadow depth scalar field, visibility masks, shadow boundary contours
  • Marching squares: Iso-contour extraction from 2D scalar fields
  • Sheet intersection: Generic terrain intersection with observable iso-surfaces (range, TDOA, FDOA, AOA)
  • TerrainSource ABC: Abstract interface for terrain data providers (implemented by gri-terrain)
  • Sheet stitching: Mosaic multiple tiles into a single contiguous array
  • Adaptive intersection: Subsample-based efficient intersection for large terrain datasets

See Terrain README

Dependencies

  • numpy: Array operations and linear algebra
  • scipy: Scientific computing (coordinate conversions, optimization)
  • psutil: System resource monitoring (optional, for resources module)

Other Projects

Current list of other GRI FOSS Projects we are building and maintaining.

License

MIT License. See LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gri_utils-0.6.0.tar.gz (2.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gri_utils-0.6.0-py3-none-any.whl (2.2 MB view details)

Uploaded Python 3

File details

Details for the file gri_utils-0.6.0.tar.gz.

File metadata

  • Download URL: gri_utils-0.6.0.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gri_utils-0.6.0.tar.gz
Algorithm Hash digest
SHA256 ce90fe3394984bb65488a6b342dceec1dcc3ff1e480be4ccad627c4fcd6575ac
MD5 9d9658e20dcb730b1c78a0f8e3a89496
BLAKE2b-256 8af25c7a0e3d651c82a2df4c0f81205b4b6b1ab053f20615f0974ae1952eb65a

See more details on using hashes here.

File details

Details for the file gri_utils-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: gri_utils-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gri_utils-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b53aaf8a234e72382ab3e18f84dd80cc24f7ba848cc5f070ba1159cb2e8a049e
MD5 96fcb39c8f80c11cc4165d345cc79139
BLAKE2b-256 211c9b99b097574e256210767e7dd58a56a8aeeaa3c1b82781b5c3f99c3a88d3

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.1

2 files

This release

0.6.0 This release

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0.post1

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page