From 7553e1fa8d6efea67e93f38be52d6e5d62fbcee7 Mon Sep 17 00:00:00 2001 From: jgieseler Date: Wed, 1 Nov 2023 11:43:13 +0200 Subject: [PATCH 01/19] increase version number --- seppy/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seppy/version.py b/seppy/version.py index 916e1fa..ce39523 100644 --- a/seppy/version.py +++ b/seppy/version.py @@ -5,4 +5,4 @@ from setuptools_scm import get_version __version__ = get_version(root='..', relative_to=__file__) except Exception: - __version__ = '0.1.10' + __version__ = '0.1.11' From cad479b575fde72735b2b88a492ee14879519c36 Mon Sep 17 00:00:00 2001 From: jgieseler Date: Fri, 3 Nov 2023 12:11:30 +0200 Subject: [PATCH 02/19] fix deprecated parameter license_file --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index b61d3fb..7f7b5c9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ name = seppy author = Jan Gieseler author_email = jan.gieseler@utu.fi license = BSD 3-clause -license_file = licenses/LICENSE.rst +license_files = licenses/LICENSE.rst url = https://github.com/serpentine-h2020/SEPpy description = SEPpy long_description = file: README.rst From dd4f861e6e928bb4c6a35f0bd276b173748ffa7d Mon Sep 17 00:00:00 2001 From: jgieseler Date: Tue, 7 Nov 2023 16:46:02 +0200 Subject: [PATCH 03/19] order widget instruments alphabetically --- seppy/tools/widgets.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/seppy/tools/widgets.py b/seppy/tools/widgets.py index 80f2780..7297a86 100644 --- a/seppy/tools/widgets.py +++ b/seppy/tools/widgets.py @@ -2,20 +2,17 @@ A library to run the interactive user interface in SEP event onset determination notebooks. @Author: Christian Palmroos -@Last updated: 2023-03-24 """ - -# from importlib.resources import path import ipywidgets as widgets # a list of available spacecraft: list_of_sc = ["PSP", "SOHO", "Solar Orbiter", "STEREO-A", "STEREO-B", "Wind"] -stereo_instr = ["SEPT", "HET"] # ["LET", "SEPT", "HET"] -solo_instr = ["STEP", "EPT", "HET"] +stereo_instr = ["HET", "SEPT"] # ["LET", "SEPT", "HET"] +solo_instr = ["EPT", "HET", "STEP"] bepi_instr = ["SIXS-P"] -soho_instr = ["ERNE-HED", "EPHIN"] +soho_instr = ["EPHIN", "ERNE-HED"] psp_instr = ["isois-epihi", "isois-epilo"] wind_instr = ["3DP"] From 0ec2393b352f1a7fc5b5a87639426607874e602d Mon Sep 17 00:00:00 2001 From: jgieseler Date: Tue, 14 Nov 2023 12:19:40 +0200 Subject: [PATCH 04/19] fix future pandas' problem with integer key --- seppy/tools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seppy/tools/__init__.py b/seppy/tools/__init__.py index aaa81c3..beee04b 100644 --- a/seppy/tools/__init__.py +++ b/seppy/tools/__init__.py @@ -869,7 +869,7 @@ def onset_determination(self, ma_sigma, flux_series, cusum_window, bg_end_time): for i in range(1, len(cusum)): # normalize the observed flux - norm_channel[i] = (flux_series[i]-ma)/sigma + norm_channel[i] = (flux_series.iloc[i]-ma)/sigma # calculate the value for ith cusum entry cusum[i] = max(0, norm_channel[i] - k_round + cusum[i-1]) From 15f7d3ea0b90773efb2917f0cba7a348f56e6314 Mon Sep 17 00:00:00 2001 From: jgieseler Date: Thu, 21 Dec 2023 15:00:34 +0200 Subject: [PATCH 05/19] load metadata for SOHO-EPHIN-L3I data --- seppy/loader/soho.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/seppy/loader/soho.py b/seppy/loader/soho.py index c5fcdac..1e3d972 100644 --- a/seppy/loader/soho.py +++ b/seppy/loader/soho.py @@ -25,17 +25,22 @@ def _get_metadata(dataset, path_to_cdf): """ metadata = [] cdf = cdflib.CDF(path_to_cdf) - if dataset=='SOHO_ERNE-HED_L2-1MIN' or dataset=='SOHO_ERNE-LED_L2-1MIN': + if dataset in ['SOHO_COSTEP-EPHIN_L3I-1MIN', 'SOHO_ERNE-HED_L2-1MIN', 'SOHO_ERNE-LED_L2-1MIN']: + if dataset=='SOHO_COSTEP-EPHIN_L3I-1MIN': + alpha = 'He' + m = '_int' if dataset=='SOHO_ERNE-HED_L2-1MIN': + alpha = 'A' m = 'H' if dataset=='SOHO_ERNE-LED_L2-1MIN': + alpha = 'A' m = 'L' metadata = {'He_E_label': cdf.varget('He_E_label')[0], 'He_energy': cdf.varget('He_energy'), 'He_energy_delta': cdf.varget('He_energy_delta'), - f'A{m}_LABL': cdf.varattsget(f'A{m}')['LABLAXIS'], - f'A{m}_UNITS': cdf.varattsget(f'A{m}')['UNITS'], - f'A{m}_FILLVAL': cdf.varattsget(f'A{m}')['FILLVAL'], + f'{alpha}{m}_LABL': cdf.varattsget(f'{alpha}{m}')['LABLAXIS'], + f'{alpha}{m}_UNITS': cdf.varattsget(f'{alpha}{m}')['UNITS'], + f'{alpha}{m}_FILLVAL': cdf.varattsget(f'{alpha}{m}')['FILLVAL'], 'P_E_label': cdf.varget('P_E_label')[0], 'P_energy': cdf.varget('P_energy'), 'P_energy_delta': cdf.varget('P_energy_delta'), From 5d9eb6bae7c84e17255d37e8ec8de4b20388defa Mon Sep 17 00:00:00 2001 From: jgieseler Date: Thu, 21 Dec 2023 15:47:45 +0200 Subject: [PATCH 06/19] fix EPHIN channels; deactivate it in dynamic spectrum --- seppy/tools/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/seppy/tools/__init__.py b/seppy/tools/__init__.py index beee04b..6e9839e 100644 --- a/seppy/tools/__init__.py +++ b/seppy/tools/__init__.py @@ -1587,7 +1587,7 @@ def combine_grids_and_ybins(grid, grid1, y_arr, y_arr1): if instrument.lower() == "ephin": particle_data = self.current_df_e s_identifier = "electrons" - warnings.warn('SOHO/EPHIN data is not fully implemented yet!') + raise Warning('SOHO/EPHIN is not implemented yet!') if spacecraft == "psp": if instrument.lower() == "isois-epihi": @@ -2268,10 +2268,10 @@ def get_channel_energy_values(self, returns: str = "num") -> list: if self.sensor.lower() == "erne": energy_ranges = self.current_energies["channels_dict_df_p"]["ch_strings"].values if self.sensor.lower() == "ephin": - # Choose only the 4 first channels / descriptions, since I only know of - # E150, E300, E1300 and E3000. The rest are unknown to me. - # Go up to index 5, because index 1 is 'deactivated bc. of failure mode D' - energy_ranges = [val for val in self.current_energies.values()][:5] + # Choose only the first 4 channels (E150, E300, E1300 and E3000) + # This are the only electron channels (rest p and He), and we + # use only electron data here. + energy_ranges = [val for val in self.current_energies.values()][:4] if self.sensor.lower() in ("ephin-5", "ephin-15"): energy_ranges = [value for key, value in self.current_energies.items()] @@ -2483,9 +2483,11 @@ def print_energies(self): channel_numbers = np.unique(channel_numbers) energy_strs = self.get_channel_energy_values("str") - # SOHO/EPHIN returns one too many energy strs, because one of them is 'deactivated bc. or failure mode D' - if self.sensor == "ephin": - energy_strs = energy_strs[:-1] + # The following behaviour has been fixed upstream. Keeping this here for + # now in case someone is missing it. + # # SOHO/EPHIN returns one too many energy strs, because one of them is 'deactivated bc. or failure mode D' + # # if self.sensor == "ephin": + # # energy_strs = energy_strs[:-1] # Assemble a pandas dataframe here for nicer presentation column_names = ("Channel", "Energy range") From 97894278f96ec94ac33e53b9879e7d8b63ced913 Mon Sep 17 00:00:00 2001 From: jgieseler Date: Thu, 21 Dec 2023 16:28:58 +0200 Subject: [PATCH 07/19] remove CELIAS docstrings --- seppy/loader/soho.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/seppy/loader/soho.py b/seppy/loader/soho.py index 1e3d972..65fb64e 100644 --- a/seppy/loader/soho.py +++ b/seppy/loader/soho.py @@ -81,10 +81,6 @@ def soho_load(dataset, startdate, enddate, path=None, resample=None, pos_timesta http://ulysses.physik.uni-kiel.de/costep/level2/rl2/ - 'SOHO_COSTEP-EPHIN_L3I-1MIN': SOHO COSTEP-EPHIN Level3 intensity 1 minute data https://cdaweb.gsfc.nasa.gov/misc/NotesS.html#SOHO_COSTEP-EPHIN_L3I-1MIN - - 'SOHO_CELIAS-PM_30S': SOHO CELIAS-PM 30 second data - https://cdaweb.gsfc.nasa.gov/misc/NotesS.html#SOHO_CELIAS-PM_30S - - 'SOHO_CELIAS-SEM_15S': SOHO CELIAS-SEM 15 second data - https://cdaweb.gsfc.nasa.gov/misc/NotesS.html#SOHO_CELIAS-SEM_15S - 'SOHO_ERNE-LED_L2-1MIN': SOHO ERNE-LED Level2 1 minute data - VERY OFTEN NO DATA! https://cdaweb.gsfc.nasa.gov/misc/NotesS.html#SOHO_ERNE-LED_L2-1MIN - 'SOHO_ERNE-HED_L2-1MIN': SOHO ERNE-HED Level2 1 minute data From a8dff0d0114d5ade8832b60a21cb31dc8d6ffbf9 Mon Sep 17 00:00:00 2001 From: jgieseler Date: Wed, 3 Jan 2024 16:18:48 +0200 Subject: [PATCH 08/19] replace deprecated IPython.core.display import --- seppy/tools/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seppy/tools/__init__.py b/seppy/tools/__init__.py index 6e9839e..769085c 100644 --- a/seppy/tools/__init__.py +++ b/seppy/tools/__init__.py @@ -1908,7 +1908,7 @@ def tsa_plot(self, view, selection=None, xlim=None, resample=None): """ import ipywidgets as widgets - from IPython.core.display import display + from IPython.display import display # inits spacecraft = self.spacecraft @@ -2423,7 +2423,7 @@ def print_energies(self): Prints out the channel name / energy range pairs """ - from IPython.core.display import display + from IPython.display import display # This has to be run first, otherwise self.current_df does not exist # Note that PSP will by default have its viewing=="all", which does not yield proper dataframes From 3fc6c478f74e35f7dacfd244ddeb6ac401c73915 Mon Sep 17 00:00:00 2001 From: jgieseler Date: Mon, 8 Jan 2024 19:16:18 +0200 Subject: [PATCH 09/19] extend tools testing (including loading) --- seppy/tests/test_tools.py | 217 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 211 insertions(+), 6 deletions(-) diff --git a/seppy/tests/test_tools.py b/seppy/tests/test_tools.py index 138863a..98f750d 100644 --- a/seppy/tests/test_tools.py +++ b/seppy/tests/test_tools.py @@ -7,13 +7,217 @@ import pandas as pd -def test_onset_ERNE_online(): +def test_onset_PSP_ISOIS_EPIHI_online(): + startdate = datetime.date(2021, 10, 28) + enddate = datetime.date(2021, 10, 29) + lpath = f"{os.getcwd()}/data/" + background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0)) + # viewing "A", single channel, electrons + Event1 = Event(spacecraft='PSP', sensor='isois-epihi', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath) + print(Event1.print_energies()) + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='A', background_range=background_range, channels=4, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (194,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 16:06:59.492059') + assert fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPIHI 0.8 - 1.0 MeV electrons\n5min averaging, viewing: A' + # viewing "B", combined channel, protons + Event1 = Event(spacecraft='PSP', sensor='isois-epihi', data_level='l2', species='protons', start_date=startdate, end_date=enddate, data_path=lpath) + print(Event1.print_energies()) + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='B', background_range=background_range, channels=[1, 5], resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (194,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 16:46:59.492059') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 19:56:59.492059') + assert fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPIHI 8.0 - 19.0 MeV protons\n5min averaging, viewing: B' + + +def test_onset_PSP_ISOIS_EPILO_e_online(): + startdate = datetime.date(2021, 10, 28) + enddate = datetime.date(2021, 10, 29) + lpath = f"{os.getcwd()}/data/" + Event1 = Event(spacecraft='PSP', sensor='isois-epilo', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath) + print(Event1.print_energies()) + background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0)) + # viewing "7", single channel + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='7', background_range=background_range, channels=4, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (198,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 15:33:14.991967') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 16:43:14.991967') + assert fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPILO 65.9 - 100.5 keV electrons\n5min averaging, viewing: 7' + # viewing "3", combined channels + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='3', background_range=background_range, channels=[0, 4], resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (198,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 15:33:14.991967') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 17:48:14.991967') + assert fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPILO 10.0 - 100.5 keV electrons\n5min averaging, viewing: 3' + + +def test_onset_Wind_3DP_p_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='protons', start_date=startdate, end_date=enddate, data_path=lpath) + print(Event1.print_energies()) + background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0)) + # viewng "sector 3" + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='sector 3', background_range=background_range, channels=4, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 16:27:35.959000') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 20:17:35.959000') + assert fig.get_axes()[0].get_title() == 'WIND/3DP 385.96 - 716.78 keV protons\n5min averaging, viewing: SECTOR 3' + # viewing "omnidirectional" + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='omnidirectional', background_range=background_range, channels=4, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 16:27:42.224000') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 21:07:42.224000') + 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 + + +def test_onset_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) + 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='sector 3', background_range=background_range, channels=4, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 16:12:35.959000') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 21:52:35.959000') + assert fig.get_axes()[0].get_title() == 'WIND/3DP 127.06 - 235.96 keV electrons\n5min averaging, viewing: SECTOR 3' + # + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='omnidirectional', background_range=background_range, channels=4, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 16:07:42.224000') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 21:52:42.224000') + 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 + + +def test_onset_STEREOB_HET_p_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='protons', start_date=startdate, end_date=enddate, data_path=lpath) + 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=[5, 8], resample_period="5min", yscale='log', cusum_window=30) + + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2006-12-13 03:18:04') + assert onset_found + assert peak_time == pd.Timestamp('2006-12-13 09:53:04') + assert fig.get_axes()[0].get_title() == 'STB/HET 26.3 - 40.5 MeV protons\n5min averaging' + + +def test_onset_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) + 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) + + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2006-12-13 02:43:04') + assert onset_found + assert peak_time == pd.Timestamp('2006-12-13 04:53:04') + assert fig.get_axes()[0].get_title() == 'STB/HET 1.4 - 2.8 MeV electrons\n5min averaging' + + +def test_onset_STEREOA_SEPT_p_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='ions', start_date=startdate, end_date=enddate, data_path=lpath) + 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='north', background_range=background_range, channels=[5, 8], resample_period="5min", yscale='log', cusum_window=30) + + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 15:53:27.974418944') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 17:18:27.974418944') + assert fig.get_axes()[0].get_title() == 'STA/SEPT 110-174.6 keV protons\n5min averaging, viewing: NORTH' + + +def test_onset_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) + 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) + + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 15:43:27.974418944') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 18:58:27.974418944') + assert fig.get_axes()[0].get_title() == 'STA/SEPT 125-145 keV electrons\n5min averaging, viewing: ASUN' + + +def test_onset_SOHO_EPHIN_online(): + startdate = datetime.date(2021, 10, 28) + enddate = datetime.date(2021, 10, 28) + lpath = f"{os.getcwd()}/data/" + Event1 = Event(spacecraft='SOHO', sensor='EPHIN', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath) + 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=150, resample_period="5min", yscale='log', cusum_window=30) + + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 15:53:42.357000') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 22:18:42.357000') # pd.Timestamp('2021-10-29 04:53:42.357000') + 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 + + +def test_onset_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) + 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='sun', background_range=background_range, channels=3, resample_period="5min", yscale='log', cusum_window=30) + 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) assert isinstance(flux, pd.Series) assert flux.shape == (288,) @@ -24,14 +228,15 @@ def test_onset_ERNE_online(): assert fig.get_axes()[0].get_title() == 'SOHO/ERNE 25.0 - 32.0 MeV protons\n5min averaging' -def test_onset_ERNE_offline(): +def test_onset_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') lpath = Path(fullpath).parent.as_posix() Event1 = Event(spacecraft='SOHO', sensor='ERNE-HED', data_level='l2', species='protons', start_date=startdate, end_date=enddate, data_path=lpath) + 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='sun', background_range=background_range, channels=3, resample_period="5min", yscale='log', cusum_window=30) + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing=None, background_range=background_range, channels=[1, 3], resample_period="5min", yscale='log', cusum_window=30) assert isinstance(flux, pd.Series) assert flux.shape == (288,) @@ -39,10 +244,10 @@ def test_onset_ERNE_offline(): assert onset_stats[5] == pd.Timestamp('2021-10-28 16:53:05.357000') assert onset_found assert peak_time == pd.Timestamp('2021-10-28 22:53:05.357000') - assert fig.get_axes()[0].get_title() == 'SOHO/ERNE 25.0 - 32.0 MeV protons\n5min averaging' + assert fig.get_axes()[0].get_title() == 'SOHO/ERNE 16.0 - 32.0 MeV protons\n5min averaging' -def test_dynamic_spectrum_ERNE_offline(): +def test_dynamic_spectrum_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') From 3a727804c958dc40f85546ed5b9e1ae0df73e68a Mon Sep 17 00:00:00 2001 From: jgieseler Date: Wed, 31 Jan 2024 10:47:39 +0200 Subject: [PATCH 10/19] extend EPHIN warning in dynamic spectrum --- seppy/tools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seppy/tools/__init__.py b/seppy/tools/__init__.py index 769085c..8e01099 100644 --- a/seppy/tools/__init__.py +++ b/seppy/tools/__init__.py @@ -1587,7 +1587,7 @@ def combine_grids_and_ybins(grid, grid1, y_arr, y_arr1): if instrument.lower() == "ephin": particle_data = self.current_df_e s_identifier = "electrons" - raise Warning('SOHO/EPHIN is not implemented yet!') + raise Warning('SOHO/EPHIN is not implemented yet in the dynamic spectrum tool!') if spacecraft == "psp": if instrument.lower() == "isois-epihi": From 37403300b5467065a05cecfed5c769dfb4c02949 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 2 Feb 2024 16:25:26 +0200 Subject: [PATCH 11/19] add SOLO/EPD onset tests --- seppy/tests/test_tools.py | 117 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/seppy/tests/test_tools.py b/seppy/tests/test_tools.py index 98f750d..b857a68 100644 --- a/seppy/tests/test_tools.py +++ b/seppy/tests/test_tools.py @@ -7,6 +7,123 @@ import pandas as pd +# TODO: find smaller datasets for SOLO/STEP +# TODO: test dynamic spectrum for all dataset +# TODO: test tsa for all dataset + + +def test_onset_SOLO_STEP_ions_old_data_online(): + startdate = datetime.date(2020, 9, 21) + enddate = datetime.date(2020, 9, 21) + lpath = f"{os.getcwd()}/data/" + background_range = (datetime.datetime(2020, 9, 21, 0, 0, 0), datetime.datetime(2020, 9, 21, 2, 0, 0)) + # + # ions + Event1 = Event(spacecraft='Solar Orbiter', sensor='STEP', data_level='l2', species='ions', start_date=startdate, end_date=enddate, data_path=lpath) + # print(Event1.print_energies()) # TODO: see test_onset_SOLO_EPT_online + # Pixel averaged + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='Pixel averaged', background_range=background_range, channels=1, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2020-09-21 17:27:32.010263') + assert onset_found + assert peak_time == pd.Timestamp('2020-09-21 17:57:32.010263') + assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0060 - 0.0091 MeV/n protons\n5min averaging, viewing: PIXEL AVERAGED' + # Pixel 8 - check that calculation is stopped bc. this data is not implemented correctly! + try: + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='Pixel 8', background_range=background_range, channels=1, resample_period="5min", yscale='log', cusum_window=30) + except Warning: + check = True + assert check + + +def test_onset_SOLO_STEP_ions_new_data_online(): + startdate = datetime.date(2021, 10, 28) + enddate = datetime.date(2021, 10, 28) + lpath = f"{os.getcwd()}/data/" + background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0)) + # ions + Event1 = Event(spacecraft='Solar Orbiter', sensor='STEP', data_level='l2', species='ions', start_date=startdate, end_date=enddate, data_path=lpath) + # print(Event1.print_energies()) # TODO: see test_onset_SOLO_EPT_online + # Pixel averaged + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='Pixel averaged', background_range=background_range, channels=1, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 16:07:30.153419') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 18:57:30.153419') + assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0061 - 0.0091 MeV protons\n5min averaging, viewing: PIXEL AVERAGED' + # Pixel 8 + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='Pixel 8', background_range=background_range, channels=1, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert onset_stats[5] == pd.Timestamp('2021-10-28 16:12:30.153419') + assert onset_found + assert peak_time == pd.Timestamp('2021-10-28 20:52:30.153419') + assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0061 - 0.0091 MeV protons\n5min averaging, viewing: PIXEL 8' + + +def test_onset_SOLO_HET_online(): + startdate = datetime.date(2022, 11, 8) + enddate = datetime.date(2022, 11, 8) + lpath = f"{os.getcwd()}/data/" + background_range = (datetime.datetime(2022, 11, 8, 0, 0, 0), datetime.datetime(2022, 11, 8, 1, 0, 0)) + # viewing "sun", single channel, protons + Event1 = Event(spacecraft='Solar Orbiter', sensor='HET', data_level='l2', species='protons', start_date=startdate, end_date=enddate, data_path=lpath) + # print(Event1.print_energies()) # TODO: see test_onset_SOLO_EPT_online + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='sun', background_range=background_range, channels=1, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (73,) + assert len(onset_stats) == 6 + assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') + assert ~onset_found + assert peak_time == pd.Timestamp('2022-11-08 17:57:54.269660') + assert fig.get_axes()[0].get_title() == 'SOLO/HET 7.3540 - 7.8900 MeV protons\n5min averaging, viewing: SUN' + # viewing "north", combined channel, electrons + Event1 = Event(spacecraft='Solar Orbiter', sensor='HET', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath) + # print(Event1.print_energies()) # TODO: see test_onset_SOLO_EPT_online + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='north', background_range=background_range, channels=[0, 3], resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (73,) + assert len(onset_stats) == 6 + assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') + assert ~onset_found + assert peak_time == pd.Timestamp('2022-11-08 22:27:54.269660') + assert fig.get_axes()[0].get_title() == 'SOLO/HET 0.4533 - 18.8300 MeV electrons\n5min averaging, viewing: NORTH' + + +def test_onset_SOLO_EPT_online(): + startdate = datetime.date(2022, 6, 6) + enddate = datetime.date(2022, 6, 6) + lpath = f"{os.getcwd()}/data/" + background_range = (datetime.datetime(2022, 6, 6, 0, 0, 0), datetime.datetime(2022, 6, 6, 1, 0, 0)) + # viewing "sun", single channel, ions + Event1 = Event(spacecraft='Solar Orbiter', sensor='EPT', data_level='l2', species='ions', start_date=startdate, end_date=enddate, data_path=lpath) + # print(Event1.print_energies()) # TODO: Fix bug! right now viewing is not defined. if run after event.find_onset, it works! + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='sun', background_range=background_range, channels=4, resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') + assert ~onset_found + assert peak_time == pd.Timestamp('2022-06-06 01:02:30.902854') + assert fig.get_axes()[0].get_title() == 'SOLO/EPT 0.0608 - 0.0678 MeV protons\n5min averaging, viewing: SUN' + # viewing "north", combined channel, electrons + Event1 = Event(spacecraft='Solar Orbiter', sensor='EPT', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath) + # print(Event1.print_energies()) # TODO: see above + flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='north', background_range=background_range, channels=[1, 4], resample_period="5min", yscale='log', cusum_window=30) + assert isinstance(flux, pd.Series) + assert flux.shape == (288,) + assert len(onset_stats) == 6 + assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') + assert ~onset_found + assert peak_time == pd.Timestamp('2022-06-06 23:02:30.902854') + assert fig.get_axes()[0].get_title() == 'SOLO/EPT 0.0334 - 0.0439 MeV electrons\n5min averaging, viewing: NORTH' + + def test_onset_PSP_ISOIS_EPIHI_online(): startdate = datetime.date(2021, 10, 28) enddate = datetime.date(2021, 10, 29) From 53b729e3ae2b7e6997f90aa92ab326377372dbf7 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 2 Feb 2024 16:26:11 +0200 Subject: [PATCH 12/19] remove SOLO/STEP electron option --- seppy/tools/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seppy/tools/widgets.py b/seppy/tools/widgets.py index 7297a86..471ce98 100644 --- a/seppy/tools/widgets.py +++ b/seppy/tools/widgets.py @@ -46,7 +46,7 @@ ("STEREO-B", "LET"): ("protons", "electrons"), ("STEREO-B", "SEPT"): ("ions", "electrons"), ("STEREO-B", "HET"): ("protons", "electrons"), - ("Solar Orbiter", "STEP"): ("ions", "electrons"), + ("Solar Orbiter", "STEP"): ("ions",), # , "electrons"), ("Solar Orbiter", "EPT"): ("ions", "electrons"), ("Solar Orbiter", "HET"): ("protons", "electrons"), ("Bepicolombo", "SIXS-P"): ("protons", "electrons"), From a5084efb27a2d997927e669427a0d586e9e76b68 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 2 Feb 2024 16:28:21 +0200 Subject: [PATCH 13/19] abort & warn for old pixeled or electron SOLO/STEP data --- seppy/tools/__init__.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/seppy/tools/__init__.py b/seppy/tools/__init__.py index 8e01099..cbb3923 100644 --- a/seppy/tools/__init__.py +++ b/seppy/tools/__init__.py @@ -92,8 +92,10 @@ def __init__(self, start_date, end_date, spacecraft, sensor, # names from the dataframe. self.load_all_viewing() - # Check that the data that was loaded is valid. If not, give a warning. - self.validate_data() + # JG: This is NOT enough to just check this at this position! This needs to be aborting the process if the specific combination is chosen! + # JG: Removed here and moved to appropriate positions. + # # Check that the data that was loaded is valid. If not, give a warning. + # self.validate_data() # Download radio cdf files ONLY if asked to if self.radio_spacecraft is not None: @@ -108,7 +110,12 @@ def validate_data(self): # Data products for SolO/STEP before 22 Oct 2021 are no reliable for non-Pixel Averaged data if self.spacecraft == "solo" and self.sensor == "step": if self.start_date < pd.to_datetime("2021-10-22").date(): - warnings.warn("WARNING! SolO/STEP particle data is not included yet for individual Pixels for dates preceding 2022-10-22.") + if not self.viewing == 'Pixel averaged': + raise Warning("WARNING! SolO/STEP data is not included yet for individual Pixels for dates preceding Oct 22, 2021.") + + # Electron data for SolO/STEP is removed for now (Feb 2024, JG) + if self.spacecraft == "solo" and self.sensor == "step" and self.species.lower()[0] == 'e': + raise Warning("WARNING! SolO/STEP electron data is not implemented yet!") def update_onset_attributes(self, flux_series, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean): """ @@ -1190,6 +1197,9 @@ def find_onset(self, viewing, bg_start=None, bg_length=None, background_range=No elif (self.spacecraft.lower() == 'soho' and self.sensor in ["ephin", "ephin-5", "ephin-15"]): self.viewing_used = '' + # Check that the data that was loaded is valid. If not, abort with warning. + self.validate_data() + self.averaging_used = resample_period self.x_sigma = x_sigma @@ -1529,6 +1539,9 @@ def combine_grids_and_ybins(grid, grid1, y_arr, y_arr1): # This method has to be run before doing anything else to make sure that the viewing is correct self.choose_data(view) + # Check that the data that was loaded is valid. If not, abort with warning. + self.validate_data() + if self.spacecraft == "solo": if instrument == "step": @@ -1935,6 +1948,9 @@ def tsa_plot(self, view, selection=None, xlim=None, resample=None): self.choose_data(view) + # Check that the data that was loaded is valid. If not, abort with warning. + self.validate_data() + if self.spacecraft == "solo": if self.sensor == "step": From 811a5dfbaec2140dc75e8e07f12d9575a0a4c5a5 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 2 Feb 2024 16:30:37 +0200 Subject: [PATCH 14/19] increase version --- seppy/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seppy/version.py b/seppy/version.py index ce39523..a009868 100644 --- a/seppy/version.py +++ b/seppy/version.py @@ -5,4 +5,4 @@ from setuptools_scm import get_version __version__ = get_version(root='..', relative_to=__file__) except Exception: - __version__ = '0.1.11' + __version__ = '0.1.12' From bba8e4a36434d3c296858d19fbc6a3e92dedb750 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 2 Feb 2024 16:33:21 +0200 Subject: [PATCH 15/19] fix test_onset_SOLO_STEP_ions_old_data_online --- seppy/tests/test_tools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/seppy/tests/test_tools.py b/seppy/tests/test_tools.py index b857a68..8cb3cce 100644 --- a/seppy/tests/test_tools.py +++ b/seppy/tests/test_tools.py @@ -31,6 +31,7 @@ def test_onset_SOLO_STEP_ions_old_data_online(): assert peak_time == pd.Timestamp('2020-09-21 17:57:32.010263') assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0060 - 0.0091 MeV/n protons\n5min averaging, viewing: PIXEL AVERAGED' # Pixel 8 - check that calculation is stopped bc. this data is not implemented correctly! + check = False try: flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='Pixel 8', background_range=background_range, channels=1, resample_period="5min", yscale='log', cusum_window=30) except Warning: From f435b37306717323325d1117f1b5f7560333688e Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 2 Feb 2024 16:35:33 +0200 Subject: [PATCH 16/19] code cleaning --- seppy/loader/psp.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/seppy/loader/psp.py b/seppy/loader/psp.py index 380b38a..f4d28c2 100644 --- a/seppy/loader/psp.py +++ b/seppy/loader/psp.py @@ -316,7 +316,7 @@ def psp_isois_load(dataset, startdate, enddate, epilo_channel='F', epilo_thresho ignore = [f'Epoch_Chan{epilo_channel}_DELTA', f'HCI_Chan{epilo_channel}', f'HCI_Lat_Chan{epilo_channel}', f'HCI_Lon_Chan{epilo_channel}', f'HCI_R_Chan{epilo_channel}', f'HGC_Lat_Chan{epilo_channel}', f'HGC_Lon_Chan{epilo_channel}', f'HGC_R_Chan{epilo_channel}', f'{species_str}_Chan{epilo_channel}_Energy_LABL', f'{species_str}_Counts_Chan{epilo_channel}', f'RTN_Chan{epilo_channel}'] - #ignore = ['Epoch_ChanP_DELTA', 'HCI_ChanP', 'HCI_Lat_ChanP', 'HCI_Lon_ChanP', 'HCI_R_ChanP', 'HGC_Lat_ChanP', 'HGC_Lon_ChanP', 'HGC_R_ChanP', 'H_ChanP_Energy', 'H_ChanP_Energy_DELTAMINUS', 'H_ChanP_Energy_DELTAPLUS', 'H_ChanP_Energy_LABL', 'H_CountRate_ChanP', 'H_Counts_ChanP', 'H_Flux_ChanP', 'H_Flux_ChanP_DELTA', 'PA_ChanP', 'Quality_Flag_ChanP', 'RTN_ChanP', 'SA_ChanP + # ignore = ['Epoch_ChanP_DELTA', 'HCI_ChanP', 'HCI_Lat_ChanP', 'HCI_Lon_ChanP', 'HCI_R_ChanP', 'HGC_Lat_ChanP', 'HGC_Lon_ChanP', 'HGC_R_ChanP', 'H_ChanP_Energy', 'H_ChanP_Energy_DELTAMINUS', 'H_ChanP_Energy_DELTAPLUS', 'H_ChanP_Energy_LABL', 'H_CountRate_ChanP', 'H_Counts_ChanP', 'H_Flux_ChanP', 'H_Flux_ChanP_DELTA', 'PA_ChanP', 'Quality_Flag_ChanP', 'RTN_ChanP', 'SA_ChanP # read 0th cdf file # # cdf = cdflib.CDF(downloaded_files[0]) @@ -463,7 +463,7 @@ def calc_av_en_flux_PSP_EPILO(df, en_dict, en_channel, species, mode, chan, view chan : string 'E', 'F', 'G', 'P', 'T'. EPILO chan viewing : int or list - EPILO viewing. 0 to 7 for electrons; 0 to 79 for ions + EPILO viewing. 0 to 7 for electrons; 0 to 79 for ions (ions 70-79 correspond to electrons 7, i.e., the electron wedges are split up into 10 viewings for ions) @@ -491,7 +491,7 @@ def calc_av_en_flux_PSP_EPILO(df, en_dict, en_channel, species, mode, chan, view en_channel = [en_channel] if type(viewing) == int: viewing = [viewing] - + df_out = pd.DataFrame() flux_out_all = {} en_channel_string_all = [] @@ -529,7 +529,7 @@ def calc_av_en_flux_PSP_EPILO(df, en_dict, en_channel, species, mode, chan, view if len(en_channel) == 1: en_channel = en_channel[0] flux_out = pd.DataFrame({f'viewing_{view}': df[f"{flux_key}_Chan{chan}_E{en_channel}_P{view}"]}, index=df.index) - + df_out = pd.concat([df_out, flux_out], axis=1) # calculate mean of all viewings: @@ -563,7 +563,7 @@ def _read_cdf_psp(fname, index_key, ignore_vars=[]): fname : path-like Location of single CDF file to read. index_key : str - The CDF key to use as the index in the output DataFrame. + The CDF key to use as the index in the output DataFrame. For example, index_key='Epoch_ChanP' ignore_vars : list In case a CDF file has columns that are unused / not required, then From 68d76d5a2e440c1615ba93eedafbdbfef867f0fd Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 2 Feb 2024 16:39:34 +0200 Subject: [PATCH 17/19] extend todo --- seppy/tests/test_tools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/seppy/tests/test_tools.py b/seppy/tests/test_tools.py index 8cb3cce..4bed15a 100644 --- a/seppy/tests/test_tools.py +++ b/seppy/tests/test_tools.py @@ -7,6 +7,7 @@ import pandas as pd +# TODO: round Timestamps because they cause sometimes failures in testing # TODO: find smaller datasets for SOLO/STEP # TODO: test dynamic spectrum for all dataset # TODO: test tsa for all dataset From 2720c6823e36bd6e0a47eb951c3f25041b20ce7c Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 2 Feb 2024 17:04:53 +0200 Subject: [PATCH 18/19] change timestamp handling of tests --- seppy/tests/test_tools.py | 80 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/seppy/tests/test_tools.py b/seppy/tests/test_tools.py index 4bed15a..0b82f74 100644 --- a/seppy/tests/test_tools.py +++ b/seppy/tests/test_tools.py @@ -27,9 +27,9 @@ def test_onset_SOLO_STEP_ions_old_data_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2020-09-21 17:27:32.010263') + assert onset_stats[5].isoformat().split('.')[0] == '2020-09-21T17:27:32' assert onset_found - assert peak_time == pd.Timestamp('2020-09-21 17:57:32.010263') + assert peak_time.isoformat().split('.')[0] == '2020-09-21T17:57:32' assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0060 - 0.0091 MeV/n protons\n5min averaging, viewing: PIXEL AVERAGED' # Pixel 8 - check that calculation is stopped bc. this data is not implemented correctly! check = False @@ -53,18 +53,18 @@ def test_onset_SOLO_STEP_ions_new_data_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 16:07:30.153419') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:07:30' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 18:57:30.153419') + assert peak_time.isoformat().split('.')[0] == '2021-10-28T18:57:30' assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0061 - 0.0091 MeV protons\n5min averaging, viewing: PIXEL AVERAGED' # Pixel 8 flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='Pixel 8', background_range=background_range, channels=1, resample_period="5min", yscale='log', cusum_window=30) assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 16:12:30.153419') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:12:30' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 20:52:30.153419') + assert peak_time.isoformat().split('.')[0] == '2021-10-28T20:52:30' assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0061 - 0.0091 MeV protons\n5min averaging, viewing: PIXEL 8' @@ -82,7 +82,7 @@ def test_onset_SOLO_HET_online(): assert len(onset_stats) == 6 assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') assert ~onset_found - assert peak_time == pd.Timestamp('2022-11-08 17:57:54.269660') + assert peak_time.isoformat().split('.')[0] == '2022-11-08T17:57:54' assert fig.get_axes()[0].get_title() == 'SOLO/HET 7.3540 - 7.8900 MeV protons\n5min averaging, viewing: SUN' # viewing "north", combined channel, electrons Event1 = Event(spacecraft='Solar Orbiter', sensor='HET', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath) @@ -93,7 +93,7 @@ def test_onset_SOLO_HET_online(): assert len(onset_stats) == 6 assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') assert ~onset_found - assert peak_time == pd.Timestamp('2022-11-08 22:27:54.269660') + 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' @@ -111,7 +111,7 @@ def test_onset_SOLO_EPT_online(): assert len(onset_stats) == 6 assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') assert ~onset_found - assert peak_time == pd.Timestamp('2022-06-06 01:02:30.902854') + assert peak_time.isoformat().split('.')[0] == '2022-06-06T01:02:30' assert fig.get_axes()[0].get_title() == 'SOLO/EPT 0.0608 - 0.0678 MeV protons\n5min averaging, viewing: SUN' # viewing "north", combined channel, electrons Event1 = Event(spacecraft='Solar Orbiter', sensor='EPT', data_level='l2', species='electrons', start_date=startdate, end_date=enddate, data_path=lpath) @@ -122,7 +122,7 @@ def test_onset_SOLO_EPT_online(): assert len(onset_stats) == 6 assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') assert ~onset_found - assert peak_time == pd.Timestamp('2022-06-06 23:02:30.902854') + 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' @@ -138,9 +138,9 @@ def test_onset_PSP_ISOIS_EPIHI_online(): assert isinstance(flux, pd.Series) assert flux.shape == (194,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 15:31:59.492059') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T15:31:59' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 16:06:59.492059') + assert peak_time.isoformat().split('.')[0] == '2021-10-28T16:06:59' assert fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPIHI 0.8 - 1.0 MeV electrons\n5min averaging, viewing: A' # viewing "B", combined channel, protons Event1 = Event(spacecraft='PSP', sensor='isois-epihi', data_level='l2', species='protons', start_date=startdate, end_date=enddate, data_path=lpath) @@ -149,9 +149,9 @@ def test_onset_PSP_ISOIS_EPIHI_online(): assert isinstance(flux, pd.Series) assert flux.shape == (194,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 16:46:59.492059') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:46:59' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 19:56:59.492059') + 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' @@ -167,18 +167,18 @@ def test_onset_PSP_ISOIS_EPILO_e_online(): assert isinstance(flux, pd.Series) assert flux.shape == (198,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 15:33:14.991967') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T15:33:14' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 16:43:14.991967') + assert peak_time.isoformat().split('.')[0] == '2021-10-28T16:43:14' assert fig.get_axes()[0].get_title() == 'PSP/ISOIS-EPILO 65.9 - 100.5 keV electrons\n5min averaging, viewing: 7' # viewing "3", combined channels flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='3', background_range=background_range, channels=[0, 4], resample_period="5min", yscale='log', cusum_window=30) assert isinstance(flux, pd.Series) assert flux.shape == (198,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 15:33:14.991967') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T15:33:14' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 17:48:14.991967') + 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' @@ -194,18 +194,18 @@ def test_onset_Wind_3DP_p_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 16:27:35.959000') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:27:35' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 20:17:35.959000') + assert peak_time.isoformat().split('.')[0] == '2021-10-28T20:17:35' assert fig.get_axes()[0].get_title() == 'WIND/3DP 385.96 - 716.78 keV protons\n5min averaging, viewing: SECTOR 3' # viewing "omnidirectional" flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='omnidirectional', background_range=background_range, channels=4, resample_period="5min", yscale='log', cusum_window=30) assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 16:27:42.224000') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:27:42' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 21:07:42.224000') + assert peak_time.isoformat().split('.')[0] == '2021-10-28T21:07:42' 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 @@ -222,18 +222,18 @@ def test_onset_Wind_3DP_e_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 16:12:35.959000') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:12:35' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 21:52:35.959000') + assert peak_time.isoformat().split('.')[0] == '2021-10-28T21:52:35' assert fig.get_axes()[0].get_title() == 'WIND/3DP 127.06 - 235.96 keV electrons\n5min averaging, viewing: SECTOR 3' # flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='omnidirectional', background_range=background_range, channels=4, resample_period="5min", yscale='log', cusum_window=30) assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 16:07:42.224000') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:07:42' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 21:52:42.224000') + assert peak_time.isoformat().split('.')[0] == '2021-10-28T21:52:42' 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 @@ -250,9 +250,9 @@ def test_onset_STEREOB_HET_p_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2006-12-13 03:18:04') + assert onset_stats[5].isoformat().split('.')[0] == '2006-12-13T03:18:04' assert onset_found - assert peak_time == pd.Timestamp('2006-12-13 09:53:04') + 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' @@ -268,9 +268,9 @@ def test_onset_STEREOB_HET_e_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2006-12-13 02:43:04') + assert onset_stats[5].isoformat().split('.')[0] == '2006-12-13T02:43:04' assert onset_found - assert peak_time == pd.Timestamp('2006-12-13 04:53:04') + 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' @@ -286,9 +286,9 @@ def test_onset_STEREOA_SEPT_p_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 15:53:27.974418944') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T15:53:27' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 17:18:27.974418944') + 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' @@ -304,9 +304,9 @@ def test_onset_STEREOA_SEPT_e_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 15:43:27.974418944') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T15:43:27' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 18:58:27.974418944') + 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' @@ -322,9 +322,9 @@ def test_onset_SOHO_EPHIN_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 15:53:42.357000') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T15:53:42' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 22:18:42.357000') # pd.Timestamp('2021-10-29 04:53:42.357000') + assert peak_time.isoformat().split('.')[0] == '2021-10-28T22:18:42' # '2021-10-29T04:53:42.357000') 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 @@ -341,9 +341,9 @@ def test_onset_SOHO_ERNE_online(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 16:53:05.357000') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:53:05' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 22:53:05.357000') + 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' @@ -360,9 +360,9 @@ def test_onset_SOHO_ERNE_offline(): assert isinstance(flux, pd.Series) assert flux.shape == (288,) assert len(onset_stats) == 6 - assert onset_stats[5] == pd.Timestamp('2021-10-28 16:53:05.357000') + assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:53:05' assert onset_found - assert peak_time == pd.Timestamp('2021-10-28 22:53:05.357000') + 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' From 67004da6deaa7d45f5a3737c6ec2cb5e041c8a39 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 2 Feb 2024 18:43:40 +0200 Subject: [PATCH 19/19] use smaller datasets for SOLO/STEP test --- seppy/tests/test_tools.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/seppy/tests/test_tools.py b/seppy/tests/test_tools.py index 0b82f74..18c5650 100644 --- a/seppy/tests/test_tools.py +++ b/seppy/tests/test_tools.py @@ -7,8 +7,6 @@ import pandas as pd -# TODO: round Timestamps because they cause sometimes failures in testing -# TODO: find smaller datasets for SOLO/STEP # TODO: test dynamic spectrum for all dataset # TODO: test tsa for all dataset @@ -41,30 +39,30 @@ def test_onset_SOLO_STEP_ions_old_data_online(): def test_onset_SOLO_STEP_ions_new_data_online(): - startdate = datetime.date(2021, 10, 28) - enddate = datetime.date(2021, 10, 28) + startdate = datetime.date(2022, 1, 9) + enddate = datetime.date(2022, 1, 9) lpath = f"{os.getcwd()}/data/" - background_range = (datetime.datetime(2021, 10, 28, 10, 0, 0), datetime.datetime(2021, 10, 28, 12, 0, 0)) + background_range = (datetime.datetime(2022, 1, 9, 10, 0, 0), datetime.datetime(2022, 1, 9, 12, 0, 0)) # ions Event1 = Event(spacecraft='Solar Orbiter', sensor='STEP', data_level='l2', species='ions', start_date=startdate, end_date=enddate, data_path=lpath) # print(Event1.print_energies()) # TODO: see test_onset_SOLO_EPT_online # Pixel averaged flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='Pixel averaged', background_range=background_range, channels=1, resample_period="5min", yscale='log', cusum_window=30) assert isinstance(flux, pd.Series) - assert flux.shape == (288,) + assert flux.shape == (164,) assert len(onset_stats) == 6 - assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:07:30' - assert onset_found - assert peak_time.isoformat().split('.')[0] == '2021-10-28T18:57:30' + assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:07:30' + assert ~onset_found + assert peak_time.isoformat().split('.')[0] == '2022-01-09T01:32:30' assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0061 - 0.0091 MeV protons\n5min averaging, viewing: PIXEL AVERAGED' # Pixel 8 flux, onset_stats, onset_found, peak_flux, peak_time, fig, bg_mean = Event1.find_onset(viewing='Pixel 8', background_range=background_range, channels=1, resample_period="5min", yscale='log', cusum_window=30) assert isinstance(flux, pd.Series) - assert flux.shape == (288,) + assert flux.shape == (164,) assert len(onset_stats) == 6 - assert onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:12:30' - assert onset_found - assert peak_time.isoformat().split('.')[0] == '2021-10-28T20:52:30' + assert isinstance(onset_stats[5], pd._libs.tslibs.nattype.NaTType) # onset_stats[5].isoformat().split('.')[0] == '2021-10-28T16:12:30' + assert ~onset_found + 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'