Skip to content

Commit ca70701

Browse files
committed
ENH: webpoda: Add an instrument-specific buffer for downloading packet files
Each instrument can specify they buffer they want to apply to include packets +/- X minutes on either side of the midnight boundary.
1 parent c39c7fe commit ca70701

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

imap_data_access/webpoda.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@
127127
"ialirt": [478],
128128
}
129129

130+
_INSTRUMENT_BUFFER_MINUTES = {
131+
"hit": 20,
132+
"mag": 30,
133+
"swapi": 1,
134+
"swe": 1,
135+
}
136+
130137

131138
def _get_webpoda_headers() -> dict:
132139
"""Get the necessary headers for webpoda requests."""
@@ -299,7 +306,7 @@ def download_daily_data(
299306

300307
# Iterate over the packet dates to make a query for each individual spacecraft day
301308
# packet_date 00:00:00 -> packet_date 23:59:59
302-
for date in unique_dates:
309+
for date in sorted(unique_dates):
303310
science_file = imap_data_access.ScienceFilePath.generate_from_inputs(
304311
instrument=instrument,
305312
data_level="l0",
@@ -315,6 +322,13 @@ def download_daily_data(
315322
daily_start_time = datetime.datetime.combine(date, datetime.time.min)
316323
daily_end_time = datetime.datetime.combine(date, datetime.time.max)
317324

325+
# Some instruments request a buffer of packets on either side of the midnight
326+
# boundary to ensure their packet groupings work together.
327+
buffer_minutes = _INSTRUMENT_BUFFER_MINUTES.get(instrument, 0)
328+
buffer_timedelta = datetime.timedelta(minutes=buffer_minutes)
329+
daily_start_time -= buffer_timedelta
330+
daily_end_time += buffer_timedelta
331+
318332
# Iterate over all apids, downloading the content for this time period
319333
# concatenating all the binary returns into a single binary file
320334
daily_packet_content = b"".join(

tests/test_webpoda.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ def test_download_daily_data(
108108
instrument, start_time, end_time, upload_to_server=upload_to_server
109109
)
110110

111+
# Make sure swapi was called with a buffer of 1 minute on either side of midnight
112+
call = mock_get_packet_binary_data_sctime.call_args_list[0][0]
113+
assert call == (
114+
1184,
115+
start_time - datetime.timedelta(minutes=1),
116+
datetime.datetime.combine(start_time, datetime.time.max)
117+
+ datetime.timedelta(minutes=1),
118+
)
119+
111120
# We expect two daily files to be created because we have packets
112121
# across two separate days
113122
for day in mock_get_packet_times_ert.return_value:

0 commit comments

Comments
 (0)