ndcube icon indicating copy to clipboard operation
ndcube copied to clipboard

Allow custom uncertainty propagation functions to operation on UnknownUncertainty objects in NDCube.rebin

Open DanRyanIrish opened this issue 2 years ago • 0 comments

Describe the feature

Currently NDCube.rebin raises a warning if the uncertainty type is unknown (see here) and proceeds without propagating the uncertainty. While this is justified for the default uncertainty propagation function, it is confusing as it allows users to supply a disallowed kwarg without erroring. Moreover, users may have "unknown" uncertainty types that they know how to propagate, e.g. instrument-specific uncertainties. However, this is forbidden by the current NDCube.rebin implementation. Instead, if a user supplies a propagation function, the responsibility for deciding what types are valid should go to that function.

Proposed solution

Move the check at L1135 to L1146 and convert the warning to an error, i.e.

if propagate_uncertainties is True:
    if isinstance(self.uncertainty, astropy.nddata.UnknownUncertainty):
        raise ValueError("self.uncertainty is of type UnknownUncertainty which does not "
                         "support uncertainty propagation.")
    propagate_uncertainties = utils.cube.propagate_rebin_uncertainties
# Continue function...

This will error if the uncertainty type is unknown only if the default propagation function is used.

DanRyanIrish avatar Sep 11 '23 09:09 DanRyanIrish