Skip to content

Commit

Permalink
compare_vdist: check outputs for real
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Nov 15, 2022
1 parent e047f54 commit 0114898
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Examples/compare/compare_ecef2eci.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

def test_ecef_eci():

ecef = [-5762640, -1682738, 3156028]
ecef = [-5762640.0, -1682738.0, 3156028.0]
utc = datetime(2019, 1, 4, 12)

eci = ecef2eci(*ecef, utc)

utc_matlab = eng.datetime(utc.year, utc.month, utc.day, utc.hour, utc.minute, utc.second)
if has_aero:
eci_matlab = eng.ecef2eci(utc_matlab, *ecef, nargout=3) # type: ignore
eci_matlab = eng.ecef2eci(utc_matlab, *ecef, nargout=3)
else:
eci_matlab = eng.matmap3d.ecef2eci(utc_matlab, *ecef, nargout=3) # type: ignore
eci_matlab = eng.matmap3d.ecef2eci(utc_matlab, *ecef, nargout=3)

assert eci == approx(eci_matlab, rel=0.01)

Expand Down
2 changes: 1 addition & 1 deletion Examples/compare/compare_lox.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def reckon(lat1: float, lon1: float, rng: float, az: float) -> tuple[float, float]:
"""Using Matlab Engine to do same thing as Pymap3d"""
if has_map:
return eng.reckon("rh", lat1, lon1, rng, az, eng.wgs84Ellipsoid(), nargout=2) # type: ignore
return eng.reckon("rh", lat1, lon1, rng, az, eng.wgs84Ellipsoid(), nargout=2)
else:
return eng.matmap3d.vreckon(lat1, lon1, rng, az, nargout=2)

Expand Down
26 changes: 17 additions & 9 deletions Examples/compare/compare_vdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@

import sys
from math import isclose, nan
import numpy as np
from pathlib import Path

from matlab_mapping import matlab_mapping

import matlab.engine
from pymap3d.vincenty import vdist

cwd = Path(__file__).parent
eng = None # don't start Matlab engine over and over when script is interactive

if eng is None:
eng = matlab.engine.start_matlab("-nojvm")
eng.addpath(eng.genpath(str(cwd)), nargout=0)
eng = matlab.engine.start_matlab("-nojvm")
eng.addpath(eng.genpath(str(cwd)), nargout=0)

if not eng.has_map_toolbox():
raise EnvironmentError("Matlab does not have Mapping Toolbox")
has_map = matlab_mapping(eng)


def matlab_func(lat1, lon1, lat2, lon2) -> tuple[float, float]:
def distance(lat1, lon1, lat2, lon2) -> tuple[float, float]:
"""Using Matlab Engine to do same thing as Pymap3d"""
return eng.distance(lat1, lon1, lat2, lon2, eng.wgs84Ellipsoid(), nargout=2) # type: ignore

if has_map:
return eng.distance(lat1, lon1, lat2, lon2, eng.wgs84Ellipsoid(), nargout=2)
else:
return eng.matmap3d.vdist(lat1, lon1, lat2, lon2, nargout=2)


dlast, alast = nan, nan
Expand All @@ -34,7 +38,11 @@ def matlab_func(lat1, lon1, lat2, lon2) -> tuple[float, float]:
assert dist_m != dlast
assert az_deg != alast
mat_match = True
dist_matlab, az_matlab = matlab_func(lat1, lon1, lat2, lon2)
dist_matlab, az_matlab = distance(lat1, lon1, lat2, lon2)

assert np.isreal(dist_m), f"Python vdist distance is not real for input latitude {lat1}"
assert np.isreal(dist_matlab), f"Matlab distance is not real for input latitude {lat1}"

if not isclose(dist_matlab, dist_m):
mat_match = False
print(
Expand Down
6 changes: 3 additions & 3 deletions Examples/compare/matlab_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
def matlab_mapping(eng: matlab.engine.matlabengine.MatlabEngine) -> bool:

if eng.has_map_toolbox():
has_aero = True
has = True
else:
has_aero = False
has = False

cwd = Path(__file__).parent
d = cwd.parents[2] / "matmap3d"
Expand All @@ -17,4 +17,4 @@ def matlab_mapping(eng: matlab.engine.matlabengine.MatlabEngine) -> bool:
else:
raise EnvironmentError(f"Matlab {eng.version()} does not have Mapping Toolbox")

return has_aero
return has

0 comments on commit 0114898

Please sign in to comment.