From e4bdb0b141030a8b3ed70b5b55514efd3afd9e05 Mon Sep 17 00:00:00 2001 From: David Gathright Date: Sat, 31 Jan 2026 08:51:04 -0700 Subject: [PATCH 1/5] Lo pointing set and map background rates update #2647 Worked with Nathan to implement addition of background to intensities per the latest update to the mapping document. --- imap_processing/lo/l2/lo_l2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/imap_processing/lo/l2/lo_l2.py b/imap_processing/lo/l2/lo_l2.py index 39b75e1d2..de0d2998b 100644 --- a/imap_processing/lo/l2/lo_l2.py +++ b/imap_processing/lo/l2/lo_l2.py @@ -1307,6 +1307,23 @@ 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 + + :where= + ( dataset["bg_intensity"] * bg_logarithmic_stability_factor ) **2 ) + # Flux correction corrector = PowerLawFluxCorrector(flux_factors) From 8a5f818ff560db39d13b3cb461b677adb410c58a Mon Sep 17 00:00:00 2001 From: David Gathright Date: Sat, 31 Jan 2026 09:14:50 -0700 Subject: [PATCH 2/5] Fixed issue with lines being too long --- imap_processing/lo/l2/lo_l2.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/imap_processing/lo/l2/lo_l2.py b/imap_processing/lo/l2/lo_l2.py index de0d2998b..4fc7cbbd7 100644 --- a/imap_processing/lo/l2/lo_l2.py +++ b/imap_processing/lo/l2/lo_l2.py @@ -1311,8 +1311,10 @@ def calculate_flux_corrections(dataset: xr.Dataset, flux_factors: Path) -> xr.Da # 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 ) + 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( From 69d0591aead0345c397492e674a3f8832775dde2 Mon Sep 17 00:00:00 2001 From: David Gathright Date: Sat, 31 Jan 2026 09:16:52 -0700 Subject: [PATCH 3/5] Fixed cut and paste error; re-ran to completion --- imap_processing/lo/l2/lo_l2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imap_processing/lo/l2/lo_l2.py b/imap_processing/lo/l2/lo_l2.py index 4fc7cbbd7..74522deab 100644 --- a/imap_processing/lo/l2/lo_l2.py +++ b/imap_processing/lo/l2/lo_l2.py @@ -1323,7 +1323,7 @@ def calculate_flux_corrections(dataset: xr.Dataset, flux_factors: Path) -> xr.Da ( dataset["bg_intensity"] * bg_logarithmic_stability_factor ) **2 ) dataset["bg_intensity_sys_err"] = np.sqrt( ( dataset["bg_intensity_sys_err"] ) **2 - + :where= + + ( dataset["bg_intensity"] * bg_logarithmic_stability_factor ) **2 ) # Flux correction From d866bb6ba4ce44580939a321a1b0f84f85dce0b3 Mon Sep 17 00:00:00 2001 From: David Gathright Date: Sat, 31 Jan 2026 09:20:00 -0700 Subject: [PATCH 4/5] Removed trailing whitespace from lines --- imap_processing/lo/l2/lo_l2.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/imap_processing/lo/l2/lo_l2.py b/imap_processing/lo/l2/lo_l2.py index 74522deab..43136a865 100644 --- a/imap_processing/lo/l2/lo_l2.py +++ b/imap_processing/lo/l2/lo_l2.py @@ -1311,18 +1311,18 @@ def calculate_flux_corrections(dataset: xr.Dataset, flux_factors: Path) -> xr.Da # 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["ena_intensity"] += ( dataset["bg_intensity"] * bg_logarithmic_stability_factor ) - dataset["bg_intensity"] += ( + 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["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_sys_err"] = np.sqrt( + ( dataset["bg_intensity_sys_err"] ) **2 + ( dataset["bg_intensity"] * bg_logarithmic_stability_factor ) **2 ) From 831f693c64b6a4e3b4f82e6c5481db6222308f65 Mon Sep 17 00:00:00 2001 From: David Gathright Date: Sat, 31 Jan 2026 09:32:07 -0700 Subject: [PATCH 5/5] Learned how to use pre-commit and applied fixes. --- imap_processing/lo/l2/lo_l2.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/imap_processing/lo/l2/lo_l2.py b/imap_processing/lo/l2/lo_l2.py index 43136a865..9abe4b43c 100644 --- a/imap_processing/lo/l2/lo_l2.py +++ b/imap_processing/lo/l2/lo_l2.py @@ -1312,19 +1312,19 @@ def calculate_flux_corrections(dataset: xr.Dataset, flux_factors: Path) -> xr.Da # 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 ) + 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["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 ) + (dataset["bg_intensity_sys_err"]) ** 2 + + (dataset["bg_intensity"] * bg_logarithmic_stability_factor) ** 2 + ) # Flux correction corrector = PowerLawFluxCorrector(flux_factors)