Archive for January, 2008

netcdf in python

Scipy doesn’t support writing netcdf files yet, which just rocks. Scientific.IO.netCDF has a few quirks, the first of which it is wordy, the second of which is it won’t retrieve the unlimited dimension (usually time).

I’m getting the latest cdat source, and I’m going to build it, in the hopes that the cdat netCDF interface, being for climate scientists and all, should be robust and easy to use.

Advertisements

Leave a Comment

n-dimensional python code

OK, I’m no python wizard. And trying to learn Numpy at the same time as python itself adds a whole extra dimension of confuse.

As a physicist, I’m trained to be lazy. So I like to write my code to be independent of the number of dimensions it might be for. Case in point, sph kernels. Why write three different cases


if dims==1:
kernel = ....
elif dims==2:
kernel=...

When you can write

for i in range(0,dims):
kernel = kernel+next_dimensions_contribution

Numpy was seriously getting to me when I discovered that zero dimensional arrays cannot be indexed. This inability means the d[0] is fine for a two dimensional vector such as (17.8,44.3), but no good for just (88,2), even if they are boht numpy arrays. The solution turns out to be to use numpy.atleast_1d() to force the zero dimensional array to have a dimension.

It’s little problems like this that make numpy a little more user-unfriendly than it should be. It’s very powerful, however my opinion is that there are too many points of difference with fortran/matlab/octave, and too many gotchas like this that end up costing time for it to be a language for scientists who aren’t already programmatically inclined.

I think it will get there –

Leave a Comment

The real power of version control

Having a time machine means you can be utterly ruthless. From time to time I’m overcome by obsessive urges not to delete old lines that have long since been commented out, just in case, at some unspecified time in the future, I need to see how I implemented what I decided was no longer needed.

A bit like keeping that old t-shirt you haven’t worn in 2 years, just in case.

Svn saves me from having to actually confront my obsessive behaviour, through the knowledge that the past is still accessible.

Leave a Comment

Visual tracking of clusters with Quake

Carl Javier, Adam Black and Lucas Parry, working for Swinburne University in Melbourne under teh supervision of Grenville Armitage has developed 3D visualisation tool for networks based on the Quake 3 arena engine.

Leave a Comment

Functional programming in python

More than just a few tricks to reduce your code line count. I’m currently reading this tutorial by alan gauld

Leave a Comment