-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add WCS 1D (including multi-D flux) writer in default_loaders #632
Conversation
Cannot really consistently reproduce the doc build failure (or the warning for that matter) locally:
It initially showed up with Python3.7 + Sphinx 2.4.4, but not with Python3.8 + Sphinx 2.2.1.; after updating the latter to Sphinx 2.4.4 as well, the warning once popped up as well, but never since (always removing the |
Worked out a way how to load 2D spectra on a common spectral axis (i.e. a range of spectra in the 1. dimension with the 2. dimension the spectral axis). |
Seems the way the reader handles additional dimensions could be extended ad infinitum; included cases up to |
I have rebased since #637 introduced a number of non-trivial merge conflicts. Main open questions remaining to be settled on my part are
|
return Spectrum1D(flux=data, wcs=wcs, meta=meta) | ||
|
||
|
||
@custom_writer("wcs1d-fits") | ||
def wcs1d_fits_writer(spectrum, file_name, update_header=False, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might want to rename this to something like image-fits
/image_fits_writer
(analogous to tabular) -- wcs1d
should be implicit it because it's on a Spectrum1D
writer, and I think we might want to express explicitly that it's writing to an images vs a table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically there are two characteristic properties – storing the flux spectrum as a 1D image, and encoding the spectral axis as wcs.WCS
. But I agree the first one is probably more informative to the user, and this might make the documentation on the different loader types clearer or easier to write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So once I have updated both identifiers it would be probably be a good moment to go ahead with the renaming. Are you more in favour of FITS IMAGE
, FITS BINTABLE
, [FITS] IRAF
; or rather IMAGE-FITS
etc. @nmearl?
(I think FITS...
would have the advantage that all three formats would be listed together, following ASCII
and ECSV
in the current loaders).
This looks great other than the comment on having the identifier functions accept hdulist objects. |
I had half forgotten this was still pending when updating the identifier functions in #708. I am adding the hdulist handling here as well, should be straightforward to merge if the new PR needs to be rebased – had to update both identifiers anyway since Travis is rebasing on master and otherwise |
Looks good, thanks @dhomeier! |
Thanks @nmearl – a bit of explanation on the |
Can you open an issue that points this out specifically, with the idea that it'll be tackled in a future PR (and link to this PR for context)? |
In #625 and related discussion on Slack the lack of a builtin
writer
forwcs1d-fits
(writing the flux data as an image array) came up again.This PR implements such an initial generic writer for saving a
Spectrum1D
to the (primary)IMAGE_HDU
in a FITS file.Writing as
wcs1d-fits
only works forSpectrum1D
objects that have a fully functional WCS (specifically having aspectrum.wcs.to_fits
method; it's up to the user to provide this.The writer also supports on-the-fly change of flux units or dtype (e.g. to save space by setting
dtype='f4'
) via kwargs; the same options have been added totabular-fits
, but may need some discussion (this implementation adds separate kwargs[fw]type
for the dtypes of flux and spectral_axis, and there are no tests yet).wcs1d-fits
actually happily accepts 2D flux arrays, and the resulting files can be opened e.g. inSAOImageDS9
, butSpectrum1D
cannot read them back in, as there is no unambiguous way to handle the WCS-constructed spectral axis. Deferring this to a separate PR or issue on handling multi-D spectra.Also following the discussion on Slack I have added auto-identification functionality one
write
totabular-fits
; from what I understood this is of limited use, as it can basically just check if the file naming scheme conforms to the rules. Forwcs1d
it would be helpful to check for a workingwcs
, but since the spectrum object is not passed to the identifier, I see no way to implement this.