Skip to content

Commit 5c619ad

Browse files
authored
2435 hi l2 updated systematic error calculation (IMAP-Science-Operations-Center#2560)
* Update equation for ena_intensity_sys_err * Fix systematic error calculation - multiply instead of divide * Fix systematic error calculation - use bg_rates, not bg_rates_unc * Remove systematic error from weights used to combine calibration products * Update test to remove use of statistical uncertainty when combinging cal products * Get rid of check that variance is >= 1 in calculation of imporved variance
1 parent fcd5f85 commit 5c619ad

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

imap_processing/hi/hi_l2.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ def calculate_ena_intensity(
305305
map_ds["ena_intensity_stat_uncert"] = (
306306
map_ds["ena_signal_rate_stat_unc"] / flux_conversion_divisor
307307
)
308-
map_ds["ena_intensity_sys_err"] = map_ds["bg_rates_unc"] / flux_conversion_divisor
308+
map_ds["ena_intensity_sys_err"] = (
309+
np.sqrt(map_ds["bg_rates"] * map_ds["exposure_factor"])
310+
/ map_ds["exposure_factor"]
311+
/ flux_conversion_divisor
312+
)
309313

310314
# Combine calibration products using proper weighted averaging
311315
# as described in Hi Algorithm Document Section 3.1.2
@@ -367,16 +371,11 @@ def combine_calibration_products(
367371
map_ds, geometric_factors, esa_energies
368372
)
369373

370-
# Calculate total variance
371-
# Note that sys_err contains uncertainty, so it must be squared to get
372-
# the systematic variance needed in this equation.
373-
total_variance = improved_stat_variance + sys_err**2
374-
375374
# Perform inverse-variance weighted averaging
376375
# Handle divide by zero and invalid values
377376
with np.errstate(divide="ignore", invalid="ignore"):
378377
# Use total variance weights for flux combination
379-
flux_weights = 1.0 / total_variance
378+
flux_weights = 1.0 / improved_stat_variance
380379
weighted_flux_sum = (ena_flux * flux_weights).sum(dim="calibration_prod")
381380
combined_flux = weighted_flux_sum / flux_weights.sum(dim="calibration_prod")
382381

@@ -450,11 +449,6 @@ def _calculate_improved_stat_variance(
450449
# Total count rates for Poisson uncertainty calculation
451450
total_count_rates_for_uncertainty = map_ds["bg_rates"] + averaged_signal_rates
452451

453-
# Ensure non-negative values for sqrt and minimum of 1 for uncertainty calculation
454-
total_count_rates_for_uncertainty = xr.where(
455-
total_count_rates_for_uncertainty < 1, 1, total_count_rates_for_uncertainty
456-
)
457-
458452
logger.debug("Computing improved flux uncertainties")
459453
# Statistical variance:
460454
with np.errstate(divide="ignore", invalid="ignore"):

imap_processing/tests/hi/test_hi_l2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def test_statistical_uncertainty_combination_correctness():
644644
# Manual calculation of expected statistical uncertainty combination
645645
# combined_stat_unc = sqrt(1/sum(1 / stat_unc**2))
646646
expected_combined_stat_unc = np.sqrt(1 / np.sum(1 / stat_unc_values**2))
647-
flux_weights = 1.0 / (np.array([101, 101]) + np.array([4, 16]))
647+
flux_weights = 1.0 / np.array([101, 101])
648648
expected_flux = np.sum(flux_values.squeeze() * flux_weights) / np.sum(flux_weights)
649649

650650
np.testing.assert_almost_equal(

0 commit comments

Comments
 (0)