def processRainfall(file, outdir, var, north, west, south, east): "Subsets, averages, writes to binary files." f=cdms.open(file) v=f(var, lat=(south, north), lon=(west, east)) timevalues=v.getTime()[:] t0=timevalues[0] # I need to test if step 0 always has only missing values # remove -50 values??? v=MA.masked_less(v,0) # create average of all ensemble members av=MA.average(v, axis=1) # get stuff for name datetime=os.path.split(file)[-1].split(".")[1] outpaths=[] # now step through time dimension (0) count=0 for dslice in av: ts=timevalues[count]-t0 outfile="rainfall.%s.%dh.dat" % (datetime, ts) outpath=os.path.join(outdir, outfile) count=count+1 numarray=Numeric.array(dslice._data) sh=numarray.shape length=sh[0]*sh[1] flatarray=Numeric.resize(numarray, [length]) output=open(outpath, "wb") arr=array.array('f', flatarray) arr.tofile(output) output.close() print "Written:", outpath outpaths.append(outpath) return outpaths