-
-
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 pure Python linspace()
- Loading branch information
Showing
5 changed files
with
155 additions
and
78 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
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.0, 80.0 | ||
lat2, lon2 = 0.0, 81.0 | ||
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 pymap3d.vincenty as vincenty | ||
|
||
from math import radians | ||
|
||
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.0, 80.0 | ||
lat2, lon2 = 0.0, 81.0 | ||
lat0 = [0.0, 0.0, 0.0, 0.0] | ||
lon0 = [80.0, 80.33333, 80.66666, 81.0] | ||
if not deg: | ||
lat1, lon1, lat2, lon2 = map(radians, (lat1, lon1, lat2, lon2)) | ||
lat0 = map(radians, lat0) | ||
lon0 = map(radians, 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
Oops, something went wrong.