Skip to content

Commit

Permalink
Use np.float64 for numpy 2.0 compatibility (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
armallen authored Jul 1, 2024
1 parent ea0bf3d commit 292336a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions gnss/coord_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@


from typing import List, Tuple, Union

import numpy as np
import numpy.typing as npt

ArrayLike = Union[List, Tuple, np.ndarray]
Coordinate = Tuple[
npt.NDArray[np.float_], npt.NDArray[np.float_], npt.NDArray[np.float_]
npt.NDArray[np.float64], npt.NDArray[np.float64], npt.NDArray[np.float64]
]

WGS84_A: float = 6378137.0
Expand Down Expand Up @@ -62,7 +63,7 @@ def llh_from_ecef(ecef: ArrayLike) -> Coordinate:
p = np.linalg.norm((x, y))

# Compute longitude first, this can be done exactly.
if p == 0.0:
if np.allclose(p, 0.0):
lon = np.zeros(np.array(x).shape, float)
else:
lon = np.arctan2(y, x)
Expand Down Expand Up @@ -178,7 +179,7 @@ def ecef_from_llh(llh: ArrayLike) -> Coordinate:
return x, y, z


def ecef_to_ned_matrix(ref_ecef: ArrayLike) -> npt.NDArray[np.float_]:
def ecef_to_ned_matrix(ref_ecef: ArrayLike) -> npt.NDArray[np.float64]:
"""Populates a provided 3x3 matrix with the appropriate rotation
matrix to transform from ECEF to NED coordinates, given the
provided ECEF reference vector.
Expand Down Expand Up @@ -209,14 +210,14 @@ def ecef_to_ned_matrix(ref_ecef: ArrayLike) -> npt.NDArray[np.float_]:

def ned_from_ecef(
ecef_vector: ArrayLike, reference_location: ArrayLike
) -> npt.NDArray[np.float_]:
) -> npt.NDArray[np.float64]:
"""Convert ECEF coordinates into NED frame of given reference."""
return np.dot(ecef_to_ned_matrix(reference_location), ecef_vector)


def relative_position_in_ned(
ecef_target: ArrayLike, ecef_reference: ArrayLike
) -> npt.NDArray[np.float_]:
) -> npt.NDArray[np.float64]:
"""Returns the vector between two ECEF points in the NED frame of the
reference.
Expand Down Expand Up @@ -244,7 +245,7 @@ def relative_position_in_ned(

def azimuth_elevation_from_ecef(
ecef_target: ArrayLike, ecef_reference: ArrayLike
) -> Tuple[npt.NDArray[np.float_], npt.NDArray[np.float_]]:
) -> Tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]:
"""Returns the azimuth and elevation of a vector pointing from `ref_position`
to `position` where both are given in ECEF
Expand Down

0 comments on commit 292336a

Please sign in to comment.