diff --git a/.gitattributes b/.gitattributes index e88485c..f9131c9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,21 +1,3 @@ archive/* linguist-documentation docs/* linguist-documentation paper/* linguist-documentation - -.gitattributes text eol=lf -.gitignore text eol=lf -Makefile text eol=lf -*.yml text eol=lf -LICENSE text eol=lf -*.ipynb text eol=lf -*.txt text eol=lf -*.py text eol=lf -*.sh text eol=lf -*.c text eol=lf -*.cpp text eol=lf -*.f text eol=lf -*.f90 text eol=lf -*.md text eol=lf -*.rst text eol=lf -*.csv text eol=lf -*.m text eol=lf diff --git a/Examples/compare/compare_ecef2eci.py b/scripts/compare/compare_ecef2eci.py similarity index 81% rename from Examples/compare/compare_ecef2eci.py rename to scripts/compare/compare_ecef2eci.py index 10bcdc6..efc66de 100644 --- a/Examples/compare/compare_ecef2eci.py +++ b/scripts/compare/compare_ecef2eci.py @@ -1,21 +1,14 @@ #!/usr/bin/env python3 from __future__ import annotations -from pathlib import Path from datetime import datetime + from pytest import approx -import matlab.engine from pymap3d.eci import ecef2eci, eci2ecef from matlab_aerospace import matlab_aerospace - -cwd = Path(__file__).parent - -eng = matlab.engine.start_matlab("-nojvm") -eng.addpath(eng.genpath(str(cwd)), nargout=0) - -has_aero = matlab_aerospace(eng) +from matlab_engine import matlab_engine def test_ecef_eci(): @@ -24,8 +17,10 @@ def test_ecef_eci(): eci = ecef2eci(*ecef, utc) + eng = matlab_engine() + utc_matlab = eng.datetime(utc.year, utc.month, utc.day, utc.hour, utc.minute, utc.second) - if has_aero: + if matlab_aerospace(eng): eci_matlab = eng.ecef2eci(utc_matlab, *ecef, nargout=3) else: eci_matlab = eng.matmap3d.ecef2eci(utc_matlab, *ecef, nargout=3) @@ -36,7 +31,7 @@ def test_ecef_eci(): ecef = eci2ecef(*eci_matlab, utc) - if has_aero: + 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) diff --git a/Examples/compare/compare_lox.py b/scripts/compare/compare_lox.py similarity index 84% rename from Examples/compare/compare_lox.py rename to scripts/compare/compare_lox.py index 9ca2c2a..79e1a1d 100644 --- a/Examples/compare/compare_lox.py +++ b/scripts/compare/compare_lox.py @@ -3,24 +3,18 @@ import logging from math import isclose -from pathlib import Path +from matlab_engine import matlab_engine from matlab_mapping import matlab_mapping -import matlab.engine from pymap3d.lox import loxodrome_direct -cwd = Path(__file__).parent -eng = matlab.engine.start_matlab("-nojvm") -eng.addpath(eng.genpath(str(cwd)), nargout=0) - -has_map = matlab_mapping(eng) - - 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: + + eng = matlab_engine() + if matlab_mapping(eng): return eng.reckon("rh", lat1, lon1, rng, az, eng.wgs84Ellipsoid(), nargout=2) else: return eng.matmap3d.vreckon(lat1, lon1, rng, az, nargout=2) diff --git a/Examples/compare/compare_vdist.py b/scripts/compare/compare_vdist.py similarity index 87% rename from Examples/compare/compare_vdist.py rename to scripts/compare/compare_vdist.py index 8c764e4..267e327 100644 --- a/Examples/compare/compare_vdist.py +++ b/scripts/compare/compare_vdist.py @@ -4,25 +4,19 @@ import sys from math import isclose, nan import numpy as np -from pathlib import Path +from matlab_engine import matlab_engine from matlab_mapping import matlab_mapping -import matlab.engine from pymap3d.vincenty import vdist -cwd = Path(__file__).parent - -eng = matlab.engine.start_matlab("-nojvm") -eng.addpath(eng.genpath(str(cwd)), nargout=0) - -has_map = matlab_mapping(eng) - def distance(lat1, lon1, lat2, lon2) -> tuple[float, float]: """Using Matlab Engine to do same thing as Pymap3d""" - if has_map: + eng = matlab_engine() + + if matlab_mapping(eng): return eng.distance(lat1, lon1, lat2, lon2, eng.wgs84Ellipsoid(), nargout=2) else: return eng.matmap3d.vdist(lat1, lon1, lat2, lon2, nargout=2) diff --git a/Examples/compare/has_aerospace_toolbox.m b/scripts/compare/has_aerospace_toolbox.m similarity index 100% rename from Examples/compare/has_aerospace_toolbox.m rename to scripts/compare/has_aerospace_toolbox.m diff --git a/Examples/compare/has_map_toolbox.m b/scripts/compare/has_map_toolbox.m similarity index 100% rename from Examples/compare/has_map_toolbox.m rename to scripts/compare/has_map_toolbox.m diff --git a/Examples/compare/matlab_aerospace.py b/scripts/compare/matlab_aerospace.py similarity index 93% rename from Examples/compare/matlab_aerospace.py rename to scripts/compare/matlab_aerospace.py index c60d664..df074f3 100644 --- a/Examples/compare/matlab_aerospace.py +++ b/scripts/compare/matlab_aerospace.py @@ -1,8 +1,10 @@ from pathlib import Path +import functools import matlab.engine +@functools.cache def matlab_aerospace(eng: matlab.engine.matlabengine.MatlabEngine) -> bool: if eng.has_aerospace_toolbox(): has_aero = True diff --git a/scripts/compare/matlab_engine.py b/scripts/compare/matlab_engine.py new file mode 100644 index 0000000..8d336cf --- /dev/null +++ b/scripts/compare/matlab_engine.py @@ -0,0 +1,12 @@ +import functools +from pathlib import Path + +import matlab.engine + + +@functools.cache +def matlab_engine(): + cwd = Path(__file__).parent + eng = matlab.engine.start_matlab("-nojvm") + eng.addpath(eng.genpath(str(cwd)), nargout=0) + return eng diff --git a/Examples/compare/matlab_mapping.py b/scripts/compare/matlab_mapping.py similarity index 100% rename from Examples/compare/matlab_mapping.py rename to scripts/compare/matlab_mapping.py