# [SciPy-user] Calculating daily, monthly and seasonal averages of hourly time series data.

Lionel Roubeyrie lroubeyrie@limair.asso...
Thu Oct 9 03:51:27 CDT 2008

```Hi Dharhas,
scikits.timeseries is perfect for what you want in a very useable way :

###############################
In [29]: import scikits.timeseries as ts

In [30]: sdate=ts.Date('H', '2007-01-01 00:00')

In [31]: fielddates=ts.date_array(start_date=sdate, freq='H',
length=365*24*2)

In [32]: salinity=random(365*24*2)*100

In [33]: mes=ts.time_series(data=salinity, dates=fielddates)

In [34]: mes
Out[34]:
timeseries([ 23.84116045  49.51437251  89.29221711 ...,  37.00510947
41.12589836
78.65572656],
dates = [01-jan-2007 00:00 ... 30-déc-2008 23:00],
freq  = H)

In [35]: mes_avmonth=mes.convert(freq='M', func=mean)

In [36]: mes_avmonth
Out[36]:
timeseries([ 49.29718906  50.64688937  49.88193999  48.97144253
49.5788259
50.41340038  50.15047009  51.70933261  50.5635153   51.15084406
51.15362514  51.51443468  49.17556599  49.26877667  50.21416724
49.37037657  51.00724033  49.43337134  49.60398056  50.24470761
50.62350109  51.15572702  51.37652011  49.24193747],
dates = [jan-2007 ... déc-2008],
freq  = M)

In [37]: mes_avyear=mes.convert(freq='Y', func=mean)

In [38]: mes_avyear
Out[38]:
timeseries([ 50.41903159  50.06468157],
dates = [2007 2008],
freq  = A-DEC)

In [39]: mes_avseason=mes[(mes.month>=5) & (mes.month<=9)].mean()

In [40]: mes_avseason
Out[40]: 50,33380690600049
###############################

Le mercredi 08 octobre 2008 à 14:54 -0500, Dharhas Pothina a écrit :
> Hi,
>
> I'm trying to analyze hourly salinity data. I was wondering if there is a simple way of calculating daily, monthly and seasonal averages of hourly time series data.
>
> So assuming I have two arrays that contain several years of hourly (or every 15min) salinity data: a datetime array called 'fielddates' & a data array called 'salinity'
>
> How would I go about getting the various averages. The seasonal averages would be say defined as May through September etc.
>
> I had a look at scikits.timeseries but it looks like it would require upgrading numpy to install and there isn't enough high level documentation on how to use it for me to be confident in picking it up in the time frame I'm looking at. I'm also not completely clear if it can handle stuff that happens on a scale smaller than a day. If anyone can point me to any usage examples for it that would be appreciated.
>
> Thanks,
>
> - dharhas
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
--
Lionel Roubeyrie
chargé d'études
LIMAIR - La Surveillance de l'Air en Limousin
http://www.limair.asso.fr

```