Float64 dtype issues

178 views
Skip to first unread message

Sean Arms

unread,
Jul 6, 2011, 4:40:53 PM7/6/11
to py...@googlegroups.com
Greetings!

I am using pydap to read a grib2 file from the Unidata THREDDS server.
When I try to access the data, I get the following error:

----------

/Users/lesserwhirls/.local/lib/python2.7/site-packages/pydap/xdr.py in
getvalue(self)
139 dtype = ">%s%s" % (self.var.type.typecode,
self.var.type.size)
140 #dtype = ">%s%s" % ('f', self.var.type.size)

--> 141 out = numpy.fromstring(self._buf[i:j], dtype=dtype)
142
143 if getattr(self.var, 'shape', False):

TypeError: data type ">d8" not understood

----------

sample code to reproduce the error:

======

from pydap.client import open_url
dataset = open_url('http://motherlode.ucar.edu/thredds/dodsC/fmrc/NCEP/NAM/CONUS_40km/conduit/files/NAM_CONUS_40km_conduit_20110706_1200.grib2')
var = dataset["Temperature_surface"]
print var[0,0,0]

======

However, if I go into the pydap code (xdr.py) and force the type to be
'f' instead of 'd', everything works great. The variable it bombs on
is the 'y' variable in the file, which is listed as a Float64. The
Float64 is being translated into ">d8", but ">d8" is not a recognized
dtype in the current numpy development branch. However, ">d8" is valid
in numpy 1.4. That said, the *interesting* thing is that ">d8" is
automatically converted over to ">f8".

======

In [6]: np.dtype('>d8')

Out[6]: dtype('>f8')

======

So, while the dtype ">d8" works on older versions of numpy, it's only
because somewhere under the hood of numpy, ">d8" is changed to ">f8" -
maybe there was a deprecation of that data type at some point? At any
rate, here is a fix:

----------

Fix:

In model.py, change line 25 from

Float64 = TypeFactory('Float64', 'd', 8)

to:

Float64 = TypeFactory('Float64', 'f', 8)

----------

Note: I am unsure how this would affect versions of numpy prior to
1.4, but this should be a safe fix for >1.4, unless you see any issues
that I do not see.

Cheers!

Sean Arms
UCAR/Unidata
sa...@unidata.ucar.edu

Sean Arms

unread,
Jul 6, 2011, 4:50:34 PM7/6/11
to py...@googlegroups.com
Sorry, I forgot to mention that I am using pydap 3.0 and python 2.7.

Roberto De Almeida

unread,
Jul 18, 2011, 4:11:12 PM7/18/11
to py...@googlegroups.com
Thanks, Sean. I'll fix the code and make a new release asap.

Best,
--Rob

--
You received this message because you are subscribed to the Google Groups "pydap" group.
To post to this group, send email to py...@googlegroups.com.
To unsubscribe from this group, send email to pydap+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pydap?hl=en.




--
Dr. Roberto De Almeida
http://roberto.dealmeida.net/
http://lattes.cnpq.br/1858859813771449
:wq

Roberto De Almeida

unread,
Jul 19, 2011, 11:00:46 AM7/19/11
to py...@googlegroups.com
Hi, Sean!

Thanks, this is fixed in 3.0.1 (just released) and in the repository.

Cheers,
--Rob
Reply all
Reply to author
Forward
0 new messages