Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spectrum1D round-trip test #22

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion glue_astronomy/translators/spectrum1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ def parse_attributes(attributes):

# Get mask if there is one defined, or if this is a subset
if subset_state is None:
mask = None
if 'mask' in data.component_ids():
mask = data['mask']
else:
mask = None
else:
mask = data.get_mask(subset_state=subset_state)
mask = ~mask
Expand Down
19 changes: 19 additions & 0 deletions glue_astronomy/translators/tests/test_spectrum1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)