Skip to content

Commit

Permalink
Ellipsoid: canonical default instead of None
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Feb 11, 2024
1 parent f3a3a53 commit 0bb4350
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 184 deletions.
6 changes: 4 additions & 2 deletions Examples/plot_geodetic2ecef.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations
import typing
import argparse

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


def panel(ax, val, name: str, cmap: str = None):
def panel(ax, val, name: str, cmap: str | None = None):
hi = ax.pcolormesh(lon, lat, val, cmap=cmap)
ax.set_title(name)
fg.colorbar(hi, ax=ax).set_label(name + " [m]")
ax.set_xlabel("longitude [deg]")


fg = mpl.figure(figsize=(16, 5))
axs = fg.subplots(1, 3, sharey=True)
axs: typing.Any = fg.subplots(1, 3, sharey=True)
fg.suptitle("geodetic2ecef")

panel(axs[0], x, "x", "bwr")
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ known_third_party = ["pymap3d"]
files = ["src", "Examples", "scripts"]

ignore_missing_imports = true
strict_optional = false
show_column_numbers = true

[tool.coverage.run]
branch = true
Expand Down
2 changes: 1 addition & 1 deletion src/pymap3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Fortran: [Maptran3D](https://github.com/geospace-code/maptran3d)
"""

__version__ = "3.0.1"
__version__ = "3.1.0"

from .aer import aer2ecef, aer2geodetic, ecef2aer, geodetic2aer
from .ecef import (
Expand Down
12 changes: 7 additions & 5 deletions src/pymap3d/aer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

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

ELL = Ellipsoid.from_name("wgs84")


def ecef2aer(
x,
Expand All @@ -23,7 +25,7 @@ def ecef2aer(
lat0,
lon0,
h0,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down Expand Up @@ -72,7 +74,7 @@ def geodetic2aer(
lat0,
lon0,
h0,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down Expand Up @@ -120,7 +122,7 @@ def aer2geodetic(
lat0,
lon0,
h0,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down Expand Up @@ -213,7 +215,7 @@ def aer2eci(
lon0,
h0,
t: datetime,
ell=None,
ell: Ellipsoid = ELL,
*,
deg: bool = True,
) -> tuple:
Expand Down Expand Up @@ -269,7 +271,7 @@ def aer2ecef(
lat0,
lon0,
alt0,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down
27 changes: 12 additions & 15 deletions src/pymap3d/ecef.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from .ellipsoid import Ellipsoid
from .mathfun import atan, atan2, cos, degrees, hypot, isclose, radians, sin, sqrt, tan
from .utils import sanitize

__all__ = [
"geodetic2ecef",
Expand All @@ -30,12 +29,14 @@
"enu2ecef",
]

ELL = Ellipsoid.from_name("wgs84")


def geodetic2ecef(
lat,
lon,
alt,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down Expand Up @@ -68,8 +69,9 @@ def geodetic2ecef(
z
target z ECEF coordinate (meters)
"""
lat, ell = sanitize(lat, ell, deg)

if deg:
lat = radians(lat)
lon = radians(lon)

# radius of curvature of the prime vertical section
Expand All @@ -88,7 +90,7 @@ def ecef2geodetic(
x,
y,
z,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down Expand Up @@ -121,9 +123,6 @@ def ecef2geodetic(
Journal of Surveying Engineering. doi: 10.1061/(ASCE)0733-9453
"""

if ell is None:
ell = Ellipsoid.from_name("wgs84")

try:
x = asarray(x)
y = asarray(y)
Expand Down Expand Up @@ -167,10 +166,7 @@ def ecef2geodetic(
# eqn. 13
Beta += (
(ell.semiminor_axis * u - ell.semimajor_axis * huE + E**2) * sin(Beta)
) / (
ell.semimajor_axis * huE * 1 / cos(Beta)
- E**2 * cos(Beta)
)
) / (ell.semimajor_axis * huE * 1 / cos(Beta) - E**2 * cos(Beta))
except (ArithmeticError, RuntimeWarning):
if isclose(z, 0):
Beta = 0
Expand Down Expand Up @@ -281,7 +277,7 @@ def ecef2enu(
lat0,
lon0,
h0,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down Expand Up @@ -407,7 +403,7 @@ def uvw2enu(u, v, w, lat0, lon0, deg: bool = True) -> tuple:
return East, North, Up


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


def geodetic2eci(lat, lon, alt, t: datetime, ell: Ellipsoid = None, *, deg: bool = True) -> tuple:
def geodetic2eci(lat, lon, alt, t: datetime, ell: Ellipsoid = ELL, *, deg: bool = True) -> tuple:
"""
convert geodetic coordinates to Earth Centered Internal ECI
Expand Down Expand Up @@ -496,7 +492,7 @@ def enu2ecef(
lat0,
lon0,
h0,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down Expand Up @@ -532,6 +528,7 @@ def enu2ecef(
z
target z ECEF coordinate (meters)
"""

x0, y0, z0 = geodetic2ecef(lat0, lon0, h0, ell, deg=deg)
dx, dy, dz = enu2uvw(e1, n1, u1, lat0, lon0, deg=deg)

Expand Down
2 changes: 1 addition & 1 deletion src/pymap3d/ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def __init__(
}

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

return cls(
Expand Down
6 changes: 4 additions & 2 deletions src/pymap3d/enu.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

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

ELL = Ellipsoid.from_name("wgs84")


def enu2aer(e, n, u, deg: bool = True) -> tuple:
"""
Expand Down Expand Up @@ -115,7 +117,7 @@ def enu2geodetic(
lat0,
lon0,
h0,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down Expand Up @@ -163,7 +165,7 @@ def geodetic2enu(
lat0,
lon0,
h0,
ell: Ellipsoid = None,
ell: Ellipsoid = ELL,
deg: bool = True,
) -> tuple:
"""
Expand Down
Loading

0 comments on commit 0bb4350

Please sign in to comment.