Open kgozman6159 opened 6 days ago
Thanks for the report, I probably won't have time to dig into this for a week or two, but it's on my radar. I'll see if anyone else has some time to look into it (@dhomeier, I think you wrote the relevant loader?)
Hmm, that turned out a bit trickier – I was initially thinking this could rather be related to #1127, but that's dealing with WCSDIM=3
cases and a WCS type that is indeed not fully implemented yet, since the functionality does not exist in WCSLIB
(but looking at the present case, trying to resort to astropy.wcs
may in fact have been the cardinal error there).
The difference actually arises simply from the non-integer values in the pmin
, pmax
from
WAT2_002= ' 0. 65.06 71.06 1. 0. 2 5 5.84652757644654 1904.20617675782
(last 2 numbers following the ftype=2
and order=5
for Legendre series to 4th degree).
These are truncated to int
in _read_non_linear_iraf_wcs
, adopted from the earlier single-spec implementation from #192 and its predecessor in #18.
For that first version non-integer values would indeed not have been that straightforward to implement, and may seem disingenuous as they supposedly represent pixel values (also all example and test spectra have integer-valued limits here). However Legendre1D
accepts non-integer inputs to domain
, and with the float values exactly reproduces the wavelengths from readmultispec
(which is using the same mathematical model).
So the fix is quite straightforward and trivial, just may need some discussion if this is the correct treatment. But if IRAF itself gives those same numbers, there should not be much doubt. https://iraf.readthedocs.io/en/latest/tasks/noao/onedspec/specwcs.html is also using all integer-valued examples, but does not otherwise specify allowed inputs.
Thanks for reporting this!
disingenuous as they supposedly represent pixel values (also all example and test spectra have integer-valued limits here).
@rosteen as it happens the 2 non-linear_fits_solution test spectra actually do have fractional domain limits, so if we adopt the above reading from IRAF, comparing them to the integer-domain functions, as test_iraf_non_linear_chebyshev
and test_iraf_non_linear_legendre
do, is incorrect. Should just those tests be modified, or a second set of files or modified headers be tested with integer pmin, pmax in WAT2_002
?
Hi! I'm having a problem getting specutils to read in a multispec (non-linear) spectrum generated from IRAF. This is a FITS file that has 128 spectra, all with different non-linear wavelength solutions and MULTISPEC wcs. Specifically, it doesn't seem to return the correct wavelength arrays for each spectrum.
The relevant part of the FITS header for this file is this:
Note that this goes on for many more lines in the form of WAT2_XXX, I just haven't copied them here for readability.
I'm taking the file with the above header and running it through the following code snippet:
This returns
[6830.97577634 6831.95528375 6832.93481091 ... 8842.30021791 8843.27149672 8844.24274753]
This result is different from both trying to read in this spectrum using another code and also cross-checking with IRAF itself. The actual wavelength grid for this spectrum should be
[6830.14501048 6831.12483153 6832.10467235 ... 8842.14641611 8843.11802698 8844.08960983]
which also matches what I would expect from the header of the FITS file.
I'm running this in a Jupyter notebook on a 2020 Macbook Pro running Sonoma 14.7.1 (23H222). I'm using python 3.11.7, specutils 1.19.0, and astropy 6.0.0.
I believe this is related to #708, I'm not sure if the feature of reading multispec non-linear 2D WCS has been fully implemented or not or why I'm getting the wrong wavelength array (as compared to IRAF itself).
Any suggestions or thoughts would be appreciated!