Skip to content

Commit 249046e

Browse files
committed
pythonic logic
1 parent 727855e commit 249046e

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/pymap3d/aer.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
try:
1212
from .eci import eci2ecef, ecef2eci
1313
except ImportError:
14-
eci2ecef = ecef2eci = None # type: ignore
14+
pass
1515

1616
if typing.TYPE_CHECKING:
1717
from numpy import ndarray
@@ -212,10 +212,11 @@ def eci2aer(
212212
srange : float
213213
slant range [meters]
214214
"""
215-
if eci2ecef is None:
216-
raise ImportError("pip install numpy")
217215

218-
xecef, yecef, zecef = eci2ecef(x, y, z, t, use_astropy=use_astropy)
216+
try:
217+
xecef, yecef, zecef = eci2ecef(x, y, z, t, use_astropy=use_astropy)
218+
except NameError:
219+
raise ImportError("pip install numpy")
219220

220221
return ecef2aer(xecef, yecef, zecef, lat0, lon0, h0, deg=deg)
221222

@@ -271,12 +272,13 @@ def aer2eci(
271272
z : float
272273
ECEF z coordinate (meters)
273274
"""
274-
if ecef2eci is None:
275-
raise ImportError("pip install numpy")
276275

277276
x, y, z = aer2ecef(az, el, srange, lat0, lon0, h0, ell, deg=deg)
278277

279-
return ecef2eci(x, y, z, t, use_astropy=use_astropy)
278+
try:
279+
return ecef2eci(x, y, z, t, use_astropy=use_astropy)
280+
except NameError:
281+
raise ImportError("pip install numpy")
280282

281283

282284
def aer2ecef(

src/pymap3d/ecef.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
try:
66
from numpy import radians, sin, cos, tan, arctan as atan, hypot, degrees, arctan2 as atan2, sqrt
7+
from .eci import eci2ecef, ecef2eci
78
except ImportError:
89
from math import radians, sin, cos, tan, atan, hypot, degrees, atan2, sqrt # type: ignore
910

@@ -13,11 +14,6 @@
1314
from .ellipsoid import Ellipsoid
1415
from .utils import sanitize
1516

16-
try:
17-
from .eci import eci2ecef, ecef2eci
18-
except ImportError:
19-
eci2ecef = ecef2eci = None # type: ignore
20-
2117
if typing.TYPE_CHECKING:
2218
from numpy import ndarray
2319

@@ -395,10 +391,11 @@ def eci2geodetic(
395391
396392
eci2geodetic() a.k.a. eci2lla()
397393
"""
398-
if eci2ecef is None:
399-
raise ImportError("pip install numpy")
400394

401-
xecef, yecef, zecef = eci2ecef(x, y, z, t, use_astropy=use_astropy)
395+
try:
396+
xecef, yecef, zecef = eci2ecef(x, y, z, t, use_astropy=use_astropy)
397+
except NameError:
398+
raise ImportError("pip install numpy")
402399

403400
return ecef2geodetic(xecef, yecef, zecef, ell, deg)
404401

@@ -446,12 +443,13 @@ def geodetic2eci(
446443
447444
geodetic2eci() a.k.a lla2eci()
448445
"""
449-
if ecef2eci is None:
450-
raise ImportError("pip install numpy")
451446

452447
x, y, z = geodetic2ecef(lat, lon, alt, ell, deg)
453448

454-
return ecef2eci(x, y, z, t, use_astropy=use_astropy)
449+
try:
450+
return ecef2eci(x, y, z, t, use_astropy=use_astropy)
451+
except NameError:
452+
raise ImportError("pip install numpy")
455453

456454

457455
def enu2ecef(

0 commit comments

Comments
 (0)