Skip to content

Commit 3711962

Browse files
committed
CI template
typo test geodetic <> ecef correct singularity vers
1 parent f30e644 commit 3711962

File tree

9 files changed

+83
-34
lines changed

9 files changed

+83
-34
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
image:
22
- Visual Studio 2017
3-
- ubuntu1804
3+
- Ubuntu1804
44

55
stack: python 3
66

.coveragerc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[run]
2+
cover_pylib = false
3+
omit =
4+
/home/travis/virtualenv/*
5+
*/site-packages/*
6+
*/bin/*
7+
8+
[report]
9+
exclude_lines =
10+
pragma: no cover
11+
def __repr__
12+
except RuntimeError
13+
except NotImplementedError
14+
except ImportError
15+
except FileNotFoundError
16+
except CalledProcessError
17+
logging.warning
18+
logging.error
19+
logging.critical
20+
if __name__ == .__main__.:

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ matrix:
2020
- flake8
2121
- mypy . --ignore-missing-imports
2222
after_success:
23-
- pytest --cov --cov-config=setup.cfg
23+
- pytest --cov
2424
- coveralls
2525
- os: osx
2626
language: sh

pymap3d/ecef.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ def ecef2geodetic(x: float, y: float, z: float,
141141
huE = hypot(u, E)
142142

143143
# eqn. 4b
144-
Beta = arctan(huE / u * z / hypot(x, y))
144+
with np.errstate(divide='ignore'):
145+
Beta = arctan(huE / u * z / hypot(x, y))
145146

146147
# eqn. 13
147148
eps = ((ell.b * u - ell.a * huE + E**2) * sin(Beta)) / (ell.a * huE * 1 / cos(Beta) - E**2 * cos(Beta))

pymap3d/enu.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
__all__ = ['enu2aer', 'aer2enu', 'enu2geodetic', 'geodetic2enu']
1414

1515

16-
def enu2aer(e: float, n: float, u: float, deg: bool = True) -> Tuple[float, float, float]:
16+
def enu2aer(e: np.ndarray, n: np.ndarray, u: np.ndarray, deg: bool = True) -> Tuple[float, float, float]:
1717
"""
1818
ENU to Azimuth, Elevation, Range
1919
@@ -27,6 +27,17 @@ def enu2aer(e: float, n: float, u: float, deg: bool = True) -> Tuple[float, floa
2727
* azimuth, elevation (degrees/radians) [0,360),[0,90]
2828
* slant range [meters] [0,Infinity)
2929
"""
30+
# 1 millimeter precision for singularity
31+
32+
e = np.atleast_1d(e)
33+
n = np.atleast_1d(n)
34+
u = np.atleast_1d(u)
35+
36+
with np.errstate(invalid='ignore'):
37+
e[abs(e) < 1e-3] = 0.
38+
n[abs(n) < 1e-3] = 0.
39+
u[abs(u) < 1e-3] = 0.
40+
3041
r = hypot(e, n)
3142
slantRange = hypot(r, u)
3243
elev = arctan2(u, r)
@@ -36,7 +47,7 @@ def enu2aer(e: float, n: float, u: float, deg: bool = True) -> Tuple[float, floa
3647
az = degrees(az)
3748
elev = degrees(elev)
3849

39-
return az, elev, slantRange
50+
return az[()].squeeze(), elev[()].squeeze(), slantRange[()].squeeze()
4051

4152

4253
def aer2enu(az: float, el: float, srange: float, deg: bool = True) -> Tuple[float, float, float]:

pytest.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[pytest]
2+
minversion = 3.5
3+
4+
filterwarnings =
5+
ignore::DeprecationWarning
6+
7+

setup.cfg

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pymap3d
3-
version = 1.7.12
3+
version = 1.7.13
44
author = Michael Hirsch, Ph.D.
55
author_email = [email protected]
66
description = pure Python coordinate conversions, following convention of several popular Matlab routines.
@@ -56,34 +56,8 @@ console_scripts =
5656
vdist = vdist:main
5757
vreckon = vreckon:main
5858

59-
60-
61-
[tool:pytest]
62-
filterwarnings =
63-
ignore::DeprecationWarning
64-
6559
[flake8]
6660
max-line-length = 132
6761
ignore = E501, W504
6862
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/
6963

70-
[coverage:run]
71-
cover_pylib = false
72-
omit =
73-
/home/travis/virtualenv/*
74-
*/site-packages/*
75-
*/bin/*
76-
77-
[coverage:report]
78-
exclude_lines =
79-
pragma: no cover
80-
def __repr__
81-
except RuntimeError
82-
except NotImplementedError
83-
except ImportError
84-
except FileNotFoundError
85-
except CalledProcessError
86-
logging.warning
87-
logging.error
88-
logging.critical
89-
if __name__ == .__main__.:

tests/test_geodetic.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
import pytest
33
from pytest import approx
4-
import pymap3d as pm
54
from math import radians, nan
65
import numpy as np
76

7+
import pymap3d as pm
8+
89
lla0 = (42, -82, 200)
910
rlla0 = (radians(lla0[0]), radians(lla0[1]), lla0[2])
1011
lla1 = (42.002582, -81.997752, 1.1397018e3)
@@ -19,6 +20,8 @@
1920

2021
E = pm.Ellipsoid()
2122

23+
atol_dist = 1e-6 # 1 micrometer
24+
2225

2326
def test_ecef():
2427
xyz = pm.geodetic2ecef(*lla0)
@@ -36,7 +39,28 @@ def test_ecef():
3639
assert pm.ecef2geodetic(*xyz, deg=False) == approx(rlla0)
3740

3841
assert pm.ecef2geodetic((E.a - 1) / np.sqrt(2),
39-
(E.a - 1) / np.sqrt(2), 0)
42+
(E.a - 1) / np.sqrt(2), 0) == approx([0, 45, -1])
43+
44+
45+
@pytest.mark.parametrize('lla, xyz', [((0, 0, -1), (E.a - 1, 0, 0)),
46+
((0, 90, -1), (0, E.a - 1, 0)),
47+
((0, -90, -1), (0, -E.a + 1, 0)),
48+
((90, 0, -1), (0, 0, E.b - 1)),
49+
((90, 15, -1), (0, 0, E.b - 1)),
50+
((-90, 0, -1), (0, 0, -E.b + 1))
51+
])
52+
def test_geodetic2ecef(lla, xyz):
53+
assert pm.geodetic2ecef(*lla) == approx(xyz, abs=atol_dist)
54+
55+
56+
@pytest.mark.parametrize('xyz, lla', [((E.a - 1, 0, 0), (0, 0, -1)),
57+
((0, E.a - 1, 0), (0, 90, -1)),
58+
((0, 0, E.b - 1), (90, 0, -1)),
59+
((0, 0, -E.b + 1), (-90, 0, -1)),
60+
((-E.a + 1, 0, 0), (0, 180, -1)),
61+
])
62+
def test_ecef2geodetic(xyz, lla):
63+
assert pm.ecef2geodetic(*xyz) == approx(lla)
4064

4165

4266
def test_aer():

tests/test_main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
vx, vy, vz = (5, 3, 2)
3434
ve, vn, vu = (5.368859646588048, 3.008520763668120, -0.352347711524077)
3535

36+
E = pm.Ellipsoid()
37+
3638

3739
def test_losint():
3840
az = [0., 10., 125.]
@@ -69,6 +71,16 @@ def test_aer_ecef():
6971
assert pm.ecef2aer(*xyz, *rlla0, deg=False) == approx(raer0)
7072

7173

74+
@pytest.mark.parametrize('xyz, lla, aer', [((E.a - 1, 0, 0), (0, 0, 0), (0, -90, 1)),
75+
((-E.a + 1, 0, 0), (0, 180, 0), (0, -90, 1)),
76+
((0, E.a - 1, 0), (0, 90, 0), (0, -90, 1)),
77+
((0, -E.a + 1, 0), (0, -90, 0), (0, -90, 1)),
78+
((0, 0, E.b - 1), (90, 0, 0), (0, -90, 1)),
79+
((0, 0, -E.b + 1), (-90, 0, 0), (0, -90, 1)), ])
80+
def test_ecef2aer(xyz, lla, aer):
81+
assert pm.ecef2aer(*xyz, *lla) == approx(aer)
82+
83+
7284
def test_aer_enu():
7385
xyz = pm.aer2ecef(*aer0, *lla0)
7486

0 commit comments

Comments
 (0)