|
2 | 2 | import pytest |
3 | 3 |
|
4 | 4 | import astropy.units as u |
5 | | - |
6 | 5 | import astropy.wcs |
7 | 6 | from astropy.nddata import NDData, StdDevUncertainty |
| 7 | + |
8 | 8 | from ndcube import NDCube |
9 | 9 | from ndcube.tests.helpers import assert_cubes_equal |
10 | 10 | from ndcube.utils.exceptions import NDCubeUserWarning |
@@ -343,43 +343,87 @@ def test_cube_arithmetic_multiply(ndcube_2d_ln_lt_units, value): |
343 | 343 |
|
344 | 344 |
|
345 | 345 | @pytest.mark.parametrize(("ndc", "value", "expected_kwargs"), |
346 | | - [ |
347 | | - ("ndcube_2d_ln_lt_no_unit_no_unc_no_mask_2", NDData(np.ones((2, 3)), |
348 | | - wcs=None), |
349 | | - {"data": np.array([[0, 1, 2], [3, 4, 5]])} # neither of the two has uncertainty or mask or unit. |
350 | | - ), |
351 | | - ("ndcube_2d_ln_lt_no_unit_no_unc_no_mask_2", NDData(np.ones((2, 3)), |
352 | | - wcs=None, |
353 | | - uncertainty=StdDevUncertainty(np.ones((2, 3))*0.1), |
354 | | - mask=np.ones((2, 3), dtype=bool), |
355 | | - unit=u.ct), |
356 | | - {"data": np.array([[0, 1, 2], [3, 4, 5]]), |
357 | | - "uncertainty": astropy.nddata.StdDevUncertainty(np.ones((2, 3))*0.1), |
358 | | - "mask": np.ones((2, 3), dtype=bool), |
359 | | - "unit": u.ct |
360 | | - }# ndc has no mask no uncertainty no unit, but nddata has all. |
361 | | - ), |
362 | | - ("ndcube_2d_ln_lt_unit_unc_mask", NDData(np.ones((2, 3)), |
363 | | - wcs=None, |
364 | | - uncertainty=StdDevUncertainty(np.ones((2, 3))*0.1), |
365 | | - mask=np.ones((2, 3), dtype=bool), |
366 | | - unit=u.ct), |
367 | | - {"unit": u.ct**2, |
368 | | - "data": np.array([[0, 1, 2], [3, 4, 5]]), |
369 | | - "uncertainty": astropy.nddata.StdDevUncertainty(np.array([[0.1118034, 0.1118034, 0.1118034], |
370 | | - [0.1118034, 0.1118034, 0.1118034]])), |
371 | | - "mask": np.ones((2, 3), dtype=bool)} # both of them have uncertainty and mask and unit. |
372 | | - ) |
| 346 | + [( |
| 347 | + "ndcube_2d_ln_lt_no_unit_no_unc_no_mask_2", |
| 348 | + NDData(np.ones((2, 3)) + 1, wcs=None), |
| 349 | + {"data": np.array([[0, 2, 4], [6, 8, 10]])} |
| 350 | + ), |
| 351 | + ( |
| 352 | + "ndcube_2d_ln_lt_no_unit_no_unc_no_mask_2", |
| 353 | + NDData(np.ones((2, 3)) + 1, |
| 354 | + wcs=None, |
| 355 | + uncertainty=StdDevUncertainty((np.ones((2, 3)) + 1) * 0.1), |
| 356 | + mask=np.array([[True, False, False], [False, True, False]]), |
| 357 | + unit=u.ct), |
| 358 | + {"data": np.array([[0, 2, 4], [6, 8, 10]]), |
| 359 | + "uncertainty": astropy.nddata.StdDevUncertainty((np.ones((2, 3)) + 1) * 0.1), |
| 360 | + "mask": np.array([[True, False, False], [False, True, False]]), |
| 361 | + "unit": u.ct} # ndc has no mask no uncertainty no unit, but nddata has all. |
| 362 | + ), |
| 363 | + ( |
| 364 | + "ndcube_2d_ln_lt_unit_unc_mask", |
| 365 | + NDData(np.ones((2, 3)) + 1, |
| 366 | + wcs=None, |
| 367 | + uncertainty=StdDevUncertainty((np.ones((2, 3)) + 1) * 0.1), |
| 368 | + mask=np.array([[True, False, False], [False, True, False]]), |
| 369 | + unit=u.ct), |
| 370 | + {"unit": u.ct**2, |
| 371 | + "data": np.array([[0, 2, 4], [6, 8, 10]]), |
| 372 | + "uncertainty": astropy.nddata.StdDevUncertainty(np.array([[0. , 0.2236068 , 0.4472136 ], |
| 373 | + [0.67082039, 0.89442719, 1.11803399]])), |
| 374 | + "mask": np.array([[True, True, True], [False, True, True]])} |
| 375 | + ) # both of them have uncertainty and mask and unit. |
373 | 376 | ], |
374 | 377 | indirect=("ndc",)) |
375 | | -def test_cube_arithmetic_multiply_ndcube_nddata(ndc, value, expected_kwargs, wcs_2d_lt_ln): |
| 378 | +def test_cube_arithmetic_multiply_nddata(ndc, value, expected_kwargs, wcs_2d_lt_ln): |
376 | 379 | output_cube = ndc * value # perform the multiplication |
377 | 380 |
|
378 | 381 | expected_kwargs["wcs"] = wcs_2d_lt_ln |
379 | 382 | expected_cube = NDCube(**expected_kwargs) |
380 | 383 |
|
381 | 384 | # Assert output cube is same as expected cube |
382 | | - assert_cubes_equal(output_cube, expected_cube) |
| 385 | + assert_cubes_equal(output_cube, expected_cube, check_uncertainty_values=True) |
| 386 | + |
| 387 | + |
| 388 | +@pytest.mark.parametrize(("ndc", "value", "expected_kwargs"), |
| 389 | + [( |
| 390 | + "ndcube_2d_ln_lt_no_unit_no_unc_no_mask_2", |
| 391 | + NDData(np.ones((2, 3)), wcs=None), |
| 392 | + {"data": np.array([[1, 2, 3], [4, 5, 6]])} |
| 393 | + ), |
| 394 | + ( |
| 395 | + "ndcube_2d_ln_lt_no_unit_no_unc_no_mask_2", |
| 396 | + NDData(np.ones((2, 3)), |
| 397 | + wcs=None, |
| 398 | + uncertainty=StdDevUncertainty(np.ones((2, 3))*0.1), |
| 399 | + mask=np.array([[True, False, False], [False, True, False]])), |
| 400 | + {"data": np.array([[1, 2, 3], [4, 5, 6]]), |
| 401 | + "uncertainty": astropy.nddata.StdDevUncertainty(np.ones((2, 3))*0.1), |
| 402 | + "mask": np.array([[True, False, False], [False, True, False]])} |
| 403 | + ), # ndc has no mask no uncertainty no unit, but nddata has all. |
| 404 | + ( |
| 405 | + "ndcube_2d_ln_lt_unit_unc_mask", |
| 406 | + NDData(np.ones((2, 3)), |
| 407 | + wcs=None, |
| 408 | + uncertainty=StdDevUncertainty(np.ones((2, 3))*0.1), |
| 409 | + mask=np.array([[True, False, False], [False, True, False]]), |
| 410 | + unit=u.ct), |
| 411 | + {"unit": u.ct, |
| 412 | + "data": np.array([[1, 2, 3], [4, 5, 6]]), |
| 413 | + "uncertainty": astropy.nddata.StdDevUncertainty(np.array([[0.1 , 0.1118034 , 0.14142136], |
| 414 | + [0.18027756, 0.2236068 , 0.26925824]])), |
| 415 | + "mask": np.array([[True, True, True], [False, True, True]])} |
| 416 | + ) # both of them have uncertainty and mask and unit. |
| 417 | + ], |
| 418 | + indirect=("ndc",)) |
| 419 | +def test_cube_arithmetic_add_nddata(ndc, value, expected_kwargs, wcs_2d_lt_ln): |
| 420 | + output_cube = ndc + value # perform the multiplication |
| 421 | + |
| 422 | + expected_kwargs["wcs"] = wcs_2d_lt_ln |
| 423 | + expected_cube = NDCube(**expected_kwargs) |
| 424 | + |
| 425 | + # Assert output cube is same as expected cube |
| 426 | + assert_cubes_equal(output_cube, expected_cube, check_uncertainty_values=True) |
383 | 427 |
|
384 | 428 |
|
385 | 429 | @pytest.mark.parametrize('value', [ |
|
0 commit comments