[PYTHON MATRIX-SIG] Another netCDF interface

Konrad Hinsen hinsen@ibs.ibs.fr
Thu, 9 Jan 1997 17:19:19 +0100


For my current major programming project I needed netCDF access, and
although a netCDF interface module for Python already exists, I was
not quite happy with it. I needed variable objects that behave as much
as possible like arrays, because I'll use both arrays and netCDF
variables interchangeably depending on size. I also needed extendable
variables for output, which the existing interface does not seem to
support. And I needed a quick project for the holidays anyway, so... I
wrote another netCDF interface module.

My module provides two new C types: netCDF files, and netCDF variables.
Once created, netCDF variables support most of the indexing operations
of arrays (the exception being negative strides). Attributes of files
and variables end up as Python attributes. An example program that
creates a demo file looks like this:

----------------------------------------------------------------------
from Numeric import *
from netcdf import *

file = NetCDFFile('test.nc', 'w')

file.title = "Just some useless junk"
file.version = 42

file.createDimension('xyz', 3)
file.createDimension('n', 20)
file.createDimension('t', 0)

foo = file.createVariable('foo', Float, ('n', 'xyz'))
foo[:,:] = 0.
foo[0,:] = [42., 42., 42.]
foo[:,1] = 1.
foo.units = "arbitrary"
print foo[0]

bar = file.createVariable('bar', Int, ('t', 'n'))
for i in range(10):
    bar[i] = i
print bar.shape

file.close()
----------------------------------------------------------------------

This is still work in progress, since it hasn't been tested much,
error checking needs improvement, and the C API is only partly
defined/implemented. What I am looking for now is people willing to
test my code. All you need is Python 1.4, NumPy, and the netcdf
library from Unidata. For Linux I can even supply a ready-made dynamic
module.

There's is also one problem that needs more attention: since file
objects and variable objects contain mutual references, they will
never be destroyed, thus creating a memory leak. This shouldn't be too
much of a problem, since the objects are small and you are not likely
to create many of them. But I will eventually take care of this.

Any volunteers?
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-4.76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------

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

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