astrix.functs module

Array and logic functions for Astrix.

Should not have any dependencies on core Astrix types to avoid circular dependencies. Backend utility imports are allowed.

Guiding principles: - Functions should be backend-agnstic where possible. - Functions should be JIT-compatible, where possible. - Data validation is not performed here, assume inputs are valid.

ecef2geodet(ecef)[source]

Use pyproj to convert from WGS84 coordinates to geodetic (Cartesian Earth Centered Earth Fixed (ECEF) to lat, long, alt)

Parameters:

ecef (np.ndarray) – 3xn array of ECEF x,y,z points in [m]

Returns:

3xn array of long, lat, alt [m] points

Return type:

np.ndarray

ensure_1d(x, backend=None)[source]

Ensure the input array is 1-dimensional. Scalars are converted to shape (1,).

Return type:

Any

Parameters:
  • x (Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | float | list[float])

  • backend (Any | None)

ensure_2d(x, n=None, backend=None)[source]

Ensure the input array is 2-dimensional. If n is given, ensure the second dimensionn has size n.

Return type:

Any

Parameters:
  • x (Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | float | list[float] | list[list[float]])

  • n (int | None)

  • backend (Any | None)

finite_diff_2pt(xd, fd, backend=None)[source]

Simple 2-point finite difference derivative of fd w.r.t. xd at the sample nodes. Uses forward difference at the first point, backward difference at the last point, and central difference in the interior.

Parameters:
  • xd ((N,) strictly increasing array of x-locations, must have N>=2)

  • fd ((N, ...) array of function values; derivative is taken along axis 0)

  • backend (optional, backend to use (numpy, jax, etc.))

Returns:

dfdx

Return type:

(N, …) array of derivatives at each xd[i]

Notes

Must have xd.shape[0] >= 2. No bounds checking is performed

geodet2ecef(geodet)[source]

Use pyproj to convert from WGS84 coordinates to x,y,z points (long, lat, alt to Cartesian Earth Centered Earth Fixed(ECEF))

Parameters:

geodet (np.ndarray) – 3xn array of long, lat, alt [m] points

Returns:

3xn array of ECEF x,y,z points in [m]

Return type:

np.ndarray

great_circle_distance(geodet1, geodet2, backend=None, ignore_elev=False)[source]

Uses haversine formual for cirular distance Accounts for change in altitude using euclidian norm

Ref: http://www.movable-type.co.uk/scripts/latlong.html

Can choose to ignore change in elevation for great circle distance at constant altitude

Parameters:
  • geodet1 (Array) – Nx3 array of lat, long, alt [deg, deg, m]

  • geodet2 (Array) – Nx3 array of lat, long, alt [deg, deg, m]

  • backend (Backend, optional)

  • ignore_elev (bool, optional) – If True, ignore elevation change. Defaults to False.

Returns:

Array of distances [m] between each pair of points

Return type:

Array

interp_haversine(secs, secs_data, ecef_data, backend=None)[source]

Interpolate ECEF trajectory data to given times using great-circle (haversine) interpolation. This is more accurate for long distances than linear interpolation in ECEF space. Approximates the Earth as a sphere (reasonable for interpolation).

Parameters:
  • secs (Array) – 1D array of times [s] to interpolate at.

  • secs_data (Array) – 1D array of times [s] of the data points.

  • ecef_data (Array) – Nx3 array of ECEF x,y,z points [m] of the data points.

  • backend (Backend, optional) – Backend to use (numpy, jax, etc.). Defaults to None.

Returns:

Mx3 array of interpolated ECEF x,y,z points [m] at times secs.

Return type:

Array

Notes

  • This function is not compatible with Jax JIT or grad due to the use of pyproj.

  • secs_data must be strictly increasing and within the bounds of secs.

  • ecef_data and secs_data must have the same length along axis 1.

  • Uses WGS84 Earth radius for haversine calculations.

is_increasing(x, backend=None)[source]

Check if the input array is strictly increasing along the first axis.

Return type:

bool

Parameters:
  • x (Any)

  • backend (Any | None)

ned_rotation(geodet, xp=None)[source]

Get the rotation from ECEF base to the North-East-Down frame at given geodetic locations.

Parameters:
  • pos_geodet (Array) – Nx3 array of lat, long, alt [deg, deg, m]

  • geodet (Any)

  • xp (Any | None)

Returns:

scipy Rotation object representing the NED frame rotation

Return type:

Rotation

sort_by_time(times, data, backend=None)[source]

Sort data by increasing time.

Parameters:
  • times (Array) – 1D array of times, len N.

  • data (Array) – NxM array of data to sort by time.

  • backend (Backend, optional) – Backend to use. Defaults to None.

Returns:

Sorted times and data.

Return type:

tuple[Array, Array]