From f02e5c9c31a66c16fbd4977544906304d2af1707 Mon Sep 17 00:00:00 2001 From: Laura Sandoval Date: Tue, 3 Feb 2026 14:07:00 -0700 Subject: [PATCH] select last from time --- imap_processing/ialirt/l0/process_swe.py | 28 ++++++++++-------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/imap_processing/ialirt/l0/process_swe.py b/imap_processing/ialirt/l0/process_swe.py index 7389f28f7..a72c8f0b5 100644 --- a/imap_processing/ialirt/l0/process_swe.py +++ b/imap_processing/ialirt/l0/process_swe.py @@ -520,6 +520,11 @@ def process_swe(accumulated_data: xr.Dataset, in_flight_cal_files: list) -> list # Interpolate to find the correct calibration factor in_flight_cal_df = read_in_flight_cal_data(in_flight_cal_files) + in_flight_cal_df = ( + in_flight_cal_df.dropna(subset=["met_time"]) + .sort_values("met_time") + .reset_index(drop=True) + ) # Get names of all 7 cems in the calibration file cal_cols = [f"cem{i}" for i in range(1, 8)] cal_met = in_flight_cal_df["met_time"].to_numpy() @@ -533,15 +538,10 @@ def process_swe(accumulated_data: xr.Dataset, in_flight_cal_files: list) -> list ) // 2 # Interpolate to the appropriate calibration factor + idx = np.searchsorted(cal_met, group_time_first_half_mid, side="right") - 1 + interp_cal_first_half = np.array( - [ - np.interp( - int(group_time_first_half_mid), - cal_met, - in_flight_cal_df[cem].to_numpy(), - ) - for cem in cal_cols - ], + [in_flight_cal_df[cem].iloc[idx] for cem in cal_cols], dtype=np.float64, ) # Find the middle timestamp of the second group @@ -551,16 +551,10 @@ def process_swe(accumulated_data: xr.Dataset, in_flight_cal_files: list) -> list group_time_second_half_mid = ( group_time_second_half[0] + group_time_second_half[-1] ) // 2 - # Interpolate to the appropriate calibration factor + idx = np.searchsorted(cal_met, group_time_second_half_mid, side="right") - 1 + interp_cal_second_half = np.array( - [ - np.interp( - int(group_time_second_half_mid), - cal_met, - in_flight_cal_df[cem].to_numpy(), - ) - for cem in cal_cols - ], + [in_flight_cal_df[cem].iloc[idx] for cem in cal_cols], dtype=np.float64, )