From 6a55e1b169b09e5ab69e494f4943a4d80d6ef104 Mon Sep 17 00:00:00 2001 From: Erik Tollerud Date: Thu, 13 Aug 2020 10:48:02 -0400 Subject: [PATCH] added roundtrip test for Spectrum1D w/ masks --- .../translators/tests/test_spectrum1d.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/glue_astronomy/translators/tests/test_spectrum1d.py b/glue_astronomy/translators/tests/test_spectrum1d.py index d6eafd5..c751c4e 100644 --- a/glue_astronomy/translators/tests/test_spectrum1d.py +++ b/glue_astronomy/translators/tests/test_spectrum1d.py @@ -305,3 +305,22 @@ def test_spectrum1d_2d_data(spec_ndim): # The metadata should still be present assert spec_new.meta['instrument'] == 'spamcam' + + +@pytest.mark.parametrize('maskdtype', (bool, int)) +def test_spectrum1d_mask_roundtrip(maskdtype): + maskvals = np.array([1, 0, 2, 0], dtype=maskdtype) + # for a bool dtype this becomes [True, False, True, False] + + spec = Spectrum1D(spectral_axis=[1, 2, 3, 4]*u.micron, + flux=[11, 12.5, 13, 14]*u.Jy, + mask=maskvals) + + data_collection = DataCollection() + data_collection['spectrum'] = spec + + rtspec = data_collection['spectrum'].get_object(spec.__class__) + + assert np.all(rtspec.mask == maskvals) + assert u.allclose(rtspec.spectral_axis, spec.spectral_axis) + assert u.allclose(rtspec.flux, spec.flux)