[SciPy-User] Calculating avgerage values on 20 minute time frequency

Daniel Lepage dplepage@gmail....
Fri Mar 18 13:43:05 CDT 2011

```If your measurements are spaced (nearly) evenly, won't the window
always be the same size (e.g. 12000 entries)? If so, the averages are
the discrete convolution of your data with a length-12000 signal of
all 1/12000s; you can do this efficiently with a fast fourier
transform.

--
Dan

On Fri, Mar 18, 2011 at 2:25 PM, Martin van Leeuwen
<vanleeuwen.martin@gmail.com> wrote:
> Hi Mike,
>
> date2num and datestr2num from pylab let you treat datetimes as floats
> which may make things more flexible. If you have a lot of data (e.g.
> from a weather network) using a database and accessing these data
> using psycopg2 maybe also be an option as SQL also allows averaging
> timeseries.
>
>
> def smooth(dates, signal, halfWindowWidth):
>
>        # signal is a one dimensional array
>        # dates is a one dimensional array of datatype float with times in
> units days (e.g. from datestr2num)
>        # elements in dates correspond to those in signal
>        # halfWindowWidth (int or float) indicates half the window width in seconds
>
>        # datestr2num returns a float with units days, thus halfWindowWidth
> should be divided by the number of seconds in a day to get the same
> units as datestr2num uses
>        d = float(halfWindowWidth)/float(3600*24)
>
>        smoothed = scipy.zeros((scipy.size(signal) ))
>        i=0
>
>        for date in dates:
>                t_num_start = date - d
>                t_num_end = date + d
>
>                s = scipy.argmin(abs(dates-t_num_start))        #get closest time to start
> of time window
>                e = scipy.argmin(abs(dates-t_num_end))  #get closest time to end of time window
>
>                av = scipy.average(signal[s:e])
>
>                smoothed[i] = av
>                i+=1
>
>        return smoothed
>
>
>
> Hope that helps a bit. Notice the window attracts the closest datetime
> in your series, not necessarily what's within the window.
>
> Martin
>
>
>
> 2011/3/18 Michael T Tate <mttate@usgs.gov>:
>>
>> I have a time series date set that contains a date/time field and data
>> fields (sonic temperature, WS-U, WS-V, WS-W). The data are recorded at 10hz.
>> I would like to calculate an average for each of the data fields on a 20min
>> frequency so it can be matched up with data collected by another instrument.
>>
>> It is pretty straightforward to calculate hourly averages using convert from
>> scikits.timeseries.
>>
>> Does anyone have any ideas on how I would calculate 20min averages for this
>> data?
>>
>>
>>
>> Mike
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
```