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

Trouble reading and writing spectra with convenience functions read and write. #1069

Open
jkeohane opened this issue Jul 21, 2023 · 1 comment
Labels
Milestone

Comments

@jkeohane
Copy link

I am using specutils and I am having a problem doing a simple thing.
I made a spectrum, call it "spec" and I saved it to a fits file using:

spec.write(fname+'.fits', format='tabular-fits', overwrite=True)

Then I read the exact same file using:
spec_test = Spectrum1D.read(fname+'.fits', format='tabular-fits')

However, this does not work. Any ideas?

I get the following errors, see below:

spec.write(fname+'.fits', format='tabular-fits', overwrite=True)

spec_test = Spectrum1D.read(fname+'.fits', format='tabular-fits')
Traceback (most recent call last):

Cell In[941], line 1
spec_test = Spectrum1D.read(fname+'.fits', format='tabular-fits')

File ~/anaconda3/lib/python3.10/site-packages/astropy/nddata/mixins/ndio.py:59 in call
return self.registry.read(self._cls, *args, **kwargs)

File ~/anaconda3/lib/python3.10/site-packages/astropy/io/registry/core.py:218 in read
data = reader(*args, **kwargs)

File ~/anaconda3/lib/python3.10/site-packages/specutils/io/default_loaders/tabular_fits.py:87 in tabular_fits_loader
return generic_spectrum_from_table(tab, wcs=wcs, **kwargs)

File ~/anaconda3/lib/python3.10/site-packages/specutils/io/parsing_utils.py:258 in generic_spectrum_from_table
raise IOError("Could not identify column containing the flux")

OSError: Could not identify column containing the flux

@rosteen rosteen added this to the v1.x milestone Aug 28, 2023
@rosteen
Copy link
Contributor

rosteen commented Sep 29, 2023

Thanks for reaching out, sorry for the delayed reply. I just tested this with a dummy spectrum (see below) and can't reproduce your error - can you provide some more detail (or the code) on how you created spec? And can you confirm that you're working with an up-to-date version of specutils?

The code I tested with is:

import astropy.units as u
from specutils import Spectrum1D

f = [10,15,20,18] * u.Jy
sa = [3000,3010,3020,3030] * u.AA
spec = Spectrum1D(f, spectral_axis=sa)
spec.write('test_tabular.fits', format='tabular-fits', overwrite=True)
spec_test = Spectrum1D.read('test_tabular.fits', format='tabular-fits')
spec_test

   <Spectrum1D(flux=<Quantity [10., 15., 20., 18.] Jy>, spectral_axis=<SpectralAxis [3000., 3010., 3020., 3030.] Angstrom>)>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants