Description of Refactoring/Improvement
The SHE validation workflow requires access to the noise estimate associated with each observation to compute goodness-of-fit metrics for the WaveDiff model.
Currently, train_utils.calculate_sample_weights performs two distinct operations:
- estimate the noise level using the
utils.NoiseEstimator class;
- convert this estimate into a scalar sample weight using a median-based reduction.
The current implementation does not expose the intermediate noise estimate independently, limiting its reuse for validation metrics such as reduced χ².
Goals and Objectives
Current Code Behaviour
calculate_sample_weights currently combines two responsibilities:
- Estimate the noise level for each observation using
utils.NoiseEstimator, which uses a robust MAD-based estimator on unmasked background pixels.
- Convert this estimate into a scalar sample weight used during training.
The coupling of these operations prevents the noise estimate from being accessed independently by downstream validation workflows.
Proposed Changes
Introduce a dedicated helper:
estimate_noise_sigma(...)
which returns the per-observation noise standard deviation estimated by utils.NoiseEstimator.
Refactor:
calculate_sample_weights(...)
to use:
sigma = estimate_noise_sigma(...)
weights = ...
while preserving the current training behaviour.
Expected Benefits
- Separates data-derived noise estimation from training-specific weighting.
- Makes the uncertainty information available for future goodness-of-fit calculations.
- Improves clarity around the statistical assumptions used by the training pipeline.
- Avoids duplicating noise estimation logic in validation workflows.
Dependencies
- Compatibility with the SHE validation pipeline.
- Conversion from noise estimates to an inverse covariance representation remains dependent on the uncertainty model adopted by the validation workflow and is outside the scope of this refactor.
Description of Refactoring/Improvement
The SHE validation workflow requires access to the noise estimate associated with each observation to compute goodness-of-fit metrics for the WaveDiff model.
Currently,
train_utils.calculate_sample_weightsperforms two distinct operations:utils.NoiseEstimatorclass;The current implementation does not expose the intermediate noise estimate independently, limiting its reuse for validation metrics such as reduced χ².
Goals and Objectives
estimate_noise_sigmafunction.estimate_noise_sigmainternally.Current Code Behaviour
calculate_sample_weightscurrently combines two responsibilities:utils.NoiseEstimator, which uses a robust MAD-based estimator on unmasked background pixels.The coupling of these operations prevents the noise estimate from being accessed independently by downstream validation workflows.
Proposed Changes
Introduce a dedicated helper:
which returns the per-observation noise standard deviation estimated by
utils.NoiseEstimator.Refactor:
to use:
while preserving the current training behaviour.
Expected Benefits
Dependencies