diff --git a/imap_processing/lo/l2/lo_l2.py b/imap_processing/lo/l2/lo_l2.py index 39b75e1d2..9abe4b43c 100644 --- a/imap_processing/lo/l2/lo_l2.py +++ b/imap_processing/lo/l2/lo_l2.py @@ -1307,6 +1307,25 @@ def calculate_flux_corrections(dataset: xr.Dataset, flux_factors: Path) -> xr.Da """ logger.info("Applying flux corrections") + bg_logarithmic_stability_factor = 0.04 + + # Add in the background intensity to ensure that logarithms behave + # properly in the flux corrector when intensities are zero or very low. + dataset["ena_intensity"] += ( + dataset["bg_intensity"] * bg_logarithmic_stability_factor + ) + dataset["bg_intensity"] += dataset["bg_intensity"] * bg_logarithmic_stability_factor + + # Commensurately, adjust the uncertainties to account for this addition + dataset["ena_intensity_stat_uncert"] = np.sqrt( + (dataset["ena_intensity_stat_uncert"]) ** 2 + + (dataset["bg_intensity"] * bg_logarithmic_stability_factor) ** 2 + ) + dataset["bg_intensity_sys_err"] = np.sqrt( + (dataset["bg_intensity_sys_err"]) ** 2 + + (dataset["bg_intensity"] * bg_logarithmic_stability_factor) ** 2 + ) + # Flux correction corrector = PowerLawFluxCorrector(flux_factors)