Skip to content

Commit

Permalink
compare: fail code if mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Nov 24, 2023
1 parent f4e4424 commit b3eb0a9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion scripts/matlab/compare_ecef2eci.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@
else:
logging.error("eci2ecef did not match Matlab")

assert ecef_good and eci_good, "Matlab compare mismatch"
if not ecef_good and eci_good:
raise ValueError("compare_ecef2eci: Matlab compare mismatch")
4 changes: 3 additions & 1 deletion scripts/matlab/compare_lox.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ def reckon(lat1: float, lon1: float, rng: float, az: float) -> tuple[float, floa
logging.error(rstr)

if Nerr == 0:
print("lox_stability: comparison OK")
print("OK: lox_stability: comparison")
else:
raise ValueError("FAIL: lox_stability comparison")
32 changes: 17 additions & 15 deletions scripts/matlab/compare_vdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"""
Compare with Matlab Mapping Toolbox distance()
"""

from __future__ import annotations

import sys
import logging
from math import isclose, nan
import numpy as np

Expand All @@ -26,30 +27,31 @@ def distance(lat1, lon1, lat2, lon2) -> tuple[float, float]:

dlast, alast = nan, nan
lon1, lon2 = 0.0, 1.0
Nerr = 0
for i in range(20):
lat1 = lat2 = 10.0 ** (-i)

dist_m, az_deg = vdist(lat1, lon1, lat2, lon2)

assert dist_m != dlast
assert az_deg != alast
mat_match = True
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(
f"MISMATCH: latitude {lat1} {lat2}: Python: {dist_m} Matlab: {dist_matlab}",
file=sys.stderr,
)
if not isclose(az_matlab, az_deg):
mat_match = False
print(
f"MISMATCH: latitude {lat1} {lat2}: Python: {az_matlab} Matlab: {az_deg}",
file=sys.stderr,
)
if mat_match:
if isclose(dist_matlab, dist_m) and isclose(az_matlab, az_deg):
print(f"latitudes {lat1} {lat2}: {dist_m} meters {az_deg} deg azimuth")
else:
Nerr += 1
logging.error(
f"""MISMATCH: latitude {lat1} {lat2}
azimuth: Python: {az_matlab} Matlab: {az_deg}
distance: Python: {dist_m} Matlab: {dist_matlab}
"""
)

if Nerr == 0:
print("OK: vdist compare")
else:
raise ValueError("FAIL: vdist compare")

0 comments on commit b3eb0a9

Please sign in to comment.