Skip to content

Commit eb3dd0b

Browse files
Harrison #39 - SWYN/PMCL - Hi/Lo: Refactor CG-corrected pointing set code
1 parent a960243 commit eb3dd0b

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

imap_l3_processing/maps/rectangular_survival_probability.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,14 @@ def __init__(self, l1c_dataset: InputRectangularPointingSet, sensor: Sensor, spi
8888
dims=[CoordNames.ENERGY_ULTRA_L1C.value, CoordNames.GENERIC_PIXEL.value, CoordNames.AZ_EL_VECTOR.value],
8989
)
9090

91+
spacecraft_frame_energies_in_kev = dataset["energy_sc"].values / 1000.0
92+
9193
exposure = np.full_like(l1c_dataset.exposure_times, np.nan)
92-
best_match_energies = np.full_like(l1c_dataset.exposure_times, np.nan, dtype=np.float64)
93-
for cg_energy_index, cg_energy in np.ndenumerate(dataset['energy_sc'].values[0]):
94-
best_guess = np.inf
95-
best_guess_index = -1
96-
for e_i, energy in enumerate(energy_in_ev):
97-
guess = np.abs(np.log10(energy) - np.log10(cg_energy))
98-
if guess < best_guess:
99-
best_guess = guess
100-
best_guess_index = e_i
101-
if guess > best_guess:
102-
break
103-
exposure[0, cg_energy_index[0], cg_energy_index[1]] = l1c_dataset.exposure_times[
104-
0, best_guess_index, cg_energy_index[1]]
105-
best_match_energies[0, cg_energy_index[0], cg_energy_index[1]] = cg_energy / 1000
94+
for (energy_i, spin_angle_i), cg_energy in np.ndenumerate(dataset['energy_sc'].values[0]):
95+
distance_to_bins = np.abs(np.log10(energy_in_ev) - np.log10(cg_energy))
96+
closest_energy_bin_index = np.argmin(distance_to_bins)
97+
98+
exposure[0, energy_i, spin_angle_i] = l1c_dataset.exposure_times[0, closest_energy_bin_index, spin_angle_i]
10699

107100
else:
108101
self.az_el_points = hae_az_el_points
@@ -119,7 +112,7 @@ def __init__(self, l1c_dataset: InputRectangularPointingSet, sensor: Sensor, spi
119112
if cg_corrected:
120113
sp_interpolated_to_pset_angles = interpolate_angular_data_to_nearest_neighbor(
121114
self.azimuths, glows_dataset.spin_angle, glows_dataset.probability_of_survival[0])
122-
log_sc_frame_energies = np.log10(best_match_energies[0])
115+
log_sc_frame_energies = np.log10(spacecraft_frame_energies_in_kev[0])
123116

124117
sp_final = np.empty((1, len(energies), len(self.azimuths)))
125118
for spin_angle_index in range(len(self.azimuths)):

0 commit comments

Comments
 (0)