Skip to content

Commit

Permalink
Merge pull request #682 from nabobalis/msgh
Browse files Browse the repository at this point in the history
improve rebin uncertainty message
  • Loading branch information
DanRyanIrish authored Apr 23, 2024
2 parents 1db2816 + c2efd91 commit b1a30c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions ndcube/ndcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,10 +1160,11 @@ def my_propagate(uncertainty, data, mask, **kwargs):
if propagate_uncertainties:
if self.uncertainty is None:
warnings.warn("Uncertainties cannot be propagated as there are no uncertainties, "
"i.e. self.uncertainty is None.")
"i.e., the `uncertainty` keyword was never set on creation of this NDCube.")
elif isinstance(self.uncertainty, astropy.nddata.UnknownUncertainty):
warnings.warn("Uncertainty is an UnknownUncertainty which does not "
"support uncertainty propagation.")
warnings.warn("The uncertainty on this NDCube has no known way to propagate forward and so will be dropped. "
"To create an uncertainty that can propagate, please see "
"https://docs.astropy.org/en/stable/uncertainty/index.html")
elif (not operation_ignores_mask
and (self.mask is True or (self.mask is not None
and not isinstance(self.mask, bool)
Expand Down
6 changes: 3 additions & 3 deletions ndcube/tests/test_ndcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def test_wcs_type_after_init(ndcube_3d_ln_lt_l, wcs_3d_l_lt_ln):
def test_rebin(ndcube_3d_l_ln_lt_ectime):
cube = ndcube_3d_l_ln_lt_ectime[:, 1:]
bin_shape = (10, 2, 1)
with pytest.warns(UserWarning, match="Uncertainty is an UnknownUncertainty which does not support uncertainty propagation."):
with pytest.warns(UserWarning, match="The uncertainty on this NDCube has no known way to propagate forward"):
output = cube.rebin(bin_shape, operation=np.sum, propagate_uncertainties=True)
output_sc, output_spec = output.axis_world_coords(wcs=output.wcs)
output_time, = output.axis_world_coords(wcs=output.extra_coords)
Expand Down Expand Up @@ -845,7 +845,7 @@ def test_rebin_no_ec(ndcube_3d_l_ln_lt_ectime):
cube = ndcube_3d_l_ln_lt_ectime[:, 1:]
cube._extra_coords = ExtraCoords(cube)
bin_shape = (10, 2, 1)
with pytest.warns(UserWarning, match="Uncertainty is an UnknownUncertainty which does not support uncertainty propagation."):
with pytest.warns(UserWarning, match="The uncertainty on this NDCube has no known way to propagate forward"):
output = cube.rebin(bin_shape, operation=np.mean, propagate_uncertainties=True)
assert output.extra_coords.is_empty

Expand Down Expand Up @@ -942,7 +942,7 @@ def test_rebin_no_propagate(ndcube_2d_ln_lt_mask_uncert):

cube._mask = False
cube._uncertainty = UnknownUncertainty(cube.data * 0.1)
with pytest.warns(UserWarning, match="Uncertainty is an UnknownUncertainty which does not support uncertainty propagation."):
with pytest.warns(UserWarning, match="The uncertainty on this NDCube has no known way to propagate forward"):
output = cube.rebin(bin_shape, operation=np.sum, propagate_uncertainties=True)
assert output.uncertainty is None

Expand Down

0 comments on commit b1a30c8

Please sign in to comment.