-
Notifications
You must be signed in to change notification settings - Fork 65
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
BUNIT value from FITS file header not passed to SpectralCube header #902
Comments
The problem here is that you're stripping the units: hdul = fits.open(fits_dir+fits_file+'.fits')
hdr = hdul[0].header
hdr['CD3_3'] = hdr['CDELT3'] # to repair value misread from the FITS header. It seems it was looking for 'CD3_3', as it was already using 'CD1_1', and 'CD2_2' instead of CDELT1, CDELT2 which contain wrong values.
w = WCS(hdr)
data = hdul[0].data
cube = SpectralCube(data=hdul[0].data,wcs=w) When you do data = hdul[0].data * u.erg/u.s/u.cm**2/u.AA
cube = SpectralCube(data=data, header=hdr, wcs=w) or even simpler: cube = SpectralCube.read(hdul[0]) Note for @e-koch and myself: We don't demo this case on the reading docs; we should. https://spectral-cube.readthedocs.io/en/latest/creating_reading.html |
Also, on the last part: And, yes, I think you did the right thing with |
Hi, thanks for the quick answer. I can not remove "wcs=w" from the SpectralCube(data=hdul[0].data, wcs=w) instruction, as I get the following error:
I also tried:
but it did not help. Units are still absent.
|
You're right, you can't use Use |
Great!. Now I got a related warning:
so this solved the problem:
BUT, since I can not create hdr['CD3_3'] = hdr['CDELT3'] in this way, the spectral axis is messed up (it should go up to 9800 A and not 16000 A, this is because in the original FITS file: CDELT3 = 0.9999999999999999 instead of CDELT3 = 0.49999999999999994). How can I either include CD3_3, or modify CDELT3 in the SpectralCube header now?. I tried cube.header.set('CDELT3', 0.49999999999999994) but it did not modify the read-in CDELT3 value. Here is an example of correct units, but wrong spectral axis:
Here is an example of incorrect units, but correct spectral axis:
|
I would alter the header in the HDU before passing it into spectral-cube. The SpectralCube object isn't expecting to have state changes made after instantiating, so while you could hack in changes to the header, it may cause other unintended breaks. e.g.,
|
You need to have only CD or only CDELT, so you probably want: hdul = fits.open(fits_dir+fits_file+'.fits') # for the SpectralCube function
hdr = hdul[0].header
hdr['CD3_3'] = hdr['CDELT3']
del hdr['CDELT3']
cube = SpectralCube.read(hdul) I'll echo what @e-koch said: don't try to modify the cube after you've loaded it, it is designed not to be changed. |
This worked!. Thanks
|
When reading a FITS file with the following commands:
the hdr[‘BUNIT’] = 'ergs/s/cm^2/A' string is not copied over to the Specral Cube header (cube.unit is empty).
Here is the header of the original FITS file:
Here is the output of the cube.wcs command, lacking the "unit" variable.
On a side note, the CDELT1 and CDELT2 values in the original FITS header contains incorrect values, so the CD1_1 and CD2_2 values are used for the reconstruction of the spatial axis instead. In that sense, I had to create hdr['CD3_3'] = hdr['CDELT3'], as it seems Spectral Cube assumed that the variable CD3_3 would exist for the spectral reconstruction (?), while it was not in the original header.
The text was updated successfully, but these errors were encountered: