Skip to content

Commit 58376ee

Browse files
authored
FIX: Handle potential NaNs in the middle of the repointing files (#278)
We are getting files with NaN values in the middle and that is causing the first conversion to date of the start_time to fail now. Check for that case and skip over any repointings with an invalid start date.
1 parent 4b499e3 commit 58376ee

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

imap_data_access/webpoda.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,16 @@ def download_repointing_data(
422422
# NOTE: We iterate over the repointings rather than the packet times because it is
423423
# assumed to be the shorter list (1/day vs 1000s of packets/day per apid)
424424
for i in range(len(repointings) - 1):
425-
pointing_start = datetime.datetime.strptime(
426-
repointings[i]["repoint_end_utc"], "%Y-%m-%d %H:%M:%S.%f"
427-
)
425+
# skip i and i+1 values that are NaN
426+
if repointings[i]["repoint_end_utc"].lower() == "nan":
427+
# This pointing never "started"
428+
continue
428429
if repointings[i + 1]["repoint_end_utc"].lower() == "nan":
429430
# Missing repointing end time, so it isn't a complete "pointing" yet.
430431
continue
432+
pointing_start = datetime.datetime.strptime(
433+
repointings[i]["repoint_end_utc"], "%Y-%m-%d %H:%M:%S.%f"
434+
)
431435
if pointing_start > packet_times[-1]:
432436
# This pointing is after the last packet time, so skip it
433437
logger.debug(

tests/test_webpoda.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def test_download_repointing_data(
164164
# An unfinished repointing maneuver may have NaNs in the end times
165165
# Make sure we can handle this and ignore it
166166
"10,0,NaN,NaN,2024-12-03T00:00:00.000000,NaN,4\n"
167+
"10,0,12,0,2024-12-04T00:00:00.000000,2024-12-04 00:15:00.000,5\n"
167168
)
168169

169170
start_time = datetime.datetime(2024, 12, 1, 0, 0, 0)

0 commit comments

Comments
 (0)