-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Revamp Spectrum1D tabular-fits writer #905
Comments
As a result of digging into this, I discovered that header data does not currently roundtrip using
If folks agree, I would be happy to implement this given some guidance. |
@dhomeier might also be interested in this issue since he is working on: |
Summarizing relevant discussions from Slack:
|
First I am not sure this issue really is a duplicate or, or completes #908 – the latter is primarily on better documentation of the existing options for writing spectra, while this one at least with the recent discussion is heading more into proposing new functionality. I think the current "generic" read/write loaders (in fact the only ones implementing write functionality) have already been constructed with some round-tripping support in mind, though incomplete yet. One important point here is that
A good starting point could perhaps be to review what info is already preserved in round-trip tests like specutils/specutils/tests/test_loaders.py Lines 608 to 611 in ca3153f
and what is missing that you would like to be saved. As sketched in your proposed implementation, getting header data back from |
We've tested the
results in a header which just has the minimal keywords and not any of the things we added. (I assume this is because of the no-loneger-necessary END keyword)
|
That's what you get with specutils/specutils/io/default_loaders/tabular_fits.py Lines 117 to 127 in ca3153f
for anything you put into a |
I think the bottom line is that We could continue to go down this road or maybe I should just write a custom reader/writer that is based on |
Just to show y'all what I'm talking about, here's the degradation of the header information using the current tooling. The header data I have compiled and added using
The header obtained via
The header obtained using
And the header directly from the FITS file
|
Ah, I did not expect that would not qualify as subtype of
That's exactly as expected, as
OK that's a more serious problem; I think proper treatment of comments has also been discussed a couple of times, but not sure if a good solution has come out of it.
Or, put it the other way, it has much wider functionality, so cannot be expected to conform to all FITS header conventions. Thinking that over again, I am more and more leaning towards sticking to
That is just returning the PrimaryHDU header by default, so |
Progress!
This is definitely better, but I still think the meta['header'] should be maintained in hdu0 rather than the 1st extension. Is this an issue for |
Sorry, got that confused with your piece of code. No, 'tabular-fits' does not name the extension yet (only just adding that to 'wcs1d', but there it's somewhat more important to identify the different HDUs for flux, mask etc.). Still should perhaps think of a good default name. |
See Slack comment; I think |
Don't want to interrupt the above rather promising thread, but I just wanted to make sure I understand the desires here: @kelle, your goal is to make sure the "really actually 1d" spectral use case round-trips, right? I think if we can get that to work with the updates @dhomeier is doing to Alternatively/additionally, is the underlying issue here really that it's not clear from the docs how we want someone to do this? |
Yeah, I only care about the wavelength, flux, and uncertainty of one spectrum. The docs are most certainly not clear regarding the vision for meta['header'] I'm also pretty set that I want the header in hdu0. Could also be in meta but I want a more traditional/familiar looking FITS file and header. The only route I see to do this is to make a new writer/reader. |
I think the docs have never gone into that level of detail as to what is the recommended structure for metadata, although all the examples of loaders are following the https://specutils.readthedocs.io/en/stable/custom_loading.html#creating-a-custom-loader
If it needs to output to a |
@cshanahan1 and I are working on this at a hack day! |
I'm working on writing some tests to demonstrated current and desired behavior. |
Documenting some thoughts as followup from the spectro workshop hackfest last week — IIUC @kelle identified that the problem with tabular-fits dropping the metadata when writing + reading was that the writer was putting the metadata in HDU 1 along with the bintable, while the reader was loading the metadata from HDU 0. There was discussion about whether this should be fixed on the writer or the reader side. For the purpose of the existing "tabular-fits" format, I would like to advocate for keeping the metadata in HDU 1 along with the table, and fixing this on the reader side. 3 reasons in descending order of priority:
spec = Table.read('file-written-with-tabular-fits-format.fits')
spec.meta # works!
plt.plot(spec['wavelength'], spec['flux']) if the metadata was in HDU 0 you could still access it with additional steps, but it is handy to bundle it in the way that astropy To be clear:
|
I'm actively working on this right now. :) A compromise solution is to put the metadata in both headers. That's actually easy enough. |
That is not something under the control of the reader though, i.e. if the loader encounters an HDUList with non-minimal, but different headers in several HDUs, should it give preference to one, try to merge everything into one |
This is actually opposite of the way the current |
I'm having a lot of trouble figuring out how to write a Spectrum1D object to a file. A few of my questions:
I'm happy to work on this once I understand it. :)
The text was updated successfully, but these errors were encountered: