Skip to content

Commit

Permalink
Merge pull request #51 from jgieseler/main
Browse files Browse the repository at this point in the history
Extend testing
  • Loading branch information
jgieseler authored Feb 6, 2024
2 parents 1be7097 + 3677f2c commit a2d326f
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -39,6 +39,6 @@ jobs:
run: |
pytest --cov .
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
astropy
astroquery
bs4
cdflib>=0.4.9
datetime
Expand Down
180 changes: 159 additions & 21 deletions seppy/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from seppy.tools import Event
import datetime
import os
import matplotlib.pyplot as plt
import pandas as pd


# TODO: test dynamic spectrum for all dataset
# TODO: test tsa for all dataset
# TODO: test print(Event1.print_energies()) after it has been fixed


def test_onset_SOLO_STEP_ions_old_data_online():
def test_onset_spectrum_tsa_SOLO_STEP_ions_old_data_online():
startdate = datetime.date(2020, 9, 21)
enddate = datetime.date(2020, 9, 21)
lpath = f"{os.getcwd()}/data/"
Expand All @@ -37,8 +37,17 @@ def test_onset_SOLO_STEP_ions_old_data_online():
check = True
assert check

# test dynamic spectrum:
Event1.dynamic_spectrum(view='Pixel averaged')
assert Event1.fig.get_axes()[0].get_title() == 'SOLO/STEP (Pixel averaged) ions, 2020-09-21'

def test_onset_SOLO_STEP_ions_new_data_online():
# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot('Pixel averaged', selection=(0, 4, 1), resample='1min')
assert plt.figure(1).get_axes()[0].get_title() == 'Solar Orbiter STEP, ions'


def test_onset_spectrum_tsa_SOLO_STEP_ions_new_data_online():
startdate = datetime.date(2022, 1, 9)
enddate = datetime.date(2022, 1, 9)
lpath = f"{os.getcwd()}/data/"
Expand All @@ -65,8 +74,19 @@ def test_onset_SOLO_STEP_ions_new_data_online():
assert peak_time.isoformat().split('.')[0] == '2022-01-09T00:02:30'
assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0061 - 0.0091 MeV protons\n5min averaging, viewing: PIXEL 8'

# test dynamic spectrum:
Event1.dynamic_spectrum(view='Pixel averaged')
assert Event1.fig.get_axes()[0].get_title() == 'SOLO/STEP (Pixel averaged) ions, 2022-01-09'
Event1.dynamic_spectrum(view='Pixel 8')
assert Event1.fig.get_axes()[0].get_title() == 'SOLO/STEP (Pixel 8) ions, 2022-01-09'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot('Pixel 8', selection=(0, 4, 1), resample='1min')
assert plt.figure(1).get_axes()[0].get_title() == 'Solar Orbiter STEP, ions'

def test_onset_SOLO_HET_online():

def test_onset_spectrum_tsa_SOLO_HET_online():
startdate = datetime.date(2022, 11, 8)
enddate = datetime.date(2022, 11, 8)
lpath = f"{os.getcwd()}/data/"
Expand Down Expand Up @@ -94,8 +114,17 @@ def test_onset_SOLO_HET_online():
assert peak_time.isoformat().split('.')[0] == '2022-11-08T22:27:54'
assert fig.get_axes()[0].get_title() == 'SOLO/HET 0.4533 - 18.8300 MeV electrons\n5min averaging, viewing: NORTH'

# test dynamic spectrum:
Event1.dynamic_spectrum(view='sun')
assert Event1.fig.get_axes()[0].get_title() == 'SOLO/HET (sun) electrons, 2022-11-08'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot('north', selection=None, resample='1min')
assert plt.figure(1).get_axes()[0].get_title() == 'Solar Orbiter HET, electrons'


def test_onset_SOLO_EPT_online():
def test_onset_spectrum_tsa_SOLO_EPT_online():
startdate = datetime.date(2022, 6, 6)
enddate = datetime.date(2022, 6, 6)
lpath = f"{os.getcwd()}/data/"
Expand Down Expand Up @@ -123,8 +152,17 @@ def test_onset_SOLO_EPT_online():
assert peak_time.isoformat().split('.')[0] == '2022-06-06T23:02:30'
assert fig.get_axes()[0].get_title() == 'SOLO/EPT 0.0334 - 0.0439 MeV electrons\n5min averaging, viewing: NORTH'

# test dynamic spectrum:
Event1.dynamic_spectrum(view='sun')
assert Event1.fig.get_axes()[0].get_title() == 'SOLO/EPT (sun) electrons, 2022-06-06'

def test_onset_PSP_ISOIS_EPIHI_online():
# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot('sun', selection=(0, 4, 1), resample='1min')
assert plt.figure(1).get_axes()[0].get_title() == 'Solar Orbiter EPT, electrons'


def test_onset_spectrum_tsa_PSP_ISOIS_EPIHI_online():
startdate = datetime.date(2021, 10, 28)
enddate = datetime.date(2021, 10, 29)
lpath = f"{os.getcwd()}/data/"
Expand Down Expand Up @@ -152,8 +190,17 @@ def test_onset_PSP_ISOIS_EPIHI_online():
assert peak_time.isoformat().split('.')[0] == '2021-10-28T19:56:59'
assert fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPIHI 8.0 - 19.0 MeV protons\n5min averaging, viewing: B'

# test dynamic spectrum:
Event1.dynamic_spectrum(view='A')
assert Event1.fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPIHI (A) protons, 2021-10-28'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot('A', selection=(0, 4, 1), resample='1min')
assert plt.figure(1).get_axes()[0].get_title() == 'Parker Solar Probe ISOIS-EPIHI, protons'

def test_onset_PSP_ISOIS_EPILO_e_online():

def test_onset_spectrum_tsa_PSP_ISOIS_EPILO_e_online():
startdate = datetime.date(2021, 10, 28)
enddate = datetime.date(2021, 10, 29)
lpath = f"{os.getcwd()}/data/"
Expand All @@ -179,8 +226,17 @@ def test_onset_PSP_ISOIS_EPILO_e_online():
assert peak_time.isoformat().split('.')[0] == '2021-10-28T17:48:14'
assert fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPILO 10.0 - 100.5 keV electrons\n5min averaging, viewing: 3'

# test dynamic spectrum:
Event1.dynamic_spectrum(view='7')
assert Event1.fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPILO (7) electrons, 2021-10-28'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot('3', selection=(0, 4, 1), resample='1min')
assert plt.figure(1).get_axes()[0].get_title() == 'Parker Solar Probe ISOIS-EPILO, electrons'

def test_onset_Wind_3DP_p_online():

def test_onset_spectrum_tsa_Wind_3DP_p_online():
startdate = datetime.date(2021, 10, 28)
enddate = datetime.date(2021, 10, 29)
lpath = f"{os.getcwd()}/data/"
Expand All @@ -207,12 +263,21 @@ def test_onset_Wind_3DP_p_online():
assert fig.get_axes()[0].get_title() == 'WIND/3DP 385.96 - 716.78 keV protons\n5min averaging, viewing: OMNIDIRECTIONAL'
# no channel combination inlcuded for Wind/3DP, yet

# test dynamic spectrum:
Event1.dynamic_spectrum(view='sector 3')
assert Event1.fig.get_axes()[0].get_title() == 'WIND/3DP (sector 3) protons, 2021-10-28'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot('omnidirectional', selection=(0, 4, 1), resample=None)
assert plt.figure(1).get_axes()[0].get_title() == 'Wind 3DP, protons'


def test_onset_Wind_3DP_e_online():
def test_onset_spectrum_tsa_Wind_3DP_e_online():
startdate = datetime.date(2021, 10, 28)
enddate = datetime.date(2021, 10, 29)
lpath = f"{os.getcwd()}/data/"
Event1 = Event(spacecraft='Wind', sensor='3DP', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath)
Event1 = Event(spacecraft='Wind', sensor='3DP', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath) # TODO: radio_spacecraft=('wind', 'WIND')
print(Event1.print_energies())
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
#
Expand All @@ -235,8 +300,17 @@ def test_onset_Wind_3DP_e_online():
assert fig.get_axes()[0].get_title() == 'WIND/3DP 127.06 - 235.96 keV electrons\n5min averaging, viewing: OMNIDIRECTIONAL'
# no channel combination inlcuded for Wind/3DP, yet

# test dynamic spectrum:
Event1.dynamic_spectrum(view='omnidirectional')
assert Event1.fig.get_axes()[0].get_title() == 'WIND/3DP (omnidirectional) electrons, 2021-10-28'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot('sector 3', selection=(0, 4, 1), resample=None)
assert plt.figure(1).get_axes()[0].get_title() == 'Wind 3DP, electrons'


def test_onset_STEREOB_HET_p_online():
def test_onset_spectrum_tsa_STEREOB_HET_p_online():
startdate = datetime.date(2006, 12, 13)
enddate = datetime.date(2006, 12, 14)
lpath = f"{os.getcwd()}/data/"
Expand All @@ -253,12 +327,21 @@ def test_onset_STEREOB_HET_p_online():
assert peak_time.isoformat().split('.')[0] == '2006-12-13T09:53:04'
assert fig.get_axes()[0].get_title() == 'STB/HET 26.3 - 40.5 MeV protons\n5min averaging'

# test dynamic spectrum:
Event1.dynamic_spectrum(view=None)
assert Event1.fig.get_axes()[0].get_title() == 'STB/HET protons, 2006-12-13'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot(None, selection=None, resample=None)
assert plt.figure(1).get_axes()[0].get_title() == 'STEREO-B HET, protons'


def test_onset_STEREOB_HET_e_online():
def test_onset_spectrum_tsa_STEREOB_HET_e_online():
startdate = datetime.date(2006, 12, 13)
enddate = datetime.date(2006, 12, 14)
lpath = f"{os.getcwd()}/data/"
Event1 = Event(spacecraft='STEREO-B', sensor='HET', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath)
Event1 = Event(spacecraft='STEREO-B', sensor='HET', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath, radio_spacecraft=('behind', 'STEREO-B'))
print(Event1.print_energies())
background_range = (datetime.datetime(2006, 12, 13, 0, 0, 0), datetime.datetime(2006, 12, 13, 2, 0, 0))
flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing=None, background_range=background_range, channels=[1], resample_period="5min", yscale='log', cusum_window=30)
Expand All @@ -271,8 +354,17 @@ def test_onset_STEREOB_HET_e_online():
assert peak_time.isoformat().split('.')[0] == '2006-12-13T04:53:04'
assert fig.get_axes()[0].get_title() == 'STB/HET 1.4 - 2.8 MeV electrons\n5min averaging'

# test dynamic spectrum:
Event1.dynamic_spectrum(view=None)
assert Event1.fig.get_axes()[0].get_title() == 'Radio & Dynamic Spectrum, STB/HET electrons, 2006-12-13'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot(None, selection=None, resample=None)
assert plt.figure(1).get_axes()[0].get_title() == 'STEREO-B HET, electrons'

def test_onset_STEREOA_SEPT_p_online():

def test_onset_spectrum_tsa_STEREOA_SEPT_p_online():
startdate = datetime.date(2021, 10, 28)
enddate = datetime.date(2021, 10, 28)
lpath = f"{os.getcwd()}/data/"
Expand All @@ -289,12 +381,21 @@ def test_onset_STEREOA_SEPT_p_online():
assert peak_time.isoformat().split('.')[0] == '2021-10-28T17:18:27'
assert fig.get_axes()[0].get_title() == 'STA/SEPT 110-174.6 keV protons\n5min averaging, viewing: NORTH'

# test dynamic spectrum:
Event1.dynamic_spectrum(view=None)
assert Event1.fig.get_axes()[0].get_title() == 'STA/SEPT protons, 2021-10-28'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot(None, selection=None, resample=None)
assert plt.figure(1).get_axes()[0].get_title() == 'STEREO-A SEPT, protons'

def test_onset_STEREOA_SEPT_e_online():

def test_onset_spectrum_tsa_STEREOA_SEPT_e_online():
startdate = datetime.date(2021, 10, 28)
enddate = datetime.date(2021, 10, 28)
lpath = f"{os.getcwd()}/data/"
Event1 = Event(spacecraft='STEREO-A', sensor='SEPT', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath)
Event1 = Event(spacecraft='STEREO-A', sensor='SEPT', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath, radio_spacecraft=('ahead', 'STEREO-A'))
print(Event1.print_energies())
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='asun', background_range=background_range, channels=[8], resample_period="5min", yscale='log', cusum_window=30)
Expand All @@ -307,8 +408,17 @@ def test_onset_STEREOA_SEPT_e_online():
assert peak_time.isoformat().split('.')[0] == '2021-10-28T18:58:27'
assert fig.get_axes()[0].get_title() == 'STA/SEPT 125-145 keV electrons\n5min averaging, viewing: ASUN'

# test dynamic spectrum:
Event1.dynamic_spectrum(view=None)
assert Event1.fig.get_axes()[0].get_title() == 'Radio & Dynamic Spectrum, STA/SEPT electrons, 2021-10-28'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot(None, selection=None, resample=None)
assert plt.figure(1).get_axes()[0].get_title() == 'STEREO-A SEPT, electrons'


def test_onset_SOHO_EPHIN_online():
def test_onset_spectrum_tsa_SOHO_EPHIN_online():
startdate = datetime.date(2021, 10, 28)
enddate = datetime.date(2021, 10, 28)
lpath = f"{os.getcwd()}/data/"
Expand All @@ -326,12 +436,25 @@ def test_onset_SOHO_EPHIN_online():
assert fig.get_axes()[0].get_title() == 'SOHO/EPHIN 0.25 - 0.7 MeV electrons\n5min averaging'
# 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

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot(None, selection=(0, 4, 1), resample='5min')
assert plt.figure(1).get_axes()[0].get_title() == 'SOHO EPHIN, electrons'

def test_onset_SOHO_ERNE_online():

def test_onset_spectrum_tsa_SOHO_ERNE_online():
startdate = datetime.date(2021, 10, 28)
enddate = datetime.date(2021, 10, 29)
lpath = f"{os.getcwd()}/data/"
Event1 = Event(spacecraft='SOHO', sensor='ERNE-HED', data_level='l2', species='protons', start_date=startdate, end_date=enddate, data_path=lpath)
Event1 = Event(spacecraft='SOHO', sensor='ERNE-HED', data_level='l2', species='protons', start_date=startdate, end_date=enddate, data_path=lpath, radio_spacecraft=('ahead', 'STEREO-A'))
print(Event1.print_energies())
background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0))
flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing=None, background_range=background_range, channels=3, resample_period="5min", yscale='log', cusum_window=30)
Expand All @@ -344,8 +467,18 @@ def test_onset_SOHO_ERNE_online():
assert peak_time.isoformat().split('.')[0] == '2021-10-28T22:53:05'
assert fig.get_axes()[0].get_title() == 'SOHO/ERNE 25.0 - 32.0 MeV protons\n5min averaging'

# test dynamic spectrum:
Event1.dynamic_spectrum(view=None)

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

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot(None, selection=(0, 4, 1), resample='5min')
assert plt.figure(1).get_axes()[0].get_title() == 'SOHO ERNE, protons'

def test_onset_SOHO_ERNE_offline():

def test_onset_tsa_SOHO_ERNE_offline():
startdate = datetime.date(2021, 10, 28)
enddate = datetime.date(2021, 10, 29)
fullpath = get_pkg_data_filename('data/test/soho_erne-hed_l2-1min_20211028_v01.cdf', package='seppy')
Expand All @@ -363,6 +496,11 @@ def test_onset_SOHO_ERNE_offline():
assert peak_time.isoformat().split('.')[0] == '2021-10-28T22:53:05'
assert fig.get_axes()[0].get_title() == 'SOHO/ERNE 16.0 - 32.0 MeV protons\n5min averaging'

# test tsa plot:
plt.close('all') # in order to pick the right figure, make sure all previous are closed
Event1.tsa_plot(None, selection=(0, 4, 1), resample='5min')
assert plt.figure(1).get_axes()[0].get_title() == 'SOHO ERNE, protons'


def test_dynamic_spectrum_SOHO_ERNE_offline():
startdate = datetime.date(2021, 10, 28)
Expand Down
2 changes: 1 addition & 1 deletion seppy/tools/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"None": None,
"STEREO-A": ("ahead", "STEREO-A"),
"STEREO-B": ("behind", "STEREO-B"),
"WIND (Coming soon!)": ("wind", "WIND")
# "WIND (Coming soon!)": ("wind", "WIND") # TODO: re-add when supported!
}

# Drop-downs for dynamic particle spectrum:
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ python_requires = >=3.8
setup_requires = setuptools_scm
install_requires =
astropy
astroquery
bs4
cdflib
datetime
Expand Down

0 comments on commit a2d326f

Please sign in to comment.