-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vdist, vreckon: add deg= option (default true)
track2: correct deg=False radians
- Loading branch information
Showing
3 changed files
with
135 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Compare with Matlab Mapping toolbox reckon() | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
from pytest import approx | ||
|
||
try: | ||
import numpy as np | ||
from .matlab_engine import matlab_engine, has_mapping | ||
except ImportError: | ||
pytest.skip("Matlab Engine not found", allow_module_level=True) | ||
|
||
|
||
import pymap3d.vincenty | ||
|
||
|
||
def track2(eng, lat1: float, lon1: float, lat2: float, lon2: float, npts: int, deg: bool) -> tuple: | ||
"""Using Matlab Engine to do same thing as Pymap3d""" | ||
d = "degrees" if deg else "radians" | ||
|
||
lats, lons = eng.track2( | ||
"gc", lat1, lon1, lat2, lon2, eng.wgs84Ellipsoid(), d, float(npts), nargout=2 | ||
) | ||
return np.array(lats).squeeze(), np.array(lons).squeeze() | ||
|
||
|
||
@pytest.mark.parametrize("deg", [True, False]) | ||
def test_track2_compare(deg): | ||
lat1, lon1 = 0., 80. | ||
lat2, lon2 = 0., 81. | ||
if not deg: | ||
lat1, lon1, lat2, lon2 = np.radians((lat1, lon1, lat2, lon2)) | ||
|
||
eng = matlab_engine() | ||
|
||
if not has_mapping(eng): | ||
pytest.skip("Matlab Toolbox not found") | ||
|
||
lats, lons = pymap3d.vincenty.track2(lat1, lon1, lat2, lon2, npts=4, deg=deg) | ||
|
||
lats_m, lons_m = track2(eng, lat1, lon1, lat2, lon2, npts=4, deg=deg) | ||
|
||
assert lats == approx(lats_m) | ||
assert lons == approx(lons_m) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
import numpy as np | ||
|
||
import pymap3d.vincenty as vincenty | ||
|
||
import pytest | ||
from pytest import approx | ||
|
||
|
||
def test_track2(): | ||
lats, lons = vincenty.track2(40, 80, 65, -148, npts=3) | ||
assert lats == approx([40, 69.633139886, 65]) | ||
assert lons == approx([80, 113.06849104, -148]) | ||
@pytest.mark.parametrize("deg", [True, False]) | ||
def test_track2_unit(deg): | ||
|
||
pytest.importorskip("numpy") | ||
|
||
lat1, lon1 = 0., 80. | ||
lat2, lon2 = 0., 81. | ||
lat0 = [0., 0., 0., 0.] | ||
lon0 = [80., 80.33333, 80.66666, 81.] | ||
if not deg: | ||
lat1, lon1, lat2, lon2 = np.radians((lat1, lon1, lat2, lon2)) | ||
lat0, lon0 = np.radians((lat0, lon0)) | ||
|
||
lats, lons = vincenty.track2(lat1, lon1, lat2, lon2, npts=4, deg=deg) | ||
|
||
assert lats == approx(lat0) | ||
assert lons == approx(lon0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters