Skip to content
Open
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
28 changes: 11 additions & 17 deletions imap_processing/ialirt/l0/process_swe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move these lines into read_in_flight_cal_data()? it seems like it would be useful for science too.

# 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()
Expand All @@ -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
Expand All @@ -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,
)

Expand Down