Skip to content

Commit 7f3ac25

Browse files
authored
MNT: Handle GLOWS empty hist and/or DE packets (#2432)
There may be no DE and/or hist packets returned after decomming the data, so we should gate the subsequent function calls to make sure that we are only processing when necessary.
1 parent 6fecc7b commit 7f3ac25

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

imap_processing/glows/l1a/glows_l1a.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,17 @@ def glows_l1a(packet_filepath: Path) -> list[xr.Dataset]:
5757
# Decompose packet file into histogram, and direct event data.
5858
hist_l0, de_l0 = decom_packets(packet_filepath)
5959

60-
l1a_de = process_de_l0(de_l0)
61-
l1a_hists = []
62-
for hist in hist_l0:
63-
l1a_hists.append(HistogramL1A(hist))
64-
6560
# Generate CDF files for each day
6661
output_datasets = []
67-
dataset = generate_histogram_dataset(l1a_hists, glows_attrs)
68-
output_datasets.append(dataset)
69-
70-
dataset = generate_de_dataset(l1a_de, glows_attrs)
71-
output_datasets.append(dataset)
62+
if hist_l0:
63+
l1a_hists = [HistogramL1A(hist) for hist in hist_l0]
64+
dataset = generate_histogram_dataset(l1a_hists, glows_attrs)
65+
output_datasets.append(dataset)
66+
67+
if de_l0:
68+
l1a_de = process_de_l0(de_l0)
69+
dataset = generate_de_dataset(l1a_de, glows_attrs)
70+
output_datasets.append(dataset)
7271

7372
return output_datasets
7473

imap_processing/tests/glows/test_glows_l1a_data.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import dataclasses
33
import json
44
from pathlib import Path
5+
from unittest import mock
56

67
import numpy as np
78
import pandas as pd
@@ -559,3 +560,11 @@ def test_expected_hist_results(l1a_dataset):
559560

560561
for field in compare_fields:
561562
assert np.array_equal(data[field], datapoint[field].data)
563+
564+
565+
@mock.patch("imap_processing.glows.l1a.glows_l1a.decom_packets")
566+
def test_glows_l1a_no_packet_data(decom_packets_mock):
567+
# Should return empty list when no packet data is present
568+
decom_packets_mock.return_value = ([], [])
569+
output = glows_l1a("fake/filepath/packets.bin")
570+
assert output == []

0 commit comments

Comments
 (0)