-
Notifications
You must be signed in to change notification settings - Fork 25
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
specio.read_spec assumes wavelength and flux are always in column 1 and column 2 #372
Comments
The default values (including the units) are set for historical reason. It could be overwritten, see https://synphot.readthedocs.io/en/latest/synphot/overview.html#fits-table-format The extension header must contain the following keywords (unless you overwrite them with non-default values in And you can pass in all these keywords via If this suggestion works for you, please close the issue. Thanks. |
I see that what I've got here is an explicitly nonstandard fits file. I'll see if I can put some special case logic in the code; this is for a generic file reader function and the rest of the files are more well-behaved. |
Actually, I spoke too soon. read_fits_spec() uses the manually-provided units only if there are no units in the headers, but there are units in these headers. I'm still not certain this deserves to be fixed, versus correcting the input files themselves, given that they're nonstandard. |
Ah, right... Wavelength and flux units, which default to Angstrom and FLAM, respectively. These are only used if The supported format is indeed very strict and there is no law in the land that states the units must be I will re-open this as a feature request, though I probably won't fix it unless you come back and decide that your format must be supported (instead of fixing the format itself on your side). |
A workaround with the released version is possible by not using |
I've implemented what you suggested, and reading in the data and creating a SpectralElement does work as a special case. That's sufficient for now, though I will raise the issue of the nonstandard file format with our instrument partners. |
I ran into a similar when trying to read the output of the ESO Sky Model which are FITS binary tables with wavelength, radiance flux and transmission of the atmosphere. The (cutdown, I removed the identical
Reading the transmission from the
results in |
Thanks for the extra data point. It is not good that this assumption breaks so easily now. Maybe I will try to prioritize refactoring the FITS table I/O in the near future (cc @larrybradley). If you have a hard deadline, please let me know. In the meantime, please use the workaround provided. Thanks for your patience! |
Description
If the wavelength column in a spectrum is not column 1 and the flux/throughput column is not column 2, the units are read incorrectly.
Expected behavior
Loading a file should grab the wavelength unit of the wavelength column, and the flux unit of the flux column.
Actual behavior
The ETC has a file describing the spectral traces for NIRISS SOSS, wherein the columns are x (pixels), wavelength (microns), and trace (pixels). When reading it in, the code crashed because specio.read_spec produced a file where the wavelength was supposedly in pixels, and the trace was supposedly in microns.
Steps to Reproduce
UnitConversionError: 'Unit("PIXELS")' is not a scaled version of 'Unit("Angstrom")'
. Note that the wavelength unit shouldn't be pixels; it should be microns.I have tracked the issue down to specio.read_fits_spec line 185 where in we read the data by field name, and the units from the header always as TUNIT1 and TUNIT2.
In this particular case, the wavelength column was 2, and the "flux" column was 3, so TUNIT2 and TUNIT3 should have been read.
I have experimentally written some code to fix that, which I can PR.
System Details
macOS-10.16-x86_64-i386-64bit
Python 3.11.4 (main, Jul 5 2023, 09:00:44) [Clang 14.0.6 ]
Numpy 1.26.3
astropy 6.0.0
Scipy 1.11.4
Matplotlib 3.7.2
Synphot 1.2.1
The text was updated successfully, but these errors were encountered: