Skip to content

Commit

Permalink
move compare to scripts/compare
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Nov 20, 2023
1 parent e0b7d86 commit b41016f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 49 deletions.
18 changes: 0 additions & 18 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 4 additions & 10 deletions Examples/compare/compare_lox.py → scripts/compare/compare_lox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions scripts/compare/matlab_engine.py
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.

0 comments on commit b41016f

Please sign in to comment.