Closed PBrockmann closed 7 years ago
I desperately need to update the PyFerret documentation. There is now a getstrdata
method returns a string variable (ie, string array; I still need to add a method to return a single string symbols). In my FerDSet object, I use:
namesdict = pyferret.getstrdata('..varnames')
for varname in namesdict['data'].flatten():
if sys.version_info[0] > 2:
# For Python3.x: namesdict['data'] is a NumPy array of bytes; convert to unicode
varname = str(varname, 'UTF-8')
I could add a method that returns an array of the variable names (pretty much just the code above).
But you might want to look into the FerDSet object
>>> lev = pyferret.FerDSet('levitus_climatology.cdf')
>>> dir(lev)
['SALT', 'TEMP', ..., 'salt', 'temp']
>>> lev.temp
FerVar(varname='TEMP', dsetname='levitus_climatology.cdf', title = '', defn='TEMP[d=levitus_climatology.cdf]')
Indeed, the release note describes exactly what I was looking with the use of
pyferret.getstrdata('..varnames')
Thanks Karl.
I have just tested this getstrdata method on my old laptop (PyFerret-7.0.0-Ubuntu-14.04-32) and I get different results than with my workstation (pyferret-7.1.0-Ubuntu-14.04-64).
errval, errmsg = pyferret.run('use levitus_climatology')
varnamesdict = pyferret.getstrdata('..varnames')
varnamesdict['data'].flatten()
I get with pyferret-7.1.0-Ubuntu-14.04-64
array(['TEMP', 'SALT'], dtype='|S5')
but with "older" PyFerret-7.0.0-Ubuntu-14.04-32
array(['TEMP', '\x04'], dtype='|S5')
--> no SALT variable ?
Is the 32 architecture definitely abandoned ?
That is an error I had seen before and fixed, so not surprised this is showing up in the old version. I can build an Ubuntu-14.04 32-bit version; just was waiting to see if it was still needed.
If it is not too painfull to build, I would like to have one for this architecture. Many thanks.
Ends up this was a bug in the 32-bit build that had not been fixed. As I was in the middle to getting the updates to memory management and other changes from Ferret into PyFerret, I added the fix into this latest v7.1.1-beta release and did not try making a one-off update to v7.1.
I will get the Ubuntu pre-built bundles uploaded for v7.1.1-beta. And you can try out the new memory management.
pre-built builds added, and this should now be fixed in the v7.1.1 Ubuntu-14.04-32 build.
A new method that returns the list of variables from open datasets or defined aggregations would be very convenient.
For now, I have been able to capture the "show data" information about variables by doing
but this needs extra work to parse all the output displayed.
would be much easier.
This method could return an array as follows:
Then list variables comes from: