Skip to content

Commit 8e25334

Browse files
authored
2342 hi l2 update how statistical uncertainty is combined from calibration products (#2364)
* Change equation for how we combine statistical uncertainties across calibration products * Fix incorrect calculation of stat_unc_sc in interpolate_map_flux_to_helio_frame * Add check for interpolated statistical uncertianty
1 parent ba6f8bc commit 8e25334

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

imap_processing/ena_maps/utils/corrections.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,11 @@ def interpolate_map_flux_to_helio_frame(
707707
)
708708

709709
# Statistical uncertainty propagation (Equation 75):
710-
# δJ = J * sqrt((δJ_left/J_left)^2 * (1 + unc_factor^2) + (δJ_right/J_right)^2)
710+
# δJ = J * sqrt((δJ_left/J_left)^2 * (1 + unc_factor^2)
711+
# + unc_factor^2 * (δJ_right/J_right)^2)
711712
stat_unc_sc = flux_sc * np.sqrt(
712713
(stat_unc_left / flux_left) ** 2 * (1.0 + unc_factor**2)
713-
+ (stat_unc_right / flux_right) ** 2
714+
+ unc_factor**2 * (stat_unc_right / flux_right) ** 2
714715
)
715716

716717
# Systematic uncertainty propagation (Equation 76):

imap_processing/hi/hi_l2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,9 @@ def combine_calibration_products(
379379
combined_flux = weighted_flux_sum / flux_weights.sum(dim="calibration_prod")
380380

381381
map_ds["ena_intensity"] = combined_flux
382+
# Statistical uncertainty
382383
map_ds["ena_intensity_stat_uncert"] = np.sqrt(
383-
(map_ds["ena_intensity_stat_uncert"] ** 2).sum(dim="calibration_prod")
384+
1 / (1 / (map_ds["ena_intensity_stat_uncert"] ** 2)).sum(dim="calibration_prod")
384385
)
385386
# For systematic error, just do quadrature sum over the systematic error for
386387
# each calibration product.

imap_processing/tests/ena_maps/test_corrections.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,10 @@ def test_power_law_interpolation_accuracy(self):
712712
expected_flux_middle = (
713713
(e_sc**power_law_slope) * (e_helio / e_sc) * spatial_factor
714714
)
715+
unc_factor = np.log(e_sc / 500) / np.log(1000 / 500)
716+
expected_stat_uncert = expected_flux_middle * np.sqrt(
717+
0.1**2 * (1 + unc_factor**2) + unc_factor**2 * 0.1**2
718+
)
715719

716720
# Compare interpolated result to expected value
717721
# (should be very close for a perfect power-law)
@@ -721,6 +725,13 @@ def test_power_law_interpolation_accuracy(self):
721725
rtol=1e-10,
722726
)
723727

728+
# Check expected stat. unc.
729+
np.testing.assert_allclose(
730+
result_ds["ena_intensity_stat_uncert"].values[1, 0],
731+
expected_stat_uncert,
732+
rtol=1e-10,
733+
)
734+
724735
# The flux should be finite and positive
725736
assert np.all(np.isfinite(result_ds["ena_intensity"].values))
726737
assert np.all(result_ds["ena_intensity"].values > 0)

imap_processing/tests/hi/test_hi_l2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,8 @@ def test_statistical_uncertainty_combination_correctness():
632632
result_ds = combine_calibration_products(test_ds, geom_factors, esa_energies)
633633

634634
# Manual calculation of expected statistical uncertainty combination
635-
# stat_weights = 1/σ² = [1/151, 1/151]
636-
# combined_stat_unc = sqrt(1/sum(stat_weights)) = sqrt(2/151) = sqrt(20) ≈ 4.47
637-
expected_combined_stat_unc = np.sqrt(np.sum(stat_unc_values**2))
635+
# combined_stat_unc = sqrt(1/sum(1 / stat_unc**2))
636+
expected_combined_stat_unc = np.sqrt(1 / np.sum(1 / stat_unc_values**2))
638637
flux_weights = 1.0 / (np.array([101, 101]) + np.array([4, 16]))
639638
expected_flux = np.sum(flux_values.squeeze() * flux_weights) / np.sum(flux_weights)
640639

0 commit comments

Comments
 (0)