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
It appears that (c)fitsio is treating my integer mask as a float, requiring it to be cast back as an int, which then loses information for the lowest bits when high bits are set because of the int -> float -> int round trip.
Example:
importnumpyasnpimportfitsio# create a mask where all bits up to bit n are setmask=np.array([2**n-1forninrange(1,64)])
x=np.arange(len(mask))
data=np.core.records.fromarrays([mask,x], names=('mask', 'x'))
filename='blat.fits'fitsio.write(filename, data, clobber=True)
withfitsio.FITS(filename) asfx:
# Trying to use 'mask' directly results in# OSError: FITSIO status = 431: syntax error in expression# Bitwise operations with incompatible types; only (bit OP bit) and (int OP int)# w = fx[1].where('(mask & 1) == 1')# Cast to (int) avoids error, but misses largest entriesw1=fx[1].where('((int)mask & 1) == 1')
w2=np.where((mask&1) ==1)[0] # w1 should be the same as this but isn'tw3=np.where((mask.astype(float).astype(int) &1) ==1)[0] # w1 matches this insteadprint(f'{w1=}')
print(f'{w2=}')
print(f'{w3=}')
Note that w1 (derived with fitsio.FITS.where) is missing the largest masks, but it matches w3 which is derived by casting mask to float and back to int before doing the bitwise masking operation.
I'm using fitsio 1.2.1.
The text was updated successfully, but these errors were encountered:
I'm trying to filter on a bitmask while reading a binary table, e.g. following https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node102.html .
It appears that (c)fitsio is treating my integer mask as a float, requiring it to be cast back as an int, which then loses information for the lowest bits when high bits are set because of the int -> float -> int round trip.
Example:
Results:
Note that
w1
(derived withfitsio.FITS.where
) is missing the largest masks, but it matchesw3
which is derived by castingmask
to float and back to int before doing the bitwise masking operation.I'm using fitsio 1.2.1.
The text was updated successfully, but these errors were encountered: