Skip to content

Commit

Permalink
Add Bepi/SIXS to unit test
Browse files Browse the repository at this point in the history
Add Bepi/SIXS to unit test
  • Loading branch information
jgieseler authored Mar 26, 2024
2 parents d06aae8 + 08b9bc5 commit dcd535f
Show file tree
Hide file tree
Showing 7 changed files with 1,248 additions and 20 deletions.
402 changes: 402 additions & 0 deletions seppy/data/test/20230719_side0.csv

Large diffs are not rendered by default.

402 changes: 402 additions & 0 deletions seppy/data/test/20230719_side1.csv

Large diffs are not rendered by default.

402 changes: 402 additions & 0 deletions seppy/data/test/20230719_side2.csv

Large diffs are not rendered by default.

Binary file not shown.
23 changes: 12 additions & 11 deletions seppy/tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ def test_psp_load_online():
assert np.sum(np.isnan(df3['H_Flux_ChanP_E46_P79'])) == 57


def test_psp_load_offline():
# offline data files need to be replaced if data "version" is updated!
fullpath = get_pkg_data_filename('data/test/psp_isois-epihi_l2-het-rates60_20210531_v15.cdf', package='seppy')
path = Path(fullpath).parent.as_posix()
df, meta = psp_isois_load(dataset='PSP_ISOIS-EPIHI_L2-HET-RATES60', startdate="2021/05/31",
enddate="2021/06/01", path=path, resample="1min")
assert isinstance(df, pd.DataFrame)
assert df.shape == (48, 136)
assert meta['H_ENERGY_LABL'][0][0] == ' 6.7 - 8.0 MeV'
# Check that fillvals are replaced by NaN
assert np.sum(np.isnan(df['B_H_Uncertainty_14'])) == 48
# deactivate testing of PSP offline loading bc. the version is changing so often (JG 2024/03/26)
# def test_psp_load_offline():
# # offline data files need to be replaced if data "version" is updated!
# fullpath = get_pkg_data_filename('data/test/psp_isois-epihi_l2-het-rates60_20210531_v19.cdf', package='seppy')
# path = Path(fullpath).parent.as_posix()
# df, meta = psp_isois_load(dataset='PSP_ISOIS-EPIHI_L2-HET-RATES60', startdate="2021/05/31",
# enddate="2021/06/01", path=path, resample="1min")
# assert isinstance(df, pd.DataFrame)
# assert df.shape == (48, 136)
# assert meta['H_ENERGY_LABL'][0][0] == ' 6.7 - 8.0 MeV'
# # Check that fillvals are replaced by NaN
# assert np.sum(np.isnan(df['B_H_Uncertainty_14'])) == 48


def test_soho_ephin_load_online():
Expand Down
35 changes: 28 additions & 7 deletions seppy/tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from astropy.utils.data import get_pkg_data_filename
from pathlib import Path
from seppy.tools import Event
Expand Down Expand Up @@ -440,12 +439,15 @@ def test_onset_spectrum_tsa_SOHO_EPHIN_online():
# no channel combination inlcuded for SOHO/EPHIN electrons, yet

# test dynamic spectrum:
check = False
try:
Event1.dynamic_spectrum(view=None)
except Warning:
check = True
assert check
# check = False
# try:
# Event1.dynamic_spectrum(view=None)
# except Warning:
# check = True
# assert check
Event1.dynamic_spectrum(view=None)
assert Event1.fig.get_axes()[0].get_title() == 'SOHO/EPHIN electrons, 2021-10-28'


# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Expand Down Expand Up @@ -515,3 +517,22 @@ def test_dynamic_spectrum_SOHO_ERNE_offline():
Event1.dynamic_spectrum(view=None)

assert Event1.fig.get_axes()[0].get_title() == 'SOHO/ERNE protons, 2021-10-28'


def test_onset_Bepi_SIXS_offline():
startdate = datetime.date(2023, 7, 19)
enddate = datetime.date(2023, 7, 19)
fullpath = get_pkg_data_filename('data/test/20230719_side1.csv', package='seppy')
lpath = Path(fullpath).parent.as_posix()
# lpath = '/home/jagies/data/bepi/bc_mpo_sixs/data_csv/cruise/sixs-p/raw'
Event1 = Event(spacecraft='Bepi', sensor='SIXS', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath, viewing='1')
background_range = (datetime.datetime(2023, 7, 19, 0, 30, 0), datetime.datetime(2023, 7, 19, 1, 30, 0))
flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='1', background_range=background_range, channels=2, resample_period="1min", yscale='log', cusum_window=30)

assert isinstance(flux, pd.Series)
assert flux.shape == (161,)
assert len(onset_stats) == 6
assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType)
assert ~onset_found
assert peak_time.isoformat().split('.')[0] == '2023-07-19T02:25:42'
assert fig.get_axes()[0].get_title() == 'BEPI/SIXS 106 keV electrons\n1min averaging, viewing: 1'
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{37,38,39,310}-test
py{38,39,310}-test
build_docs
codestyle
isolated_build = true
Expand All @@ -9,7 +9,7 @@ skip_missing_interpreters = True

[testenv]
# Pass through the following environemnt variables which may be needed for the CI
passenv = HOME WINDIR LC_ALL LC_CTYPE CC CI TRAVIS
passenv = HOME, WINDIR, LC_ALL, LC_CTYPE, CC, CI, TRAVIS

# Run the tests in a temporary directory to make sure that we don't import
# the package from the source tree
Expand Down

0 comments on commit dcd535f

Please sign in to comment.