I have encountered a problem when you want to pass a python object to ferret and want to work with an abstract axis to stay simple.
Here, I have simplified the problem by getting and putting back the same object.
It fails when the object has an abstract axis.
I also have found a solution by writing in the axis_coords tuple a None rather than the values themselves.
Otherwise you get this error:
`
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
`
Here is the code to test this:
import numpy as np
import pyferret
#========================================================
pyferret.start()
pyferret.run('use monthly_navy_winds.cdf')
#========================================================
# Simple get and put same data ---> works !
a = pyferret.getdata('uwnd', False)
a['name']='myvar'
print a.keys()
print a['axis_types']
pyferret.putdata(a,None)
pyferret.run('show data')
#========================================================
# Change the variable to an abstract axis
# then get and put it back for testing --> fails !
pyferret.run('def axis/t=1:132:1 mytaxis')
pyferret.run('let uwnd2 = uwnd[gt=mytaxis@ASN]')
pyferret.run('show grid uwnd2')
a = pyferret.getdata('uwnd2', False)
a['name']='myvar2'
print a.keys()
a['axis_coords'] = (
a['axis_coords'][0],
a['axis_coords'][1],
a['axis_coords'][2],
a['axis_coords'][3], # <--- to None to get rid off the error
a['axis_coords'][4],
a['axis_coords'][5],
)
pyferret.putdata(a,None)
pyferret.run('show data')
Error:
/opt/pyferret-7.4.4-RHEL7-64-Python2.7/lib/python2.7/site-packages/pyferret/datamethods.pyc in putdata(datavar_dict, axis_pos)
541 raise ValueError("number of coordinates for axis %d does not match the number of data points" % (k+1))
542 elif axis_types[k] == libpyferret.AXISTYPE_ABSTRACT:
--> 543 if axis_coords[k] != None:
544 axis_coords[k] = numpy.array(axis_coords[k], dtype=numpy.float64, copy=1)
545 if axis_coords[k].shape[0] != shape[k]:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I have encountered a problem when you want to pass a python object to ferret and want to work with an abstract axis to stay simple.
Here, I have simplified the problem by getting and putting back the same object. It fails when the object has an abstract axis. I also have found a solution by writing in the axis_coords tuple a
None
rather than the values themselves.Otherwise you get this error:
`
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
`
Here is the code to test this:
Error: