[PYTHON MATRIX-SIG] notes on netcdf module

Kyle Schalm kschalm@geog.ubc.ca
Wed, 30 Oct 1996 10:47:07 -0800 (PST)


Janko Hauser writes:
>My original code read a record (one timestep) of  4-dimensional
>field var(time,z,y,x). Because of the nested lists I could use
>
>data=array(f_hist.var(var_name)[time])
>
>, the other dimensions are unknow here.
>
>If I understand var.get() right I must now specify the length of the
>remaining dimensions, right? Or is there a default-value? (I know it's
>not difficult to get the dimensions ...)

what you want is done like this:

f_hist.var(var_name).set_cur(time,0,0,0)
data=f_hist.var(var_name).get(1, nc.all, nc.all, nc.all)

a bit of a clumsy syntax but good enough for now. 
of course if you will be reading many timesteps one at a time, it
is better to read the whole array and take slices.

in general, you can 
specify a current position in the array from which gets and puts
take place and use nc.all and nc.toEnd:

var.set_cur(1,2,3,4)
var.get(1, nc.toEnd, nc.toEnd, nc.all)

if var normally has a shape of (5,5,5,5) then this returns an array
with shape (1,3,2,5) which is a subarray beginning at (1,2,3,0).

this reminds me, there is not full support for record data yet. i will look
into that (hopefully) soon. also, longs may or may not work on any given
machine; anyway, all this code is use-at-your-own-risk ;)

-Kyle


=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================