Open ngbusca opened 7 years ago
example code: ` In [1]: import fitsio
In [2]: h=fitsio.FITS("example_bool.fits","rw")
In [3]: a=rand(10)
In [4]: h.write(a)
In [5]: a=rand(10)>0.5
In [6]: h.write(a)
In [7]: h.close()
In [8]: h=fitsio.FITS("example_bool.fits")
In [9]: h Out[9]:
file: example_bool.fits mode: READONLY extnum hdutype hduname[v] 0 IMAGE_HDU
In [10]: `
I'm sorry I missed your report earlier. I think I was traveling at that time and missed a number of things.
The code you posted does produce an error for me
h=fitsio.FITS("example_bool.fits","rw")
a=numpy.random.random(10)
h.write(a)
a=numpy.random.random(10)>0.5
h.write(a)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
TypeError: Unsupported numpy image datatype 0
The above exception was the direct cause of the following exception:
SystemError Traceback (most recent call last)
<ipython-input-8-b3fad0e0b795> in <module>()
----> 1 h.write(a)
~/miniconda3/lib/python3.6/site-packages/fitsio/fitslib.py in write(self, data, units, extname, extver, compress, tile_dims, header, names, table_type, write_bitcols, **keys)
483 self.write_image(data, extname=extname, extver=extver,
484 compress=compress, tile_dims=tile_dims,
--> 485 header=header)
486 else:
487 self.write_table(data, units=units,
~/miniconda3/lib/python3.6/site-packages/fitsio/fitslib.py in write_image(self, img, extname, extver, compress, tile_dims, header)
537 header=header,
538 extname=extname, extver=extver,
--> 539 compress=compress, tile_dims=tile_dims)
540
541 if header is not None:
~/miniconda3/lib/python3.6/site-packages/fitsio/fitslib.py in create_image_hdu(self, img, dims, dtype, extname, extver, compress, tile_dims, header)
689 tile_dims=tile_dims,
690 extname=extname,
--> 691 extver=extver)
692
693
SystemError: <built-in method create_image_hdu of _fitsio.FITS object at 0x7f4901b75d08> returned a result with an error set
I'm sorry I missed your report earlier.
no problem!
I've just tried again at nersc with python 2.7.14, fitsio 0.9.11 and I get the behavior I initially reported. What version of fitsio did you try for your test? I'll see if I can reproduce your error on the same python (3.6?) and fitsio as you.
Yes, that was 3.6 and numpy 1.13.3, fitsio from recent master
Have you tried with python 3 or recent fitsio master?
I've just tried in python3 with fitsio 0.9.11 and I get the same error as you. Is this the expected behavior? Thanks!
Maybe; I didn't add the boolean support, maybe @dstndstn or @rainwoodman can comment
Huh, that's confusing because it looks like we handle NPY_BOOL here,
(and I just checked the numpy headers and NPY_BOOL is enumeration value 0, matching your error message.)
On Tue, Mar 20, 2018 at 2:38 PM, Erin Sheldon notifications@github.com wrote:
Maybe; I didn't add the boolean support, maybe @dstndstn https://github.com/dstndstn or @rainwoodman https://github.com/rainwoodman can comment
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/esheldon/fitsio/issues/137#issuecomment-374711025, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBD_VrWHxWUnZ3ILvPL9jDLrbmKz7rxks5tgUy0gaJpZM4PxV9f .
Where do we stand on this one?
ping
Hi Erin,
I still get an error with FITSIO 1.1.3 and Python 3.9.0
import fitsio
from numpy.random import rand
h=fitsio.FITS("example_bool.fits","rw", clobber=True)
a=rand(10)
h.write(a)
a=rand(10)>0.5
print('Writing boolean image')
h.write(a)
print('Wrote boolean image')
h.close()
h=fitsio.FITS("example_bool.fits")
print(h)
fails with
Writing boolean image
TypeError: Unsupported numpy image datatype 0
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/private/tmp/tst.py", line 8, in <module>
h.write(a)
File "/usr/local/lib/python3.9/site-packages/fitsio/fitslib.py", line 693, in write
self.write_image(data, extname=extname, extver=extver,
File "/usr/local/lib/python3.9/site-packages/fitsio/fitslib.py", line 781, in write_image
self.create_image_hdu(
File "/usr/local/lib/python3.9/site-packages/fitsio/fitslib.py", line 990, in create_image_hdu
self._FITS.create_image_hdu(
SystemError: <built-in method create_image_hdu of _fitsio.FITS object at 0x1134edd50> returned a result with an error set
Writing an np.array of bool is silently ignored. Is this on purpose? It would be useful if at least a warning were returned.