-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Writer needed for cube data #592
Comments
So the user has to create their own writer or are we planning on providing them with some general writers? |
We have a general cube loader, but not a general cube writer. We'll definitely end up providing one, but if a user requires some specific thing to be stored with their output, they'd probably have to create their own. |
#632 has a writer that supports 2D spectra now, maybe that could help as a template for a cube version – actually I checked that you can throw a 3D spectrum at it as well, that is read in as a cube by |
Addendum: I've tried to read in the test file created above, which has
with the
so this might not be the desired type of cube, or the comment about |
I was just looking for this. This is blocking Jdaviz development because when we generate a new spectral cube, we can no longer write it out properly after switching from Problem: import numpy as np
from astropy import units as u
from astropy.io import fits
from astropy.wcs import WCS
from specutils import Spectrum1D
flux = np.arange(720).reshape((8, 9, 10)).astype(np.float32) * u.nJy
w = WCS({'WCSAXES': 3, 'CRPIX1': 38.0, 'CRPIX2': 38.0, 'CRPIX3': 1.0,
'CRVAL1': 205.4384, 'CRVAL2': 27.004754, 'CRVAL3': 4.890499866509344,
'CTYPE1': 'RA---TAN', 'CTYPE2': 'DEC--TAN', 'CTYPE3': 'WAVE',
'CUNIT1': 'deg', 'CUNIT2': 'deg', 'CUNIT3': 'um',
'CDELT1': 3.61111097865634E-05, 'CDELT2': 3.61111097865634E-05, 'CDELT3': 0.001000000047497451, # noqa
'PC1_1 ': -1.0, 'PC1_2 ': 0.0, 'PC1_3 ': 0,
'PC2_1 ': 0.0, 'PC2_2 ': 1.0, 'PC2_3 ': 0,
'PC3_1 ': 0, 'PC3_2 ': 0, 'PC3_3 ': 1,
'DISPAXIS': 2, 'VELOSYS': -2538.02,
'SPECSYS': 'BARYCENT', 'RADESYS': 'ICRS', 'EQUINOX': 2000.0,
'LONPOLE': 180.0, 'LATPOLE': 27.004754,
'MJDREFI': 0.0, 'MJDREFF': 0.0, 'DATE-OBS': '2014-03-30'})
sp = Spectrum1D(flux=flux, wcs=w)
sp.write("blah3.fits") # This write out the wrong format
What I really want is to write it out like this but using hdu = fits.ImageHDU(flux.value)
hdu.name = "SCI"
hdu.header['BUNIT'] = flux.unit.to_string(format='fits')
hdu.header.update(w.to_header())
hdulist = fits.HDUList([fits.PrimaryHDU(), hdu])
hdulist.writeto("blah4.fits")
Motivation: We want this functionality to be able to roundtrip cube I/O in Jdaviz (Cubeviz). Workaround: We can stop using |
The WCS in that example is 1D? What happens if you write it out with |
No, it is a 3D WCS. It is a legit spectral cube. |
Adding |
That example above is a fully reproducible example. I gotta run now but feel free to play with it. |
I mean 1D-spectral. Didn't think it could become a legit |
I'm listening in here, but unfortunately I don't have the answer; we're not close to having a solution that merges spectral-cube and specutils again. If this is now a priority for STSCI, I'd be interested in talking through how to do that, though. Spectral-cube's writer is extremely simple, but it is also built on spectral-cubes being closely linked to FITS-WCS. HDU builder: so I imagine most of the effort would be in mangling |
Yes, 1D has spectral, while the other 2D is spatial (e.g., RA and Dec). |
I can get the writer to pass the spectral_axis check by comparing to
fails on read with
|
Maybe this is good enough for now until we have demands for cubes with GWCS. Writer that works for most cases but not all is better than no writer at all? |
Writer that writes out illegal WCS is not much use either. Although directly reading the header returns a valid WCS, so it's probably something in the loader that needs to be fixed. |
That's certainly my take! I have also encountered no demand for support for non-FITS-compatible cubes; generally the process of building a cube, at any wavelength, requires putting the data onto a regular grid, and thus FITS can handle it. I'm sure one can come up with use cases that require GWCS, but I haven't seen them in the wild. Solar people probably have counterexamples though. That said, I'm not clear what's wrong with the output @dhomeier showed. Maybe it's that rogue |
Re: Illegal WCS -- I am not sure either. I thought the example code I gave to write it back out was fine, as Cubeviz was able to roundtrip with that one. |
Yes, it was the the loader that "fixed" the WCS when, I think, only 1D (pure spectral) WCS could be passed to |
I have a downstream workaround at spacetelescope/jdaviz#2012 until this issue is resolved. Please have a look to see if I missed anything. Thanks! |
How do we save spectral cubes to file formats that are readable by other applications?
What type of api call do we implement for this?
🐱
The text was updated successfully, but these errors were encountered: