Friday, September 24, 2010

Exploring NIO

The PyNIO install from binary went more or less without incident; I had to dig up a conformant numpy (1.5 is out but the binary required 1.4)

I am deferring a PyNGL install until I figure out what PyNIO can do.

So now I have py 2.5.1, numpy 1.4.1, Nio 1.4.0 and a doc.

The main doc is here

Not hard for me to dig up a netcdf file from the CAM distribution; let's take a 2 D dataset from the land surface model. No idea what is in it.

-rwxr-x--- 1 tobis G-25522 7671124 Oct 22 2009

seems to work! The data object has some attributes set by the data file.

>>> import numpy as np
>>> import Nio
>>> data = Nio.open_file("")
>>> data

>>> dir(data)
['Conventions', 'Glacier_raw_data_file_name', 'History_Log', 'Host', 'Inland_water_raw_data_file_name', 'Input_navy_oro_dataset', 'Lai_raw_data_file_name', 'Logname', 'Revision_Id', 'Run_mode', 'Soil_color_raw_data_file_name', 'Soil_texture_raw_data_file_name', 'Source', 'Urban_raw_data_file_name', 'Vegetation_type_raw_data_filename', 'Version', '__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'close', 'create_dimension', 'create_variable', 'set_option']

but how to get at the actual contents?

Ah; the directory is incomplete. Apparently the extension module wasn't Pythonic. This can be patched.

So we can get at dv = data.variables() yielding


Now, just printing (__str__) data tells us

lsmlon = 128
lsmlat = 64
float PCT_LAKE [ lsmlat, lsmlon ]

so dv['PCT_LAKE'] ought to be a 128 x 64 array

but dv[2000,0] works. Apparently an overflow is treated as a [-1] index and an underflow as a [0] index. Not very reassuring.

Exasperatingly, though PyNIO is available for py2.5 and numpy 1.4, PyNGL is not. Must get python 2.6... boring...

No comments: