@@ -1166,27 +1166,32 @@ def calculate_flux_corrections(dataset: xr.Dataset, flux_factors: Path) -> xr.Da
11661166
11671167 # Flux correction
11681168 corrector = PowerLawFluxCorrector (flux_factors )
1169- # FluxCorrector works on (energy, :) arrays, so we need to flatten the map
1170- # spatial dimensions for the correction and then reshape back after.
1171- input_shape = dataset ["ena_intensity" ].shape [1 :] # Exclude epoch dimension
1172- intensity = dataset ["ena_intensity" ].values [0 ].reshape (len (dataset ["energy" ]), - 1 )
1173- stat_uncert = (
1174- dataset ["ena_intensity_stat_uncert" ]
1175- .values [0 ]
1176- .reshape (len (dataset ["energy" ]), - 1 )
1177- )
1178- corrected_intensity , corrected_stat_unc = corrector .apply_flux_correction (
1179- intensity ,
1180- stat_uncert ,
1181- dataset ["energy" ].data ,
1182- )
1183- # Add the size 1 epoch dimension back in to the corrected fluxes.
1184- dataset ["ena_intensity" ].data = corrected_intensity .reshape (input_shape )[
1185- np .newaxis , ...
1186- ]
1187- dataset ["ena_intensity_stat_uncert" ].data = corrected_stat_unc .reshape (input_shape )[
1188- np .newaxis , ...
1189- ]
1169+
1170+ # NOTE: We need to apply this to both total flux and background flux
1171+ for var in ["ena" , "bg" ]:
1172+ # FluxCorrector works on (energy, :) arrays, so we need to flatten the map
1173+ # spatial dimensions for the correction and then reshape back after.
1174+ input_shape = dataset [f"{ var } _intensity" ].shape [1 :] # Exclude epoch dimension
1175+ intensity = (
1176+ dataset [f"{ var } _intensity" ].values [0 ].reshape (len (dataset ["energy" ]), - 1 )
1177+ )
1178+ stat_uncert = (
1179+ dataset [f"{ var } _intensity_stat_uncert" ]
1180+ .values [0 ]
1181+ .reshape (len (dataset ["energy" ]), - 1 )
1182+ )
1183+ corrected_intensity , corrected_stat_unc = corrector .apply_flux_correction (
1184+ intensity ,
1185+ stat_uncert ,
1186+ dataset ["energy" ].data ,
1187+ )
1188+ # Add the size 1 epoch dimension back in to the corrected fluxes.
1189+ dataset [f"{ var } _intensity" ].data = corrected_intensity .reshape (input_shape )[
1190+ np .newaxis , ...
1191+ ]
1192+ dataset [f"{ var } _intensity_stat_uncert" ].data = corrected_stat_unc .reshape (
1193+ input_shape
1194+ )[np .newaxis , ...]
11901195
11911196 return dataset
11921197
0 commit comments