Skip to content

Commit f4e595d

Browse files
committed
correct cube_root function. Use _dummy module to avoid type: ignore
1 parent d4d8e57 commit f4e595d

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/pymap3d/_dummy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from datetime import datetime
2+
3+
def eci2ecef(x, y, z, time: datetime, force_non_astropy: bool = False) -> tuple:
4+
raise ImportError("Numpy required for eci2ecef")
5+
6+
def ecef2eci(x, y, z, time: datetime, force_non_astropy: bool = False) -> tuple:
7+
raise ImportError("Numpy required for ecef2eci")

src/pymap3d/aer.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111
try:
1212
from .eci import ecef2eci, eci2ecef
1313
except ImportError:
14-
15-
def eci2ecef(x, y, z, time: datetime, force_non_astropy: bool = False) -> tuple:
16-
raise ImportError("Numpy required for eci2ecef")
17-
18-
def ecef2eci(x, y, z, time: datetime, force_non_astropy: bool = False) -> tuple:
19-
raise ImportError("Numpy required for ecef2eci")
14+
from ._dummy import ecef2eci, eci2ecef
2015

2116

2217
__all__ = ["aer2ecef", "ecef2aer", "geodetic2aer", "aer2geodetic", "eci2aer", "aer2eci"]

src/pymap3d/mathfun.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,14 @@ def sign(x) -> float: # type: ignore
7171

7272
return y
7373

74-
try:
75-
import math.cbrt as cbrt # type: ignore
76-
except ImportError:
77-
78-
def cbrt(x) -> float: # type: ignore
79-
return x ** (1 / 3)
80-
8174

8275
__all__ = [
8376
"asin",
8477
"asinh",
8578
"atan",
8679
"atan2",
8780
"atanh",
88-
"cbrt",
81+
"cube_root",
8982
"cos",
9083
"degrees",
9184
"exp",
@@ -101,3 +94,14 @@ def cbrt(x) -> float: # type: ignore
10194
"sqrt",
10295
"tan",
10396
]
97+
98+
99+
def cube_root(x):
100+
"""cube root function, handles negative numbers"""
101+
try:
102+
return cbrt(x)
103+
except NameError:
104+
if x < 0:
105+
return -power(-x, 1.0 / 3.0)
106+
else:
107+
return power(x, 1.0 / 3.0)

src/pymap3d/spherical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import annotations
88

99
from .ellipsoid import Ellipsoid
10-
from .mathfun import asin, atan2, cbrt, degrees, hypot, power, radians, sin, sqrt
10+
from .mathfun import asin, atan2, cube_root, degrees, hypot, power, radians, sin, sqrt
1111

1212
__all__ = [
1313
"geodetic2spherical",
@@ -145,7 +145,7 @@ def spherical2geodetic(
145145
q_0 = (1 - ell.eccentricity**2) / ell.semimajor_axis**2 * Z**2
146146
r_0 = (p_0 + q_0 - ell.eccentricity**4) / 6
147147
s_0 = ell.eccentricity**4 * p_0 * q_0 / 4 / r_0**3
148-
t_0 = cbrt(1 + s_0 + sqrt(2 * s_0 + s_0**2))
148+
t_0 = cube_root(1 + s_0 + sqrt(2 * s_0 + s_0**2))
149149
u_0 = r_0 * (1 + t_0 + 1 / t_0)
150150
v_0 = sqrt(u_0**2 + q_0 * ell.eccentricity**4)
151151
w_0 = ell.eccentricity**2 * (u_0 + v_0 - q_0) / 2 / v_0

0 commit comments

Comments
 (0)