Skip to content

Commit 504f230

Browse files
committed
More tests
1 parent cc8d915 commit 504f230

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

ndcube/asdf/converters/ndcube_converter.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,10 @@ def to_yaml_tree(self, ndcube, tag, ctx):
4141
This ensures that users are aware of potentially important information
4242
that is not included in the serialized output.
4343
"""
44-
from astropy.wcs.wcsapi import BaseHighLevelWCS
45-
4644
node = {}
4745
node["data"] = ndcube.data
48-
if isinstance(ndcube.wcs, BaseHighLevelWCS):
49-
node["wcs"] = ndcube.wcs.low_level_wcs
50-
else:
51-
node["wcs"] = ndcube.wcs
46+
# NDData always has .wcs as a high level wcs
47+
node["wcs"] = ndcube.wcs.low_level_wcs
5248
if not ndcube.extra_coords.is_empty:
5349
node["extra_coords"] = ndcube.extra_coords
5450
if ndcube.global_coords._all_coords:

ndcube/asdf/converters/tests/test_ndcollection_converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def test_serialization_cube(create_ndcollection_cube, tmp_path):
3535
assert_collections_equal(af["ndcube_gwcs"], ndcollection)
3636

3737

38-
@pytest.fixture
39-
def create_ndcollection_sequence(ndcube_gwcs_3d_ln_lt_l, ndcube_gwcs_3d_ln_lt_l_ec_dropped_dim):
38+
@pytest.fixture(params=[{"meta": {"hello": "world"}}, {}])
39+
def create_ndcollection_sequence(ndcube_gwcs_3d_ln_lt_l, ndcube_gwcs_3d_ln_lt_l_ec_dropped_dim, request):
4040
sequence02 = NDCubeSequence([ndcube_gwcs_3d_ln_lt_l, ndcube_gwcs_3d_ln_lt_l_ec_dropped_dim])
4141
sequence20 = NDCubeSequence([ndcube_gwcs_3d_ln_lt_l_ec_dropped_dim, ndcube_gwcs_3d_ln_lt_l])
42-
return NDCollection([("seq0", sequence02), ("seq1", sequence20)], aligned_axes="all")
42+
return NDCollection([("seq0", sequence02), ("seq1", sequence20)], aligned_axes="all", **request.param)
4343

4444

4545
def test_serialization_sequence(create_ndcollection_sequence, tmp_path):

ndcube/asdf/converters/tests/test_ndcube_converter.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from contextlib import nullcontext
2+
13
import asdf_astropy
24
import numpy as np
35
import pytest
@@ -17,10 +19,16 @@ def test_serialization(all_ndcubes, tmp_path, all_ndcubes_names):
1719
if not isinstance(all_ndcubes.data, np.ndarray):
1820
pytest.skip("Can't save non-numpy array to ASDF.")
1921

22+
# A warning is thrown if psf is present
23+
write_context = nullcontext()
24+
if all_ndcubes.psf is not None:
25+
write_context = pytest.warns(UserWarning, match="'psf' is present")
26+
2027
file_path = tmp_path / "test.asdf"
2128
with asdf.AsdfFile() as af:
2229
af["ndcube"] = all_ndcubes
23-
af.write_to(file_path)
30+
with write_context:
31+
af.write_to(file_path)
2432

2533
with asdf.open(file_path) as af:
2634
assert_cubes_equal(af["ndcube"], all_ndcubes, rtol=1e-12)

ndcube/asdf/converters/tests/test_ndcubesequence_converter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import pytest
2+
13
import asdf
24

35
from ndcube.ndcube_sequence import NDCubeSequence
46
from ndcube.tests.helpers import assert_cubesequences_equal
57

68

7-
def test_serialization(ndcube_gwcs_3d_ln_lt_l, ndcube_gwcs_3d_ln_lt_l_ec_q_t_gc, tmp_path):
9+
@pytest.mark.parametrize("meta", [None, {"hello": "world"}])
10+
def test_serialization(meta, ndcube_gwcs_3d_ln_lt_l, ndcube_gwcs_3d_ln_lt_l_ec_q_t_gc, tmp_path):
811
file_path = tmp_path / "test.asdf"
9-
ndcseq = NDCubeSequence([ndcube_gwcs_3d_ln_lt_l, ndcube_gwcs_3d_ln_lt_l_ec_q_t_gc], common_axis=1)
12+
ndcseq = NDCubeSequence([ndcube_gwcs_3d_ln_lt_l, ndcube_gwcs_3d_ln_lt_l_ec_q_t_gc], common_axis=1, meta=meta)
1013
with asdf.AsdfFile() as af:
1114
af["ndcube_gwcs"] = ndcseq
1215
af.write_to(file_path)

ndcube/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,13 @@ def ndcube_2d_ln_lt(wcs_2d_lt_ln):
851851
return NDCube(data_cube, wcs=wcs_2d_lt_ln)
852852

853853

854+
@pytest.fixture
855+
def ndcube_2d_ln_lt_psf(wcs_2d_lt_ln):
856+
shape = (10, 12)
857+
data_cube = data_nd(shape)
858+
return NDCube(data_cube, wcs=wcs_2d_lt_ln, psf=np.zeros(shape))
859+
860+
854861
@pytest.fixture
855862
def ndcube_2d_ln_lt_uncert(wcs_2d_lt_ln):
856863
shape = (10, 12)
@@ -1086,6 +1093,7 @@ def ndcube_1d_l(wcs_1d_l):
10861093
"ndcube_3d_coupled_time",
10871094
"ndcube_3d_l_ln_lt_ectime",
10881095
"ndcube_2d_ln_lt",
1096+
"ndcube_2d_ln_lt_psf",
10891097
"ndcube_2d_ln_lt_uncert",
10901098
"ndcube_2d_ln_lt_mask_uncert",
10911099
"ndcube_2d_ln_lt_mask_uncert_unit_mask_false",

0 commit comments

Comments
 (0)