Skip to content

Commit

Permalink
Add warning for non-homogenous case
Browse files Browse the repository at this point in the history
  • Loading branch information
rosteen committed Feb 22, 2024
1 parent da86d5e commit a60829b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions glue_astronomy/translators/spectrum1d.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import warnings

from glue.config import data_translator
from glue.core import Data, Subset
Expand Down Expand Up @@ -157,9 +158,7 @@ def _has_homogenous_spectral_solution(self, data):

def to_data(self, obj):

# Glue expects spectral axis first for cubes (opposite of specutils).
# Swap the spectral axis to first here. to_object doesn't need this because
# Spectrum1D does it automatically on initialization.
# specutils 2.0 doesn't care where the spectral axis anymore, but we still need PaddedSpectrumWCS for now
if obj.flux.ndim > 1 and obj.wcs.world_n_dim == 1:
data = Data(coords=PaddedSpectrumWCS(obj.wcs, obj.flux.ndim, obj.spectral_axis_index))
else:
Expand Down Expand Up @@ -238,10 +237,13 @@ def to_object(self, data_or_subset, attribute=None, statistic='mean'):
kwargs = {'spectral_axis': spectral_axis}

else:
# In this case we'll need to resample the flux onto a common spectral axis before collapsing
# In this case we should resample the flux onto a common spectral axis before collapsing
warnings.warn("Spectral solution is not the same at all spatial points,"
" collapsing may give inaccurate results.")
kwargs = {'wcs': data.coords}
else:
raise ValueError('Can only use statistic= if the Data object has a FITS WCS')
# Shouldn't get here anymore, but just in case.
raise ValueError('Can only use statistic= if the Data object has a GWCS or FITS WCS')

elif isinstance(data.coords, SpectralCoordinates):

Expand Down

0 comments on commit a60829b

Please sign in to comment.