You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tripped across this from reading a fits file that had uint8 data and then not being able to write the data back out into a new file so simply avoiding uint8 is not an option.
the uint=True doesn't really do anything. It's an internal detail used only when reading files. Normally unsigned ints are supported in new tables transparently without having to do anything special.
Anyways, I see the problem here. Turns out the 8-bit integers are natively unsigned in FITS tables, and signed 8-bit integers have to be represented using TZERO. This is the opposed of all other integer types. Oof--after all this time FITS still finds new ways to horrify me.
Turns out this applies to images as well--BITPIX = 8 implies unsigned ints, not signed ints. I'm not exactly sure what PyFITS does in this case but I'll have to check.
This should be fixed (with tests) for both images and tables, and should include a clarification in the documentation that the sense of "pseudo-unsigned ints" is reversed for 1-byte ints (and that signed bytes should be considered "pseudo-signed ints").
Okay, I confirmed that for images unsigned bytes are handled properly, but signed bytes simply aren't supported at all (though it should be possible to support them with bzero).
Suprising indeed. I know why it is though. On this line it checks if the type is unsigned int by checking the dtype.kind attribute. However, for a multi-dimensional type this is 'V', not 'u' (or whatever the base kind happens to be). So that's a minor bug in its own right.
@embray and @sbailey key erroris raised when dictinary key is unable to find its value. here 1:because 10 is in categories of unint8
also if we pass int8 its forking fine because in that case it not entering in bug part of the code
also @embray is right it has nothing to do with hdu = fits.BinTableHDU(data, uint=True) &
hdu = fits.BinTableHDU(data)
@AMAN3003 This fix is not correct though, because as I pointed out unsigned bytes are stored natively in FITS, while it's signed bytes that need special handling, converse to all other byte types. This needs to be fixed for images as well as tables. Now that I think about it it's actually a pretty serious bug, but somehow it hasn't come up before.
Can someone confirm whether a FITS file containing signed bytes created by Astropy is read correctly by other software, say, CFITSIO or IRAF?
@sbailey Thanks for doing those tests, that's perfect!
As for uint64, I believe CFITSIO has lacked support for that for a while, so the problem is in CFITSIO I think (but someone please correct me if that's wrong--I'm not sure--I just remember that being the case some time ago).
But for signed/unsigned bytes I think astropy.io.fits is definitely broken. Aman's attempt at a fix had the right idea, but unfortunately it needs to do more to treat signed/unsigned bytes as a separate special case (and needs to work for images as well as tables).
All examples from the original post work, but I'm confused of what the desired test results should be for #4267 (comment) . I've edited the code, so it's copy-pasteable. @saimn or @MSeifert04 - could you have a quick look of this and possible close it?
The original issue with uint8 data in BinTableHDU seems to be solved.
The only issue that remains I think, is with int8 data. Related to the post above, fitsio can write a file with int8 data, with the file is bad (BITPIX=64, BZERO=9223372036854775808). But int8 is another issue, probably not easy to support and not too common, I think we can close this one.
Activity
embray commentedon Nov 16, 2015
FWIW in this
the
uint=Truedoesn't really do anything. It's an internal detail used only when reading files. Normally unsigned ints are supported in new tables transparently without having to do anything special.embray commentedon Nov 16, 2015
Anyways, I see the problem here. Turns out the 8-bit integers are natively unsigned in FITS tables, and signed 8-bit integers have to be represented using TZERO. This is the opposed of all other integer types. Oof--after all this time FITS still finds new ways to horrify me.
embray commentedon Nov 16, 2015
Turns out this applies to images as well--BITPIX = 8 implies unsigned ints, not signed ints. I'm not exactly sure what PyFITS does in this case but I'll have to check.
This should be fixed (with tests) for both images and tables, and should include a clarification in the documentation that the sense of "pseudo-unsigned ints" is reversed for 1-byte ints (and that signed bytes should be considered "pseudo-signed ints").
embray commentedon Nov 16, 2015
Okay, I confirmed that for images unsigned bytes are handled properly, but signed bytes simply aren't supported at all (though it should be possible to support them with bzero).
embray commentedon Nov 16, 2015
Suprising indeed. I know why it is though. On
this lineit checks if the type is unsigned int by checking thedtype.kindattribute. However, for a multi-dimensional type this is'V', not'u'(or whatever the base kind happens to be). So that's a minor bug in its own right.fix for the fits.BinTableHDU error with uint8 data astropy#4267
AMAN3003 commentedon Feb 13, 2016
@sbailey and @embray i have come with fix please review it
AMAN3003@ef9ec6d
AMAN3003 commentedon Feb 13, 2016
@embray and @sbailey key erroris raised when dictinary key is unable to find its value. here 1:because 10 is in categories of unint8
also if we pass int8 its forking fine because in that case it not entering in bug part of the code
also @embray is right it has nothing to do with hdu = fits.BinTableHDU(data, uint=True) &
hdu = fits.BinTableHDU(data)
AMAN3003 commentedon Feb 13, 2016
@embray can i add test for it
embray commentedon Feb 17, 2016
@AMAN3003 This fix is not correct though, because as I pointed out unsigned bytes are stored natively in FITS, while it's signed bytes that need special handling, converse to all other byte types. This needs to be fixed for images as well as tables. Now that I think about it it's actually a pretty serious bug, but somehow it hasn't come up before.
Can someone confirm whether a FITS file containing signed bytes created by Astropy is read correctly by other software, say, CFITSIO or IRAF?
sbailey commentedon Feb 17, 2016
Using code snippet below to test reading/writing images, I found:
I'm not sure if that is the test you were requesting though, but wow this is a mess.
Results:
embray commentedon Feb 18, 2016
@sbailey Thanks for doing those tests, that's perfect!
As for uint64, I believe CFITSIO has lacked support for that for a while, so the problem is in CFITSIO I think (but someone please correct me if that's wrong--I'm not sure--I just remember that being the case some time ago).
But for signed/unsigned bytes I think
astropy.io.fitsis definitely broken. Aman's attempt at a fix had the right idea, but unfortunately it needs to do more to treat signed/unsigned bytes as a separate special case (and needs to work for images as well as tables).bsipocz commentedon Mar 18, 2019
All examples from the original post work, but I'm confused of what the desired test results should be for #4267 (comment) . I've edited the code, so it's copy-pasteable.
@saimn or @MSeifert04 - could you have a quick look of this and possible close it?
saimn commentedon Mar 18, 2019
The original issue with uint8 data in BinTableHDU seems to be solved.
The only issue that remains I think, is with int8 data. Related to the post above, fitsio can write a file with int8 data, with the file is bad (BITPIX=64, BZERO=9223372036854775808). But int8 is another issue, probably not easy to support and not too common, I think we can close this one.