Skip to content

Commit 3e2d13a

Browse files
authored
FIX: SWE l1b needs to handle all full-cycle case as well (#2463)
* FIX: SWE l1b needs to handle all full-cycle case as well Before we were only setting the local variable if there was a mismatch in the full cycle length compared to packets. We can ignore this if-block and just subset the dataset based on full cycle data regardless and the isel just won't do anything in the case of a full match. * MNT: Remove redundant checks and rename total_packets to n_cycles
1 parent 947a83a commit 3e2d13a

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

imap_processing/swe/l1b/swe_l1b.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,6 @@ def swe_l1b_science(dependencies: ProcessingInputCollection) -> xr.Dataset:
647647
science_files = dependencies.get_file_paths(descriptor="sci")
648648
l1a_data = load_cdf(science_files[0])
649649

650-
total_packets = len(l1a_data["science_data"].data)
651-
652650
l1a_data_copy = l1a_data.copy(deep=True)
653651

654652
# First convert some science data to engineering units
@@ -695,25 +693,18 @@ def swe_l1b_science(dependencies: ProcessingInputCollection) -> xr.Dataset:
695693
logger.info("No full cycle data found. Skipping.")
696694
return None
697695

698-
# In this case, we found incomplete cycle data. We need to filter
696+
# We may have potentially found incomplete cycle data. We need to filter
699697
# out all the data that does not make a full cycle.
700-
if len(full_cycle_data_indices) != total_packets:
701-
# Filter metadata and science data of packets that makes full cycles
702-
full_cycle_l1a_data = l1a_data_copy.isel({"epoch": full_cycle_data_indices})
703-
704-
# Update total packets
705-
total_packets = len(full_cycle_data_indices)
706-
logger.debug(
707-
"Quarters cycle after filtering: "
708-
f"{full_cycle_l1a_data['quarter_cycle'].data}"
709-
)
710-
if len(full_cycle_data_indices) != len(
711-
full_cycle_l1a_data["quarter_cycle"].data
712-
):
713-
raise ValueError(
714-
"Error: full cycle data indices and filtered quarter cycle data size "
715-
"mismatch"
716-
)
698+
n_cycles = len(full_cycle_data_indices)
699+
logger.info(
700+
f"Length of data [{len(l1a_data['science_data'])}]; "
701+
f"Number of full cycles found [{n_cycles}]"
702+
)
703+
full_cycle_l1a_data = l1a_data_copy.isel({"epoch": full_cycle_data_indices})
704+
705+
logger.debug(
706+
f"Quarters cycle after filtering: {full_cycle_l1a_data['quarter_cycle'].data}"
707+
)
717708

718709
# Main science processing steps
719710
# ---------------------------------------------------------------
@@ -767,7 +758,7 @@ def swe_l1b_science(dependencies: ProcessingInputCollection) -> xr.Dataset:
767758
# Store ESA energies of full cycle for L2 purposes.
768759
esa_energies = get_esa_energy_pattern(esa_lut_files[0])
769760
# Repeat the (24, 30) energy pattern n_cycles times along a new first axis
770-
esa_energies = np.repeat(esa_energies[np.newaxis, :, :], total_packets // 4, axis=0)
761+
esa_energies = np.repeat(esa_energies[np.newaxis, :, :], n_cycles // 4, axis=0)
771762
# Convert voltage to electron energy in eV by apply conversion factor
772763
esa_energies = esa_energies * swe_constants.ENERGY_CONVERSION_FACTOR
773764
# ------------------------------------------------------------------
@@ -785,7 +776,7 @@ def swe_l1b_science(dependencies: ProcessingInputCollection) -> xr.Dataset:
785776
# get indices of 3rd quarter cycle data packet in each full cycle
786777
# and use that to calculate center time of data acquisition time.
787778
# Quarter cycle indices: 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, ...
788-
indices_of_center_time = np.arange(2, total_packets, swe_constants.N_QUARTER_CYCLES)
779+
indices_of_center_time = np.arange(2, n_cycles, swe_constants.N_QUARTER_CYCLES)
789780

790781
center_time = combine_acquisition_time(
791782
full_cycle_l1a_data["acq_start_coarse"].data[indices_of_center_time],

0 commit comments

Comments
 (0)