Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion imap_processing/ialirt/l0/process_swe.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,17 @@ def process_swe(accumulated_data: xr.Dataset, in_flight_cal_files: list) -> list
# Add required parameters.
accumulated_data["met"] = met

# Drop any off-nominal SWE groups
nominal_data = accumulated_data.where(
accumulated_data["swe_nom_flag"] != 0,
drop=True,
)

# Get total full cycle data available for processing.
# There are 60 packets in a set so (0, 59) is the range.
grouped_data = find_groups(accumulated_data, (0, 59), "swe_seq", "time_seconds")
grouped_data = find_groups(
nominal_data, (0, 59), "swe_seq", "met", check_src_seq_ctr=False
)
unique_groups = np.unique(grouped_data["group"])
swe_data: list[dict] = []
incomplete_groups = []
Expand Down
10 changes: 8 additions & 2 deletions imap_processing/ialirt/utils/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def find_groups(
sequence_range: tuple,
sequence_name: str,
time_name: str,
check_src_seq_ctr: bool = True,
) -> xr.Dataset:
"""
Group data based on time and sequence number values.
Expand All @@ -64,6 +65,8 @@ def find_groups(
Name of the sequence variable.
time_name : str
Name of the time variable.
check_src_seq_ctr : bool | True
Check for incrementing src_seq_ctr.

Returns
-------
Expand Down Expand Up @@ -114,7 +117,10 @@ def find_groups(
# group (epoch) int64 7kB 1 1 1 1 1 1 1 1 1 ... 15 15 15 15 15 15 15 15 15
grouped_data = grouped_data.assign_coords(group=("epoch", group_labels))

# Filter out groups with non-sequential src_seq_ctr values.
filtered_data = filter_valid_groups(grouped_data)
if check_src_seq_ctr:
# Filter out groups with non-sequential src_seq_ctr values.
filtered_data = filter_valid_groups(grouped_data)
else:
filtered_data = grouped_data

return filtered_data
17 changes: 17 additions & 0 deletions imap_processing/tests/ialirt/unit/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,20 @@ def test_find_groups(test_data):
grouped_data = find_groups(test_data, (0, 3), "sequence", "time_seconds")

assert np.all(np.unique(grouped_data["group"]) == np.array([1, 3]))


def test_find_groups_no_valid(test_data):
"""Tests the find_groups function when no valid groups are found."""

flag = np.ones(np.size(test_data["src_seq_ctr"]), dtype=int)
flag[-1] = 0

test_data["swe_nom_flag"] = ("epoch", flag)

nominal_data = test_data.where(
test_data["swe_nom_flag"] != 0,
drop=True,
)
grouped_data = find_groups(nominal_data, (0, 3), "sequence", "time_seconds")

assert np.all(np.unique(grouped_data["group"]) == np.array([1]))
1 change: 1 addition & 0 deletions imap_processing/tests/ialirt/unit/test_process_swe.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def test_process_spacecraft_packet(
np.arange(462466219, 462466219 + n, dtype=np.uint32),
)
sc_xarray_data["swe_seq"] = ("epoch", np.arange(n) % 60)
sc_xarray_data["swe_nom_flag"] = xr.ones_like(sc_xarray_data["swe_nom_flag"])

in_flight_cal_file = (
imap_module_directory
Expand Down