Wednesday, October 6, 2010

PyNGL Even worse than CDAT?

Undecided as yet. More to follow. But plenty of the same signs of cluelessness.

I am still hopeful that the interpolation routine I need will work. And the install is much more straightforward, there being suitable binaries for the machines I care about.

But the test routine starts with an absolute path to a python installation at NCAR!

And this is unpythonic, though perhaps this is a Fortran 77 constraint rearing its ugly head

import Ngl
import Nio
import numpy

# create an array and make a netcdf file

ff = Nio.open_file("foo.nc","c")
ff.create_dimension("x",10)
ff.create_dimension("y",10)

ff.create_variable("u","f",("x","y"))

z = numpy.zeros((10,10),"f")

# ff.variables["u"] = z doesn't work

ff.variables["u"].assign_value(z)

# assignment is by value, as the name indicates

z[3,3] = 3.3

ff.variables["u"][4,4] = 4.4

# but after assignment you can pick up a reference

u = ff.variables["u"]

u[2,2] = 2.2

"""
>>> ff.variables["u"][:]
array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 2.2, 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 4.4, 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]], dtype=float32)
"""

ff.close()

No comments: