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

Compressing floating point image with NaN values #356

Open
astrofrog opened this issue Dec 13, 2022 · 1 comment
Open

Compressing floating point image with NaN values #356

astrofrog opened this issue Dec 13, 2022 · 1 comment

Comments

@astrofrog
Copy link

The following example shows that if a NaN value is present in the original data being compressed, the whole tile will be NaN when read in again:

In [1]: import numpy as np
   ...: data = np.arange(36).reshape((6, 6)).astype(float)
   ...: data[1, 1] = np.nan
   ...: data
Out[1]: 
array([[ 0.,  1.,  2.,  3.,  4.,  5.],
       [ 6., nan,  8.,  9., 10., 11.],
       [12., 13., 14., 15., 16., 17.],
       [18., 19., 20., 21., 22., 23.],
       [24., 25., 26., 27., 28., 29.],
       [30., 31., 32., 33., 34., 35.]])

In [2]: import fitsio
   ...: ft = fitsio.FITS('test_masking.fits', "rw")
   ...: ft.write(data, compress='RICE_1', tile_dims=(3, 3))

In [3]: ft2 = fitsio.FITS('test_masking.fits', 'r')
   ...: ft2[1].read()
Out[3]: 
array([[nan, nan, nan,  3.,  4.,  5.],
       [nan, nan, nan,  9., 10., 11.],
       [nan, nan, nan, 15., 16., 17.],
       [18., 19., 20., 21., 22., 23.],
       [24., 25., 26., 27., 28., 29.],
       [30., 31., 32., 33., 34., 35.]])

The FITS standard seems to suggest that ZBLANK can be used to circumvent this, and store NaN values (once quantized) as a specific integer value, which can then be converted back to NaN when de-quantizing. Is this something that can be done with fitsio?

@esheldon
Copy link
Owner

I'm sorry for the very late reply. I don't know if it can be done, but I would be very happy to accept a pull request for this..

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

No branches or pull requests

2 participants