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

add more spectral-cube class translators #54

Merged
merged 7 commits into from
Sep 24, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

- Fixed unit parsing for ``Specutils1DHandler.to_data`` so it no longer
drops the flux unit in some cases. [#78]
- Added support for a wider range of spectral-cube objects [#54]

0.5.0 (2022-08-18)
------------------
Expand Down
31 changes: 27 additions & 4 deletions glue_astronomy/translators/spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
from astropy import units as u
from astropy.wcs import WCSSUB_STOKES, WCS

from spectral_cube import SpectralCube, BooleanArrayMask
from spectral_cube import BooleanArrayMask
from spectral_cube.spectral_cube import (BaseSpectralCube, SpectralCube,
VaryingResolutionSpectralCube)
from spectral_cube.dask_spectral_cube import DaskSpectralCube, DaskVaryingResolutionSpectralCube


@data_translator(SpectralCube)
@data_translator(BaseSpectralCube)
class SpectralCubeHandler:

def to_data(self, obj):
Expand All @@ -19,7 +22,7 @@ def to_data(self, obj):
data.meta.update(obj.meta)
return data

def to_object(self, data_or_subset, attribute=None):
def to_object(self, data_or_subset, attribute=None, cls=SpectralCube):
"""
Convert a glue Data object to a SpectralCube object.

Expand Down Expand Up @@ -82,4 +85,24 @@ def to_object(self, data_or_subset, attribute=None):
values = values[slc[::-1]]
wcs = wcs.sub(subkeep)

return SpectralCube(values, mask=mask, wcs=wcs, meta=data.meta)
return cls(values, mask=mask, wcs=wcs, meta=data.meta)


data_translator(SpectralCube)(SpectralCubeHandler)
data_translator(DaskSpectralCube)(SpectralCubeHandler)


@data_translator(VaryingResolutionSpectralCube)
class VaryingResolutionSpectralCubeHandler(SpectralCubeHandler):

def to_data(self, obj):
data = super().to_data(obj)
data.meta['beams'] = obj.beams
return data

def to_object(self, data_or_subset, attribute=None, cls=VaryingResolutionSpectralCube):
return super().to_object(data_or_subset, attribute=attribute, cls=cls,
beams=data_or_subset.meta['beams'])
dhomeier marked this conversation as resolved.
Show resolved Hide resolved


data_translator(DaskVaryingResolutionSpectralCube)(VaryingResolutionSpectralCubeHandler)