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
1 change: 1 addition & 0 deletions imap_processing/ialirt/l0/process_codice.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def process_codice(
_populate_instrument_header_items(met)
| {
"instrument": f"{sensor}",
"codice_lo_epoch": int(l1a_lo["epoch"]),
f"{sensor}_c_over_o_abundance": l2_lo.c_over_o_abundance,
f"{sensor}_mg_over_o_abundance": l2_lo.mg_over_o_abundance,
f"{sensor}_fe_over_o_abundance": l2_lo.fe_over_o_abundance,
Expand Down
14 changes: 14 additions & 0 deletions imap_processing/ialirt/l0/process_hit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
find_groups,
)
from imap_processing.ialirt.utils.time import calculate_time
from imap_processing.spice.time import met_to_ttj2000ns, met_to_utc

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -154,6 +155,17 @@ def process_hit(xarray_data: xr.Dataset) -> list[dict]:
incomplete_groups.append(group)
continue

hit_met = grouped_data["hit_met"][(grouped_data["group"] == group).values]
mid_measurement = int((hit_met[0] + hit_met[-1]) // 2)

status_values = grouped_data["hit_status"][
(grouped_data["group"] == group).values
]

if np.any(status_values == 0):
logger.info(f"Off-nominal value detected at {met_to_utc(mid_measurement)}")
continue

fast_rate_1 = grouped_data["hit_fast_rate_1"][
(grouped_data["group"] == group).values
]
Expand All @@ -164,12 +176,14 @@ def process_hit(xarray_data: xr.Dataset) -> list[dict]:
(grouped_data["group"] == group).values
]
met = grouped_data["met"][(grouped_data["group"] == group).values]

l1 = create_l1(fast_rate_1, fast_rate_2, slow_rate)

hit_data.append(
_populate_instrument_header_items(met)
| {
"instrument": "hit",
"hit_epoch": int(met_to_ttj2000ns(mid_measurement)),
"hit_e_a_side_low_en": int(l1["IALRT_RATE_1"] + l1["IALRT_RATE_2"]),
"hit_e_a_side_med_en": int(l1["IALRT_RATE_5"] + l1["IALRT_RATE_6"]),
"hit_e_a_side_high_en": int(l1["IALRT_RATE_7"]),
Expand Down
8 changes: 7 additions & 1 deletion imap_processing/ialirt/l0/process_swapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
find_groups,
)
from imap_processing.ialirt.utils.time import calculate_time
from imap_processing.spice.time import met_to_ttj2000ns
from imap_processing.swapi.l1.swapi_l1 import process_sweep_data
from imap_processing.swapi.l2.swapi_l2 import SWAPI_LIVETIME

Expand Down Expand Up @@ -163,9 +164,13 @@ def process_swapi_ialirt(
seq_values = grouped_dataset["swapi_seq_number"][
(grouped_dataset["group"] == group)
]

met = grouped_dataset["met"][(grouped_dataset["group"] == group).values]

swapi_met = grouped_dataset["swapi_acq"][
(grouped_dataset["group"] == group).values
]
mid_measurement = int((swapi_met[0] + swapi_met[-1]) // 2)

# Ensure no duplicates and all values from 0 to 11 are present
if not np.array_equal(seq_values.values.astype(int), np.arange(12)):
incomplete_groups.append(group)
Expand Down Expand Up @@ -209,6 +214,7 @@ def process_swapi_ialirt(
_populate_instrument_header_items(met)
| {
"instrument": "swapi",
"swapi_epoch": int(met_to_ttj2000ns(mid_measurement)),
"swapi_pseudo_proton_speed": Decimal(f"{pseudo_speed:.3f}"),
"swapi_pseudo_proton_density": Decimal(f"{pseudo_density:.3f}"),
"swapi_pseudo_proton_temperature": Decimal(f"{pseudo_temperature:.3f}"),
Expand Down
38 changes: 9 additions & 29 deletions imap_processing/tests/ialirt/unit/test_process_hit.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_process_spacecraft_packet(sc_packet_path):
)[478]
hit_product = process_hit(sc_xarray_data)

assert len(hit_product[0].keys()) == 17
assert len(hit_product[0].keys()) == 18


def generate_prefixes(prefixes):
Expand Down Expand Up @@ -172,34 +172,14 @@ def test_process_hit(xarray_data, caplog):

# Tests that it functions normally
hit_product = process_hit(xarray_data)
assert len(hit_product) == 15

# Make a subset of data that has values to check the calculations of process hit.
indices = (xarray_data["hit_met"] != 0).values.nonzero()[0]
xarray_data["hit_slow_rate"].values[indices[0] : indices[0] + 60] = 2
subset = xarray_data.isel(epoch=slice(indices[0], indices[0] + 60))

hit_product = process_hit(subset)

assert hit_product[0]["hit_e_a_side_low_en"] == 4
assert hit_product[0]["hit_e_a_side_med_en"] == 4
assert hit_product[0]["hit_e_b_side_low_en"] == 4
assert hit_product[0]["hit_e_b_side_high_en"] == 2
assert hit_product[0]["hit_e_b_side_med_en"] == 4
assert hit_product[0]["hit_he_omni_high_en"] == 2

# Create a scrambled set of subcom values.
xarray_data["hit_subcom"].values[indices[0] : indices[0] + 60] = [
i for i in range(29) for _ in range(2)
] + [59, 59]

with caplog.at_level("INFO"):
process_hit(subset)

assert any(
"skipped due to missing or duplicate pkt_counter values" in message
for message in caplog.text.splitlines()
)
assert len(hit_product) == 1

assert hit_product[0]["hit_e_a_side_low_en"] == 0
assert hit_product[0]["hit_e_a_side_med_en"] == 0
assert hit_product[0]["hit_e_b_side_low_en"] == 0
assert hit_product[0]["hit_e_b_side_high_en"] == 0
assert hit_product[0]["hit_e_b_side_med_en"] == 1
assert hit_product[0]["hit_he_omni_high_en"] == 0


def test_decom_packets(xarray_data, hit_test_data):
Expand Down