Skip to content
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

Extend spectrum information written by tabular_fits_writer #539

Merged
merged 4 commits into from
Nov 11, 2019

Conversation

dhomeier
Copy link
Contributor

This is an attempt to address some of the issues reported in #531, notably adding the missing unit information to the written spectrum. It also adds the uncertainty column, if present, and indicates the type of spectral_axis in TTYPE1. The last commit adds writing of any other header metadata, taking the 2nd option discussed in
#531 (comment) (with a new kwarg update_header). It also passes other kwargs though to the table writer, allowing e.g. to force overwriting of existing files.
Added tests for all these functions in test_loaders.py

Files thus written still fail to be read in as tabular-fits on the WCSWrapper error, but since they are fully compliant (except for a missing checksum) FITS files with complete spectral information, this really seems to be more of a problem on the reader side.

Copy link
Contributor

@nmearl nmearl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, @dhomeier. Some minor suggestions, but not necessary.

header.update([k for k in spectrum.meta.items() if
isinstance(k[1], hdr_types)])

# Strip header of FITS reserved keywords (strangely, loop does not work!)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could do:

for keyword in ['NAXIS', 'NAXIS1', 'NAXIS2']:
    header.remove(keyword, ignore_missing=True)


columns = [disp, flux]
colnames = [dispname, "flux"]
# Include uncertainty - ToDo: uncertainty units?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's alright to not deal with uncertainty units because they should be assumed the same as the flux units.

colnames = [dispname, "flux"]
# Include uncertainty - ToDo: uncertainty units?
if spectrum.uncertainty is not None:
columns.append(spectrum.uncertainty.array * spectrum.uncertainty.unit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
columns.append(spectrum.uncertainty.array * spectrum.uncertainty.unit)
columns.append(spectrum.uncertainty.quantity)

@nmearl nmearl added this to the v0.7 milestone Nov 7, 2019
@dhomeier
Copy link
Contributor Author

dhomeier commented Nov 7, 2019

Thanks for the suggestions, I think they make for notably more concise code!
CHANGES.rst seems to be one release behind; no v0.7 section yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants