From f23b00f051db0ec43680c0c381bcd62d32e56c53 Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 30 Aug 2024 18:45:49 +0300 Subject: [PATCH 1/2] bepi data now correctly time-centered --- seppy/util/__init__.py | 25 +++++++------------------ seppy/version.py | 2 +- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/seppy/util/__init__.py b/seppy/util/__init__.py index c0083d7..b2814f6 100644 --- a/seppy/util/__init__.py +++ b/seppy/util/__init__.py @@ -109,24 +109,13 @@ def bepicolombo_sixs_stack(path, date, side, pos_timestamp='center'): df.index = np.array(times) df = df.drop(columns=['TimeUTC']) - # TODO: (as it's not really nicely done so far) - # careful! - # adjusting the position of the timestamp manually. - # requires knowledge of the original time resolution and timestamp position! - if type(date) is datetime.datetime: - change_date = pd.Timestamp(2022, 8, 29) - elif type(date) is datetime.date: - change_date = pd.Timestamp(2022, 8, 29).date() - if date < change_date: - cadence = 8 - elif date >= change_date: - cadence = 24 - # - if pos_timestamp == 'center': - df.index = df.index+pd.Timedelta(f'{cadence/2}s') - # warnings.warn("Assuming cadence of 8s before 2022-08-29 and 24s after!") - custom_warning("Assuming cadence of 8s before 2022-08-29 and 24s after!") - elif pos_timestamp == 'start': + if pos_timestamp == 'start': + cadence1 = (df.index[1]-df.index[0]).seconds + cadence2 = (df.index[-1]-df.index[-2]).seconds + if cadence1 != cadence2: + custom_warning("Bepi/SIXS cadence is changing throughout the day; something is wrong!") + df.index = df.index-pd.Timedelta(f'{cadence1/2}s') + elif pos_timestamp == 'center': pass except FileNotFoundError: print(f'Unable to open {filename}') diff --git a/seppy/version.py b/seppy/version.py index cb15159..4e9dc1b 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.15' + __version__ = '0.1.16' From cf9c82063a188e76aaec4e322c88d2a90ad3fa6b Mon Sep 17 00:00:00 2001 From: Jan Gieseler Date: Fri, 30 Aug 2024 18:56:41 +0300 Subject: [PATCH 2/2] update tests --- seppy/tests/test_tools.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/seppy/tests/test_tools.py b/seppy/tests/test_tools.py index 6475a1a..b943810 100644 --- a/seppy/tests/test_tools.py +++ b/seppy/tests/test_tools.py @@ -62,7 +62,7 @@ def test_onset_spectrum_tsa_SOLO_STEP_ions_new_data_online(): assert flux.shape == (164,) assert len(onset_stats) == 6 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 not onset_found assert peak_time.isoformat().split('.')[0] == '2022-01-09T01:32:31' assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0061 - 0.0091 MeV protons\n5min averaging, viewing: PIXEL AVERAGED' # Pixel 8 @@ -71,7 +71,7 @@ def test_onset_spectrum_tsa_SOLO_STEP_ions_new_data_online(): assert flux.shape == (164,) assert len(onset_stats) == 6 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 not onset_found assert peak_time.isoformat().split('.')[0] == '2022-01-09T00:02:31' assert fig.get_axes()[0].get_title() == 'SOLO/STEP 0.0061 - 0.0091 MeV protons\n5min averaging, viewing: PIXEL 8' @@ -101,7 +101,7 @@ def test_onset_spectrum_tsa_SOLO_HET_online(): 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 not onset_found assert peak_time.isoformat().split('.')[0] == '2022-11-08T17:58:09' assert fig.get_axes()[0].get_title() == 'SOLO/HET 7.3540 - 7.8900 MeV protons\n5min averaging, viewing: SUN' # viewing "north", combined channel, electrons @@ -112,7 +112,7 @@ def test_onset_spectrum_tsa_SOLO_HET_online(): 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 not onset_found assert peak_time.isoformat().split('.')[0] == '2022-11-08T22:27:56' assert fig.get_axes()[0].get_title() == 'SOLO/HET 0.4533 - 18.8300 MeV electrons\n5min averaging, viewing: NORTH' @@ -139,7 +139,7 @@ def test_onset_spectrum_tsa_SOLO_EPT_online(): 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 not onset_found assert peak_time.isoformat().split('.')[0] == '2022-06-06T01:02:31' assert fig.get_axes()[0].get_title() == 'SOLO/EPT 0.0608 - 0.0678 MeV protons\n5min averaging, viewing: SUN' # viewing "north", combined channel, electrons @@ -150,7 +150,7 @@ def test_onset_spectrum_tsa_SOLO_EPT_online(): 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 not onset_found assert peak_time.isoformat().split('.')[0] == '2022-06-06T23:02:31' assert fig.get_axes()[0].get_title() == 'SOLO/EPT 0.0334 - 0.0439 MeV electrons\n5min averaging, viewing: NORTH' @@ -533,6 +533,6 @@ def test_onset_Bepi_SIXS_offline(): 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 not onset_found + assert peak_time.isoformat().split('.')[0] == '2023-07-19T02:25:30' assert fig.get_axes()[0].get_title() == 'BEPI/SIXS 106 keV electrons\n1min averaging, viewing: 1'