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

writing bool image is silently ignored #137

Open
ngbusca opened this issue Oct 7, 2017 · 11 comments
Open

writing bool image is silently ignored #137

ngbusca opened this issue Oct 7, 2017 · 11 comments
Labels

Comments

@ngbusca
Copy link

ngbusca commented Oct 7, 2017

Writing an np.array of bool is silently ignored. Is this on purpose? It would be useful if at least a warning were returned.

@ngbusca
Copy link
Author

ngbusca commented Oct 7, 2017

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]:
`

@esheldon
Copy link
Owner

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

@ngbusca
Copy link
Author

ngbusca commented Dec 18, 2017

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.

@esheldon
Copy link
Owner

Yes, that was 3.6 and numpy 1.13.3, fitsio from recent master

@esheldon
Copy link
Owner

Have you tried with python 3 or recent fitsio master?

@ngbusca
Copy link
Author

ngbusca commented Mar 20, 2018

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!

@esheldon
Copy link
Owner

Maybe; I didn't add the boolean support, maybe @dstndstn or @rainwoodman can comment

@dstndstn
Copy link
Contributor

dstndstn commented Mar 20, 2018 via email

@esheldon
Copy link
Owner

Where do we stand on this one?

@esheldon esheldon added the Bug label Apr 10, 2019
@esheldon
Copy link
Owner

ping

@dstndstn
Copy link
Contributor

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

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

No branches or pull requests

3 participants