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
9 changes: 5 additions & 4 deletions imap_processing/ialirt/l0/process_hit.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,16 @@ 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)
hit_met = int(
grouped_data["hit_met"][(grouped_data["group"] == group).values].values[0]
)

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)}")
logger.info(f"Off-nominal value detected at {met_to_utc(hit_met)}")
continue

fast_rate_1 = grouped_data["hit_fast_rate_1"][
Expand All @@ -196,7 +197,7 @@ def process_hit(xarray_data: xr.Dataset) -> list[dict]:
_populate_instrument_header_items(met)
| {
"instrument": "hit",
"hit_epoch": int(met_to_ttj2000ns(mid_measurement)),
"hit_epoch": int(met_to_ttj2000ns(hit_met)),
"hit_e_a_side_low_en": Decimal(
f"{l1['IALRT_RATE_1'] + l1['IALRT_RATE_2']:.3f}"
),
Expand Down
40 changes: 34 additions & 6 deletions imap_processing/ialirt/utils/create_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
import xarray as xr
from cdflib.epochs import CDFepoch

from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes
from imap_processing.codice.constants import (
Expand All @@ -19,7 +20,6 @@
hit_restricted_fields,
swe_energy,
)
from imap_processing.spice.time import et_to_ttj2000ns, str_to_et


def create_xarray_from_records(records: list[dict]) -> xr.Dataset: # noqa: PLR0912
Expand Down Expand Up @@ -53,11 +53,39 @@ def create_xarray_from_records(records: list[dict]) -> xr.Dataset: # noqa: PLR0
dt = datetime.fromisoformat(date)

# Start and end of that UTC day
start_str = dt.date().isoformat() + "T00:00:00Z"
end_str = (dt.date() + timedelta(days=1)).isoformat() + "T00:00:00Z"

start_ttj2000 = et_to_ttj2000ns(str_to_et(start_str))
end_ttj2000 = et_to_ttj2000ns(str_to_et(end_str))
start_dt = dt.replace(hour=0, minute=0, second=0, microsecond=0)
end_dt = start_dt + timedelta(days=1)

start_ttj2000 = int(
CDFepoch.compute_tt2000(
[
start_dt.year,
start_dt.month,
start_dt.day,
start_dt.hour,
start_dt.minute,
start_dt.second,
0,
0,
0, # ms, us, ns
]
)
)
end_ttj2000 = int(
CDFepoch.compute_tt2000(
[
end_dt.year,
end_dt.month,
end_dt.day,
end_dt.hour,
end_dt.minute,
end_dt.second,
0,
0,
0, # ms, us, ns
]
)
)

for record in records:
inst = record.get("instrument")
Expand Down