radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
95 stars 61 forks source link

converting microns to wave number #881

Open alexmaragko opened 1 year ago

alexmaragko commented 1 year ago

I have a spectral cube object where the spectral_axis is in microns (u.um) and I would like to update it, or alternatively create a new cube, in wave numbers (1/u.cm).

new_cube = cube.with_spectral_unit(1/u.cm) does not work because it requires an equivalencies=u.spectral(), but with_spectral_unit takes the velocity_convention argument with the ‘relativistic’, ‘radio’, or ‘optical’ options.

cube.spectral_axis.to(1/u.cm, equivalencies=u.spectral()) does the job but I am not sure how to create a new cube that has this as the spectral axis.

keflavich commented 1 year ago

Thevelocity_convention keyword should be optional. cube.with_spectral_unit should then just work. All conversions of velocity coordinates automatically use the .spectral equivalency.

If you get an error leaving velocity_convention unspecified - that's a legit bug that we should fix, but put in velocity_convention='radio' as a placeholder

alexmaragko commented 1 year ago

Giving new_cube = cube.with_spectral_unit(1/u.cm) returns *** KeyError: 'wavenumber', and the same error is given even if I include velocity_convention='radio'

keflavich commented 1 year ago

Ah, then this is a deeper issue; it may be that the FITS standard does not support wavenumber? I'll have to dig more deeply to be sure

alexmaragko commented 1 year ago

Thanks. Is there currently a way to create a new cube using cube.spectral_axis.to(1/u.cm, equivalencies=u.spectral()) which works as expected?

keflavich commented 1 year ago

No, the framework underlying all of what spectral-cube does is the FITS-WCS library. If FITS doesn't support a unit, we can't serialize the data or compute transformations b/w systems

keflavich commented 1 year ago

Ah, but FITS does support wavenumber; this might be a simple fix