-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
debug:improve test coverage between matlab and python cases
typo complete rebase
- Loading branch information
Showing
8 changed files
with
198 additions
and
16 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
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
import ncarglow as glow | ||
import pytest | ||
from pytest import approx | ||
from datetime import datetime | ||
import numpy as np | ||
|
||
|
||
def test_simple(): | ||
time = datetime(2015, 12, 13, 10, 0, 0) | ||
glat = 65.1 | ||
glon = -147.5 | ||
# %% flux [erg cm-2 s-1 == mW m-2 s-1] | ||
Q = 1 | ||
# %% characteristic energy [eV] | ||
Echar = 100e3 | ||
# %% Number of energy bins | ||
Nbins = 250 | ||
|
||
try: | ||
iono = glow.simple(time, glat, glon, Q, Echar, Nbins) | ||
except ConnectionError: | ||
pytest.skip('CI internet FTP issue') | ||
|
||
assert iono['alt_km'].size == Nbins | ||
assert iono.alt_km[32] == approx(101.8) | ||
assert iono['Tn'][32] == approx(188.) | ||
assert iono['ver'].loc[:, '5577'][32] == approx(20.45) | ||
<<<<<<< HEAD | ||
assert iono['ionrate'][32] == approx(473.) | ||
======= | ||
assert iono['ionrate'][32] == approx(0.488) | ||
>>>>>>> db1f403... upgrade API for use as subproject | ||
|
||
|
||
def test_ebins(): | ||
time = datetime(2015, 12, 13, 10, 0, 0) | ||
glat = 65.1 | ||
glon = -147.5 | ||
# %% Energy grid [eV] | ||
Emin = 0.1 | ||
Emax = 1e6 | ||
E0 = 100e3 | ||
Nbins = 250 | ||
# %% monoenergetic beam | ||
Ebins = np.logspace(np.log10(Emin), np.log10(Emax), Nbins).astype(np.float32) | ||
Phitop = np.zeros_like(Ebins) | ||
Phitop[abs(Ebins-E0).argmin()] = 1. | ||
Phitop = Phitop.astype(np.float32) | ||
# %% run glow | ||
try: | ||
iono = glow.ebins(time, glat, glon, Ebins, Phitop) | ||
except ConnectionError: | ||
pytest.skip('CI internet FTP issue') | ||
|
||
assert iono['alt_km'].size == Nbins | ||
assert iono['Tn'][32] == approx(188.0) | ||
assert iono['ver'].loc[:, '5577'][32] == approx(0.04) | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main(['-r', 'a', '-v', __file__]) |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python | ||
import pytest | ||
import ncarglow.build as build | ||
from pathlib import Path | ||
|
||
R = Path(__file__).parent | ||
|
||
|
||
@pytest.mark.parametrize('build_sys', ['cmake', 'meson']) | ||
def test_build(build_sys, tmp_path): | ||
build.build(build_sys, R.parent, tmp_path) | ||
|
||
|
||
<<<<<<< HEAD | ||
======= | ||
def test_bad(tmp_path): | ||
with pytest.raises(ValueError): | ||
build.build('fake', R.parent, tmp_path) | ||
|
||
|
||
>>>>>>> db1f403... upgrade API for use as subproject | ||
if __name__ == '__main__': | ||
pytest.main(['-r', 'a', '-v', '-s', __file__]) |
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
r""" | ||
On Windows with Octave >= 5, you may need to add to PATH like: | ||
C:\Octave\Octave-5.1.0.0\mingw64\bin | ||
to get at octave.exe instead of octave.vbs | ||
""" | ||
from pathlib import Path | ||
import subprocess | ||
import pytest | ||
import shutil | ||
|
||
R = Path(__file__).parent | ||
Rcode = R.parent / 'matlab' | ||
|
||
OCTAVE = shutil.which('octave-cli') | ||
MATLAB = shutil.which('matlab') | ||
|
||
|
||
@pytest.mark.skipif(not OCTAVE, reason="GNU Octave not available") | ||
@pytest.mark.parametrize('build_sys', ['cmake', 'meson']) | ||
def test_octave_build(build_sys, tmp_path): | ||
subprocess.check_call([OCTAVE, '--eval', | ||
<<<<<<< HEAD | ||
f"setup('{build_sys}', '{R.parent}', '{tmp_path}')"], | ||
======= | ||
f"build('{build_sys}', '{R.parent}', '{tmp_path}')"], | ||
>>>>>>> db1f403... upgrade API for use as subproject | ||
cwd=Rcode, timeout=120) | ||
|
||
|
||
@pytest.mark.skipif(not MATLAB, reason="Matlab not available") | ||
@pytest.mark.parametrize('build_sys', ['cmake', 'meson']) | ||
def test_matlab_build(build_sys, tmp_path): | ||
subprocess.check_call([MATLAB, '-batch', | ||
<<<<<<< HEAD | ||
f"setup('{build_sys}', '{R.parent}', '{tmp_path}')"], | ||
======= | ||
f"build('{build_sys}', '{R.parent}', '{tmp_path}')"], | ||
>>>>>>> db1f403... upgrade API for use as subproject | ||
cwd=Rcode, timeout=120) | ||
|
||
|
||
@pytest.mark.skipif(not MATLAB, reason="Matlab not available") | ||
def test_matlab_api(): | ||
subprocess.check_call([MATLAB, '-batch', 'test_mod'], | ||
cwd=R, timeout=60) | ||
|
||
|
||
@pytest.mark.skipif(not OCTAVE, reason='octave not found') | ||
def test_octave_api(): | ||
subprocess.check_call([OCTAVE, 'test_mod.m'], | ||
cwd=R, timeout=60) | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main(['-r', 'a', '-v', '-s', __file__]) |
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
%% simple | ||
time = datenum(2015,12,13,10,0,0); | ||
glat = 65.1; | ||
glon = -147.5; | ||
Ap = 4; | ||
f107 = 100; | ||
f107a = 100; | ||
f107p = 100; | ||
Q = 1; | ||
Echar = 100e3; | ||
Nbins = 250; | ||
|
||
cwd = fileparts(mfilename('fullpath')); | ||
addpath([cwd, filesep, '..', filesep, 'matlab']) | ||
|
||
iono = glow(time, glat, glon, f107a, f107, f107p, Ap, Q, Echar, Nbins); | ||
|
||
<<<<<<< HEAD | ||
i = 32; | ||
|
||
assert(abs(iono.altkm(i) - 99.8) < 0.1, 'wrong altitude?') | ||
assert(abs(iono.Tn(i) - 188.) < 0.01, 'Tn error') | ||
assert(abs(iono.A5577(i) - 27.32) < 0.0001, 'A5577 error') | ||
assert(abs(iono.ionrate(i) - 473.) < 0.01, 'ionrate error') | ||
======= | ||
i = 32-1; | ||
|
||
assert(abs(iono.altkm(i) - 101.8) < 0.1, 'wrong altitude?') | ||
assert(abs(iono.Tn(i) - 188.) < 0.01, 'Tn error') | ||
assert(abs(iono.A5577(i) - 20.45) < 0.0001, 'A5577 error') | ||
assert(abs(iono.ionrate(i) - 0.488) < 0.01, 'ionrate error') | ||
>>>>>>> db1f403... upgrade API for use as subproject |