Hello,
I need to write a float32 dataset that uses +Inf as fill value. Writing infinite values in the dataset works fine, but it seems that setting the fill value fails.
Here is what I have done :
---
from pyhdf import SD
import numpy
# data to write : a float32 array of Infinite values
data = numpy.zeros ( ( 2, 2 ), dtype = numpy.float32 ) + numpy.inf
# write data to hdf file of float32 Inf -> OK
fname = "myfile.hdf"
sds_name = "data"
hdf = SD.SD ( fname, SD.SDC.WRITE | SD.SDC.CREATE )
sds = hdf.create( sds_name, SD.SDC.FLOAT32, data.shape )
sds[:] = data[:]
# set an Inf fill value -> NOT OK
fill = numpy.float32 ( numpy.inf )
sds.setfillvalue ( fill ) # <-- Fails here
sds.endaccess()
hdf.end()
---
I obtain the error :
Traceback (most recent call last):
File "test.py", line 16, in <module>
sds.setfillvalue ( fill )
File "/usr/local/lib/python2.6/dist-packages/pyhdf/SD.py", line 2468, in setfillvalue
buf[0] = fill_val
File "/usr/local/lib/python2.6/dist-packages/pyhdf/hdfext.py", line 237, in __setitem__
def __setitem__(*args): return _hdfext.array_float32___setitem__(*args)
TypeError: in method 'array_float32___setitem__', argument 3 of type 'float'
The problem does not appear when using float64 values, but occurs even if I try to write it directly as a SDS _FillValue attribute, or as a file attribute.
Does anybody know how I can manage that ?
Thanks by advance.
- Configuration -
Python 2.6.4
numpy-1.3.0
HDF4.2r4
pyhdf-0.8.3