Skip to content

Commit b0360bf

Browse files
committed
put cbrt() in utils.py
1 parent 5ab7858 commit b0360bf

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/pymap3d/spherical.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@
1414
degrees,
1515
arctan2 as atan2,
1616
sqrt,
17-
cbrt,
1817
power as pow,
1918
)
2019
except ImportError:
2120
from math import radians, sin, hypot, degrees, atan2, asin, sqrt # type: ignore
2221

23-
def cbrt(x): # type: ignore
24-
"Backup cube root function in case of no numpy"
25-
return x ** (1 / 3)
2622

2723
from .ellipsoid import Ellipsoid
28-
from .utils import sanitize
24+
from .utils import sanitize, cbrt
2925

3026

3127
__all__ = [
@@ -87,7 +83,8 @@ def geodetic2spherical(
8783

8884
# radius of curvature of the prime vertical section
8985
N = ell.semimajor_axis**2 / hypot(
90-
ell.semimajor_axis * coslat, ell.semiminor_axis * sinlat,
86+
ell.semimajor_axis * coslat,
87+
ell.semiminor_axis * sinlat,
9188
)
9289

9390
# Instead of computing X and Y, we only compute the projection on the XY

src/pymap3d/tests/test_spherical.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from pytest import approx
33

44
try:
5-
import numpy.array as nparray
5+
from numpy import asarray
66
except ImportError:
77

8-
def nparray(*args):
8+
def asarray(*args): # type: ignore
99
"dummy function to convert values to arrays"
1010
return args
1111

12+
1213
import pymap3d as pm
1314

1415

@@ -36,8 +37,8 @@ def nparray(*args):
3637
]
3738
llallr_list = [([[i] for i in lla], llr) for lla, llr in llallr]
3839
llrlla_list = [([[i] for i in llr], lla) for llr, lla in llrlla]
39-
llallr_array = [([nparray(i) for i in lla], llr) for lla, llr in llallr]
40-
llrlla_array = [([nparray(i) for i in llr], lla) for llr, lla in llrlla]
40+
llallr_array = [([asarray(i) for i in lla], llr) for lla, llr in llallr]
41+
llrlla_array = [([asarray(i) for i in llr], lla) for llr, lla in llrlla]
4142

4243
atol_dist = 1e-6 # 1 micrometer
4344

src/pymap3d/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .ellipsoid import Ellipsoid
99

1010
try:
11-
from numpy import hypot, cos, sin, arctan2 as atan2, radians, asarray, sign
11+
from numpy import hypot, cos, sin, arctan2 as atan2, radians, asarray, sign, cbrt
1212
except ImportError:
1313
from math import atan2, hypot, cos, sin, radians # type: ignore
1414

@@ -23,6 +23,10 @@ def sign(x) -> float: # type: ignore
2323

2424
return y
2525

26+
def cbrt(x) -> float: # type: ignore
27+
"""math.cbrt was added in Python 3.11"""
28+
return x ** (1 / 3)
29+
2630

2731
__all__ = ["cart2pol", "pol2cart", "cart2sph", "sph2cart", "sign"]
2832

0 commit comments

Comments
 (0)