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

Fix corruption of FITS tables with unsigned int columns on save and load #3680

Conversation

eslavich
Copy link
Collaborator

Addresses #3655

The problem on save turned out to be less of an astropy bug and more of a missing feature -- the public API doesn't currently allow us to put a FITS_rec into "pseudo unsigned integer" mode. We were already messing with astropy implementation details by setting _colrefs directly, so I don't think it's a big deal to also set _uint.

The problem on load is, I think, an astropy bug. I filed an issue and added a workaround here, which is to overwrite the incorrect FITS_rec dtype.

Copy link
Contributor

@philhodge philhodge left a comment

Choose a reason for hiding this comment

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

Aside from the assignment to self.dq, this looks fine.

@@ -58,11 +58,6 @@ def __init__(self, ms, spec, exptime_key):
self.surf_bright = np.zeros_like(self.flux)
self.sb_error = np.zeros_like(self.flux)
log.warning("There is no SURF_BRIGHT column in the input.")
# xxx temporary self.dq = spec.spec_table.field("dq").copy()
Copy link
Contributor

Choose a reason for hiding this comment

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

Only the "# xxx temporary " part of this line should be deleted. The actual assignment to self.dq needs to be done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh! Oops, thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(this has been fixed)

fits_rec = fits.FITS_rec(val)
fits_rec._coldefs = coldefs
# FITS_rec needs to know if it should be operating in pseudo-unsigned-ints mode,
# otherwise it won't properly convert integer columns with TZEROn before saving.
fits_rec._uint = uint
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used in astropy.io.fits?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, here. The else... is where it was changing the dtype to float64.

Copy link
Collaborator

@hbushouse hbushouse left a comment

Choose a reason for hiding this comment

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

LGTM

@hbushouse
Copy link
Collaborator

Shall we go ahead and merge this?

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

Successfully merging this pull request may close these issues.

3 participants