Problems with adding float constant to NioVariables

From: Raymond P. <rtp1_at_nyahnyahspammersnyahnyah>
Date: Wed Mar 17 2010 - 10:18:56 MDT

Hello,

I am using the Nio OS10.5 build from the ESG portal, under Python 2.6
with OS 10.6 .
(This is a bit of a kludge pending a better build for 10.6/2.6 but it
sort of works). To
Get PyNio to work with Python 2.6, I had to edit the line in the PyNio
Python script
that was causing problems on account of the way it was passing an
argument
to an __init__ . This was only supposed to affect some advanced
capabilities,
but perhaps it has also created the problem I note below.

The problem I am having is that the NioVariable object doesn't know
how to perform
an operation with a float scalar. This behavior contrasts with all
other Python
arrays -- numpy arrays, masked arrays, etc. Either this broke in
Python 2.6, or
there is a bug or oversight in Nio. Here's an example of the problem:

Bring in a variable from a file

>>> T = f.variables['sat']

Check out that it looks OK.

>>> T[0:10]
masked_array(data = [ 13.06858921 13.07066441 13.07257843
13.07219887 13.07272339
   13.07136154 13.07164955 13.07108593 13.07037163 13.06673241],
              mask = False,
        fill_value = 9.96920996839e+36)

Now try to create a new array, subtracting off a float:
>>> T1 = T - 13.068
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'NioVariable' and 'float'

That didn't work. The operation seems not have been defined for an
NioVariable object.
On the other hand, the following works:
>>> T1 = T[:] - 13.068
>>> T1[0:10]
masked_array(data = [ 0.00058937 0.00266457 0.00457859 0.00419903
0.00472355 0.0033617
   0.00364971 0.00308609 0.00237179 -0.00126743],
              mask = False,
        fill_value = 9.96920996839e+36)

--------------------------------

For consistency with all the other array systems in the Python world,
you should be able to do array/scalar operations on NioVariable objects.
Are people having the same problem when running with Python 2.5?

Thanks,
Ray Pierrehumbert
_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Wed Mar 17 10:19:36 2010

This archive was generated by hypermail 2.1.8 : Mon Mar 29 2010 - 12:19:51 MDT