Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-26 Thread mdekauwe
Yep that will do nicely, code becomes import sys, os, glob import numpy as np def averageEightDays(files, numrows, numcols, year, doy): """ Read in 8 files at a time, sum the valid LST, keep a count of the valid pixels and average the result every 8days. """

Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-26 Thread Vincent Schut
mdekauwe wrote: > > Vincent Schut-2 wrote: >> Oh, and minor issue: creating a array of zeros and then multiplying with >> -999 still makes an array of zeros... I'd incorporated an array of >> *ones* multiplied with -999, because for the last chunk of days you >> could end up with a 8day array o

Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-26 Thread mdekauwe
Vincent Schut-2 wrote: > > Oh, and minor issue: creating a array of zeros and then multiplying with > -999 still makes an array of zeros... I'd incorporated an array of > *ones* multiplied with -999, because for the last chunk of days you > could end up with a 8day array only partly filled wi

Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-26 Thread Vincent Schut
mdekauwe wrote: > Thanks...I have adopted that and as you said it is a lot neater! Though I > need to keep the pixel count for a weighting in another piece of code so > have amended your logic slightly. Alternatively, you could simply take the sum over axis=0 of the weight array to get the pixel

Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-26 Thread mdekauwe
Thanks...I have adopted that and as you said it is a lot neater! Though I need to keep the pixel count for a weighting in another piece of code so have amended your logic slightly. #!/usr/bin/env python import sys, os, glob import numpy as np def averageEightDays(filenamesList, numrows, numcol

Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-26 Thread Vincent Schut
Hi mdekauwe, as long as your data size is small enough to fit a 8x array in memory and use it, why not just skip the running total and average 8 data arrays each 8day period? And skip the x and y loops; these are real performance killers. As a bonus, your code gets a lot smaller and more reade

Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-26 Thread mdekauwe
Thanks. Agreed it will break down under that scenario but that shouldn't be encountered as I am simply checking the value is greater than what I have set the undefined to be (-999.0). Here is the refjigged logic using numpy functionality for anyone who it might help. Would appreciate any suggestio

Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-25 Thread Pierre GM
On Nov 25, 2009, at 4:13 PM, mdekauwe wrote: > I tried redoing the internal logic for example by using the where function > but I can't seem to work out how to match up the logic. For example (note > slightly different from above). If I change the main loop to > > lst = np.where((data > -900.0) &

Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-25 Thread josef . pktd
On Wed, Nov 25, 2009 at 4:13 PM, mdekauwe wrote: > > I tried redoing the internal logic for example by using the where function > but I can't seem to work out how to match up the logic. For example (note > slightly different from above). If I change the main loop to > > lst = np.where((data > -900

Re: [Numpy-discussion] Help making better use of numpy array functions

2009-11-25 Thread mdekauwe
I tried redoing the internal logic for example by using the where function but I can't seem to work out how to match up the logic. For example (note slightly different from above). If I change the main loop to lst = np.where((data > -900.0) & (lst < -900.0), data, lst) lst = np.where((data > -900

[Numpy-discussion] Help making better use of numpy array functions

2009-11-24 Thread mdekauwe
Hi I have written some code and I would appreciate any suggestions to make better use of the numpy arrays functions to make it a bit more efficient and less of a port from C. Any tricks are thoughts would be much appreciated. The code reads in a series of images, collects a running total if the v