From cc4228b5d5957e73e73437d6eb06aeb36559e567 Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Tue, 23 Apr 2024 14:46:03 +0200 Subject: [PATCH 1/3] improve message hopefully --- ndcube/ndcube.py | 7 ++++--- ndcube/tests/test_ndcube.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ndcube/ndcube.py b/ndcube/ndcube.py index 40af1ba61..9ddb4098b 100644 --- a/ndcube/ndcube.py +++ b/ndcube/ndcube.py @@ -1138,10 +1138,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 set 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) diff --git a/ndcube/tests/test_ndcube.py b/ndcube/tests/test_ndcube.py index f7e2bd4d8..413324073 100644 --- a/ndcube/tests/test_ndcube.py +++ b/ndcube/tests/test_ndcube.py @@ -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 set 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) @@ -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 set 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 @@ -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 set 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 From fe8795a598a7f61410af5dc7026f42809d80521a Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Tue, 23 Apr 2024 15:39:39 +0200 Subject: [PATCH 2/3] Update ndcube/ndcube.py Co-authored-by: Stuart Mumford --- ndcube/ndcube.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndcube/ndcube.py b/ndcube/ndcube.py index 9ddb4098b..e41fb0f29 100644 --- a/ndcube/ndcube.py +++ b/ndcube/ndcube.py @@ -1140,7 +1140,7 @@ def my_propagate(uncertainty, data, mask, **kwargs): warnings.warn("Uncertainties cannot be propagated as there are no uncertainties, " "i.e., the `uncertainty` keyword was never set on creation of this NDCube.") elif isinstance(self.uncertainty, astropy.nddata.UnknownUncertainty): - warnings.warn("The set uncertainty on this NDCube has no known way to propagate forward and so will be dropped. " + 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 From c2efd9132456ddb94d93425e4b3bc9f835646f7c Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Tue, 23 Apr 2024 15:40:13 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- ndcube/tests/test_ndcube.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ndcube/tests/test_ndcube.py b/ndcube/tests/test_ndcube.py index 413324073..85572d906 100644 --- a/ndcube/tests/test_ndcube.py +++ b/ndcube/tests/test_ndcube.py @@ -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="The set uncertainty on this NDCube has no known way to propagate forward"): + 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) @@ -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="The set uncertainty on this NDCube has no known way to propagate forward"): + 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 @@ -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="The set uncertainty on this NDCube has no known way to propagate forward"): + 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