[SciPy-user] timeseries and maskedarrays
bevan
bevan07 at gmail.com
Sun Mar 16 19:01:49 EDT 2008
Hello,
I recently posted on the numpy forum looking for a solution to creating totals
and averages for time series of rainfall. It was suggested to me that I try
the timeseries package.
I have managed to get it working (struggling due to limited abilities rather
than any issues with the package) - thanks by the way to the developers.
However, when I run my code i get the following warning:
C:\Python25\lib\site-packages\scipy\sandbox\maskedarray\core.py:1521:
UserWarning: Warning: converting a masked element to nan.
warnings.warn("Warning: converting a masked element to nan.")
Is this an issue?
The main question I have is:
How would i create an average on values based on month, that is sum the
rainfall from daily values to monthly totals (done), then average all the
Januarys, Februarys etc in the timeseries?
Also any other issues with my code (below) that is likely to trip me up later?
Thanks for your time.
import time
import numpy
import maskedarray as MA
import timeseries as TS
def readTSFtimeseries(filename):
"""
# PURPOSE: read a HYDROL .tsf file into a timeseries array.
#
# INPUT:
#20/11/2003 @ 00:00:00 Q255 T5
#21/11/2003 @ 00:00:00 0.000000 Q30 T5
#............................................
#07/05/2008 @ 00:00:00 2.500000 Q10 T5
#
# OUTPUT: a timeseries array
#
# EXAMPLE: >>> data = readTSFtimeseries(r'B:\Python\test.tsf')
# >>> x = data.dates
# >>> y = data.series
"""
MYFILE = open(filename, "r")
datafile = MYFILE.readlines()
MYFILE.close()
DateList=[]
Rain_mmList=[]
QualityList=[]
TypeList=[]
jd=[]
for datalines in datafile:
dataflds = datalines.split()
datefld =time.strptime(dataflds[0]+'_'+dataflds[2], '%d/%m/%Y_%H:%M:%S')
jd.append(datefld[7])
DateList.append(TS.Date('D',year=datefld[0],month=datefld[1],day=datefld
[2]))
if len(dataflds) == 6:
Rain_mmList.append(float(dataflds[3]))
QualityList.append(dataflds[4])
TypeList.append(dataflds[5])
if len(dataflds) == 5:
#Rain_mmList.append(float(-9.99))
Rain_mmList.append(TS.tsmasked)
QualityList.append(dataflds[3])
TypeList.append(dataflds[4])
DateArr=TS.DateArray(dates=DateList,freq='D',copy =False)
data=TS.time_series(Rain_mmList,DateArr)
print data.dates.size,data.series.size
return(data)
Raindata =readTSFtimeseries(r"C:\Documents and
Settings\bevanj\Desktop\rain.tsf")
import pylab
import matplotlib
from timeseries import plotlib as TSPL
MonRaindata = Raindata.convert('monthly', MA.sum)
print MonRaindata
print Raindata.convert('yearly', MA.sum)
#fig1=TSPL.tsfigure()3
#fplt1=fig1.add_tsplot(111)
#fplt1.tsplot(RainData,'-')
#fplt1.tsplot(MonRainData,'-')
#pylab.show()
More information about the SciPy-User
mailing list