33import typing
44
55try :
6- from numpy import radians , sin , cos , hypot , arctan2 as atan2 , degrees , pi , vectorize , ndarray
6+ from numpy import asarray , radians , sin , cos , hypot , arctan2 as atan2 , degrees , pi , ndarray
77except ImportError :
88 from math import radians , sin , cos , hypot , atan2 , degrees , pi # type: ignore
99
10- vectorize = None
1110 ndarray = typing .Any # type: ignore
1211
1312from .ecef import geodetic2ecef , ecef2geodetic , enu2ecef , uvw2enu
2019
2120
2221def enu2aer (
23- e : float | ndarray , n : float | ndarray , u : float | ndarray , deg : bool = True
24- ) -> tuple [float , float , float ]:
22+ e : ndarray , n : ndarray , u : ndarray , deg : bool = True
23+ ) -> tuple [ndarray , ndarray , ndarray ]:
2524 """
2625 ENU to Azimuth, Elevation, Range
2726
@@ -48,26 +47,19 @@ def enu2aer(
4847 slant range [meters]
4948 """
5049
51- if vectorize is not None :
52- fun = vectorize (enu2aer_point )
53- az , el , rng = fun (e , n , u , deg )
54- return az [()], el [()], rng [()]
55- else :
56- return enu2aer_point (e , n , u , deg )
57-
58-
59- def enu2aer_point (
60- e : float | ndarray , n : float | ndarray , u : float | ndarray , deg : bool = True
61- ) -> tuple [float , float , float ]:
62-
6350 # 1 millimeter precision for singularity
6451
65- if abs (e ) < 1e-3 :
66- e = 0.0
67- if abs (n ) < 1e-3 :
68- n = 0.0
69- if abs (u ) < 1e-3 :
70- u = 0.0
52+ try :
53+ e [abs (e ) < 1e-3 ] = 0.0
54+ n [abs (n ) < 1e-3 ] = 0.0
55+ u [abs (u ) < 1e-3 ] = 0.0
56+ except TypeError :
57+ if abs (e ) < 1e-3 :
58+ e = 0.0 # type: ignore
59+ if abs (n ) < 1e-3 :
60+ n = 0.0 # type: ignore
61+ if abs (u ) < 1e-3 :
62+ u = 0.0 # type: ignore
7163
7264 r = hypot (e , n )
7365 slantRange = hypot (r , u )
@@ -82,17 +74,6 @@ def enu2aer_point(
8274
8375
8476def aer2enu (az : float , el : float , srange : float , deg : bool = True ) -> tuple [float , float , float ]:
85- if vectorize is not None :
86- fun = vectorize (aer2enu_point )
87- e , n , u = fun (az , el , srange , deg )
88- return e [()], n [()], u [()]
89- else :
90- return aer2enu_point (az , el , srange , deg )
91-
92-
93- def aer2enu_point (
94- az : float , el : float , srange : float , deg : bool = True
95- ) -> tuple [float , float , float ]:
9677 """
9778 Azimuth, Elevation, Slant range to target to East, North, Up
9879
@@ -120,8 +101,12 @@ def aer2enu_point(
120101 el = radians (el )
121102 az = radians (az )
122103
123- if srange < 0 :
124- raise ValueError ("Slant range [0, Infinity)" )
104+ try :
105+ if (asarray (srange ) < 0 ).any ():
106+ raise ValueError ("Slant range [0, Infinity)" )
107+ except UnboundLocalError :
108+ if srange < 0 :
109+ raise ValueError ("Slant range [0, Infinity)" )
125110
126111 r = srange * cos (el )
127112
@@ -177,15 +162,15 @@ def enu2geodetic(
177162
178163
179164def geodetic2enu (
180- lat : float ,
181- lon : float ,
182- h : float ,
165+ lat : ndarray ,
166+ lon : ndarray ,
167+ h : ndarray ,
183168 lat0 : float ,
184169 lon0 : float ,
185170 h0 : float ,
186171 ell : Ellipsoid = None ,
187172 deg : bool = True ,
188- ) -> tuple [float , float , float ]:
173+ ) -> tuple [ndarray , ndarray , ndarray ]:
189174 """
190175 Parameters
191176 ----------
0 commit comments