Skip to content

Commit 0bb4350

Browse files
committed
Ellipsoid: canonical default instead of None
1 parent f3a3a53 commit 0bb4350

19 files changed

+151
-184
lines changed

Examples/plot_geodetic2ecef.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
import typing
35
import argparse
46

57
import matplotlib.pyplot as mpl
@@ -15,15 +17,15 @@
1517
x, y, z = pm.geodetic2ecef(lat, lon, args.alt_m)
1618

1719

18-
def panel(ax, val, name: str, cmap: str = None):
20+
def panel(ax, val, name: str, cmap: str | None = None):
1921
hi = ax.pcolormesh(lon, lat, val, cmap=cmap)
2022
ax.set_title(name)
2123
fg.colorbar(hi, ax=ax).set_label(name + " [m]")
2224
ax.set_xlabel("longitude [deg]")
2325

2426

2527
fg = mpl.figure(figsize=(16, 5))
26-
axs = fg.subplots(1, 3, sharey=True)
28+
axs: typing.Any = fg.subplots(1, 3, sharey=True)
2729
fg.suptitle("geodetic2ecef")
2830

2931
panel(axs[0], x, "x", "bwr")

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ known_third_party = ["pymap3d"]
4242
files = ["src", "Examples", "scripts"]
4343

4444
ignore_missing_imports = true
45-
strict_optional = false
46-
show_column_numbers = true
4745

4846
[tool.coverage.run]
4947
branch = true

src/pymap3d/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Fortran: [Maptran3D](https://github.com/geospace-code/maptran3d)
3030
"""
3131

32-
__version__ = "3.0.1"
32+
__version__ = "3.1.0"
3333

3434
from .aer import aer2ecef, aer2geodetic, ecef2aer, geodetic2aer
3535
from .ecef import (

src/pymap3d/aer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

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

18+
ELL = Ellipsoid.from_name("wgs84")
19+
1820

1921
def ecef2aer(
2022
x,
@@ -23,7 +25,7 @@ def ecef2aer(
2325
lat0,
2426
lon0,
2527
h0,
26-
ell: Ellipsoid = None,
28+
ell: Ellipsoid = ELL,
2729
deg: bool = True,
2830
) -> tuple:
2931
"""
@@ -72,7 +74,7 @@ def geodetic2aer(
7274
lat0,
7375
lon0,
7476
h0,
75-
ell: Ellipsoid = None,
77+
ell: Ellipsoid = ELL,
7678
deg: bool = True,
7779
) -> tuple:
7880
"""
@@ -120,7 +122,7 @@ def aer2geodetic(
120122
lat0,
121123
lon0,
122124
h0,
123-
ell: Ellipsoid = None,
125+
ell: Ellipsoid = ELL,
124126
deg: bool = True,
125127
) -> tuple:
126128
"""
@@ -213,7 +215,7 @@ def aer2eci(
213215
lon0,
214216
h0,
215217
t: datetime,
216-
ell=None,
218+
ell: Ellipsoid = ELL,
217219
*,
218220
deg: bool = True,
219221
) -> tuple:
@@ -269,7 +271,7 @@ def aer2ecef(
269271
lat0,
270272
lon0,
271273
alt0,
272-
ell: Ellipsoid = None,
274+
ell: Ellipsoid = ELL,
273275
deg: bool = True,
274276
) -> tuple:
275277
"""

src/pymap3d/ecef.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from .ellipsoid import Ellipsoid
1818
from .mathfun import atan, atan2, cos, degrees, hypot, isclose, radians, sin, sqrt, tan
19-
from .utils import sanitize
2019

2120
__all__ = [
2221
"geodetic2ecef",
@@ -30,12 +29,14 @@
3029
"enu2ecef",
3130
]
3231

32+
ELL = Ellipsoid.from_name("wgs84")
33+
3334

3435
def geodetic2ecef(
3536
lat,
3637
lon,
3738
alt,
38-
ell: Ellipsoid = None,
39+
ell: Ellipsoid = ELL,
3940
deg: bool = True,
4041
) -> tuple:
4142
"""
@@ -68,8 +69,9 @@ def geodetic2ecef(
6869
z
6970
target z ECEF coordinate (meters)
7071
"""
71-
lat, ell = sanitize(lat, ell, deg)
72+
7273
if deg:
74+
lat = radians(lat)
7375
lon = radians(lon)
7476

7577
# radius of curvature of the prime vertical section
@@ -88,7 +90,7 @@ def ecef2geodetic(
8890
x,
8991
y,
9092
z,
91-
ell: Ellipsoid = None,
93+
ell: Ellipsoid = ELL,
9294
deg: bool = True,
9395
) -> tuple:
9496
"""
@@ -121,9 +123,6 @@ def ecef2geodetic(
121123
Journal of Surveying Engineering. doi: 10.1061/(ASCE)0733-9453
122124
"""
123125

124-
if ell is None:
125-
ell = Ellipsoid.from_name("wgs84")
126-
127126
try:
128127
x = asarray(x)
129128
y = asarray(y)
@@ -167,10 +166,7 @@ def ecef2geodetic(
167166
# eqn. 13
168167
Beta += (
169168
(ell.semiminor_axis * u - ell.semimajor_axis * huE + E**2) * sin(Beta)
170-
) / (
171-
ell.semimajor_axis * huE * 1 / cos(Beta)
172-
- E**2 * cos(Beta)
173-
)
169+
) / (ell.semimajor_axis * huE * 1 / cos(Beta) - E**2 * cos(Beta))
174170
except (ArithmeticError, RuntimeWarning):
175171
if isclose(z, 0):
176172
Beta = 0
@@ -281,7 +277,7 @@ def ecef2enu(
281277
lat0,
282278
lon0,
283279
h0,
284-
ell: Ellipsoid = None,
280+
ell: Ellipsoid = ELL,
285281
deg: bool = True,
286282
) -> tuple:
287283
"""
@@ -407,7 +403,7 @@ def uvw2enu(u, v, w, lat0, lon0, deg: bool = True) -> tuple:
407403
return East, North, Up
408404

409405

410-
def eci2geodetic(x, y, z, t: datetime, ell: Ellipsoid = None, *, deg: bool = True) -> tuple:
406+
def eci2geodetic(x, y, z, t: datetime, ell: Ellipsoid = ELL, *, deg: bool = True) -> tuple:
411407
"""
412408
convert Earth Centered Internal ECI to geodetic coordinates
413409
@@ -448,7 +444,7 @@ def eci2geodetic(x, y, z, t: datetime, ell: Ellipsoid = None, *, deg: bool = Tru
448444
return ecef2geodetic(xecef, yecef, zecef, ell, deg)
449445

450446

451-
def geodetic2eci(lat, lon, alt, t: datetime, ell: Ellipsoid = None, *, deg: bool = True) -> tuple:
447+
def geodetic2eci(lat, lon, alt, t: datetime, ell: Ellipsoid = ELL, *, deg: bool = True) -> tuple:
452448
"""
453449
convert geodetic coordinates to Earth Centered Internal ECI
454450
@@ -496,7 +492,7 @@ def enu2ecef(
496492
lat0,
497493
lon0,
498494
h0,
499-
ell: Ellipsoid = None,
495+
ell: Ellipsoid = ELL,
500496
deg: bool = True,
501497
) -> tuple:
502498
"""
@@ -532,6 +528,7 @@ def enu2ecef(
532528
z
533529
target z ECEF coordinate (meters)
534530
"""
531+
535532
x0, y0, z0 = geodetic2ecef(lat0, lon0, h0, ell, deg=deg)
536533
dx, dy, dz = enu2uvw(e1, n1, u1, lat0, lon0, deg=deg)
537534

src/pymap3d/ellipsoid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def __init__(
151151
}
152152

153153
@classmethod
154-
def from_name(cls, name: str) -> Ellipsoid | None:
154+
def from_name(cls, name: str) -> Ellipsoid:
155155
"""Create an Ellipsoid from a name."""
156156

157157
return cls(

src/pymap3d/enu.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
__all__ = ["enu2aer", "aer2enu", "enu2geodetic", "geodetic2enu"]
1616

17+
ELL = Ellipsoid.from_name("wgs84")
18+
1719

1820
def enu2aer(e, n, u, deg: bool = True) -> tuple:
1921
"""
@@ -115,7 +117,7 @@ def enu2geodetic(
115117
lat0,
116118
lon0,
117119
h0,
118-
ell: Ellipsoid = None,
120+
ell: Ellipsoid = ELL,
119121
deg: bool = True,
120122
) -> tuple:
121123
"""
@@ -163,7 +165,7 @@ def geodetic2enu(
163165
lat0,
164166
lon0,
165167
h0,
166-
ell: Ellipsoid = None,
168+
ell: Ellipsoid = ELL,
167169
deg: bool = True,
168170
) -> tuple:
169171
"""

0 commit comments

Comments
 (0)