-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compare ecef2eci: run all tests, print details
- Loading branch information
Showing
2 changed files
with
26 additions
and
22 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 |
---|---|---|
@@ -1,45 +1,49 @@ | ||
#!/usr/bin/env python3 | ||
from __future__ import annotations | ||
|
||
import logging | ||
from datetime import datetime | ||
|
||
from pytest import approx | ||
import numpy as np | ||
|
||
from pymap3d.eci import ecef2eci, eci2ecef | ||
|
||
from matlab_aerospace import matlab_aerospace | ||
from matlab_engine import matlab_engine | ||
|
||
|
||
def test_ecef_eci(): | ||
ecef = [-5762640.0, -1682738.0, 3156028.0] | ||
utc = datetime(2019, 1, 4, 12) | ||
ecef = [-5762640.0, -1682738.0, 3156028.0] | ||
utc = datetime(2019, 1, 4, 12) | ||
|
||
eci = ecef2eci(*ecef, utc) | ||
eci_py = ecef2eci(ecef[0], ecef[1], ecef[2], utc) | ||
|
||
eng = matlab_engine() | ||
eng = matlab_engine() | ||
|
||
utc_matlab = eng.datetime(utc.year, utc.month, utc.day, utc.hour, utc.minute, utc.second) | ||
if matlab_aerospace(eng): | ||
eci_matlab = eng.ecef2eci(utc_matlab, *ecef, nargout=3) | ||
else: | ||
eci_matlab = eng.matmap3d.ecef2eci(utc_matlab, *ecef, nargout=3) | ||
utc_matlab = eng.datetime(utc.year, utc.month, utc.day, utc.hour, utc.minute, utc.second) | ||
if matlab_aerospace(eng): | ||
eci_matlab = eng.ecef2eci(utc_matlab, np.array(ecef), nargout=3) | ||
else: | ||
eci_matlab = eng.matmap3d.ecef2eci(utc_matlab, *ecef, nargout=3) | ||
|
||
assert eci == approx(eci_matlab, rel=0.01) | ||
eci_good = np.isclose(eci_py, eci_matlab, rtol=0.01).all() | ||
|
||
if eci_good: | ||
print("OK: PyMap3d ecef2eci vs. Matlab ecef2eci") | ||
else: | ||
logging.error("eci2ecef did not match Matlab") | ||
|
||
ecef = eci2ecef(*eci_matlab, utc) | ||
ecef_py = eci2ecef(eci_matlab[0], eci_matlab[1], eci_matlab[2], utc) | ||
|
||
if matlab_aerospace(eng): | ||
ecef_matlab = eng.eci2ecef(utc_matlab, *eci_matlab, nargout=3) | ||
else: | ||
ecef_matlab = eng.matmap3d.eci2ecef(utc_matlab, *eci_matlab, nargout=3) | ||
if matlab_aerospace(eng): | ||
ecef_matlab = eng.eci2ecef(utc_matlab, *eci_matlab, nargout=3) | ||
else: | ||
ecef_matlab = eng.matmap3d.eci2ecef(utc_matlab, *eci_matlab, nargout=3) | ||
|
||
assert ecef == approx(ecef_matlab, rel=0.02) | ||
ecef_good = np.isclose(ecef_py, ecef_matlab, rtol=0.02).all() | ||
|
||
if ecef_good: | ||
print("OK: PyMap3d eci2ecef vs. Matlab eci2ecef") | ||
else: | ||
logging.error("eci2ecef did not match Matlab") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_ecef_eci() | ||
assert ecef_good and eci_good, "Matlab compare mismatch" |
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