问题描述
我有一些实际的降雨数据记录为日期和时间,以及在翻斗式雨量计上的小费累计数量.倾卸桶代表0.5mm的降雨量.我想循环浏览文件并确定强度的变化(降雨/时间)因此,我需要多个固定时间范围内的滚动平均值:因此,我要累积降雨,直到累积5分钟的降雨,然后以mm/小时为单位确定强度.因此,如果在5分钟内录制了3mm,则等于3/5 * 60 = 36mm/hr.在10分钟内,相同的降雨量将为18mm/hr ...
I have some real rainfall data recorded as the date and time, and the accumulated number of tips on a tipping bucket rain-gauge. The tipping bucket represents 0.5mm of rainfall.I want to cycle through the file and determine the variation in intensity (rainfall/time)So I need a rolling average over multiple fixed time frames:So I want to accumulate rainfall, until 5minutes of rain is accumulated and determine the intensity in mm/hour. So if 3mm is recorded in 5min it is equal to 3/5*60 = 36mm/hr.the same rainfall over 10 minutes would be 18mm/hr...
因此,如果我几个小时都有降雨,则可能需要按照几个标准间隔进行检查,例如:5、10、15、20、25、30、45、60分钟等.同样,数据也以相反的顺序记录在原始文件中,因此最早的时间在文件的末尾,而后一个和最后一个时间的步骤首先出现在标头之后:看起来像...(此处975-961 = 14个提示= 7毫米的降雨)平均强度1.4毫米/小时但是在16:27和16:34之间967-961 = 6个技巧= 7分钟内3毫米= 27.71毫米/小时
So if I have rainfall over several hours I may need to review at several standard intervals of say: 5, 10,15,20,25,30,45,60 minutes etc...Also the data is recorded in reverse order in the raw file, so the earliest time is at the end of the file and the later and last time step appears first after a header:Looks like... (here 975 - 961 = 14 tips = 7mm of rainfall) average intensity 1.4mm/hrBut between 16:27 and 16:34 967-961 = 6 tips = 3mm in 7 min = 27.71mm/hour
7424 Figtree (O'Briens Rd)
DATE :hh:mm Accum Tips
8/11/2011 20:33 975
8/11/2011 20:14 974
8/11/2011 20:04 973
8/11/2011 20:00 972
8/11/2011 19:35 971
8/11/2011 18:29 969
8/11/2011 16:44 968
8/11/2011 16:34 967
8/11/2011 16:33 966
8/11/2011 16:32 965
8/11/2011 16:28 963
8/11/2011 16:27 962
8/11/2011 15:30 961
有什么建议吗?
推荐答案
我不确定您有什么疑问.
I am not entirely sure what it is that you have a question about.
您知道如何读取文件吗?您可以执行以下操作:
Do you know how to read out the file? You can do something like:
data = [] # Empty list of counts
# Skip the header
lines = [line.strip() for line in open('data.txt')][2::]
for line in lines:
print line
date, hour, count = line.split()
h,m = hour.split(':')
t = int(h) * 60 + int(m) # Compute total minutes
data.append( (t, int(count) ) ) # Append as tuple
data.reverse()
由于您的数据是累积数据,因此您需要将每两个条目相减,这就是python的列表推导非常好.
Since your data is cumulative, you need to subtract each two entries, this is wherepython's list comprehensions are really nice.
data = [(t1, d2 - d1) for ((t1,d1), (t2, d2)) in zip(data, data[1:])]
print data
现在,我们需要循环浏览并查看最近x分钟内有多少条目.
Now we need to loop through and see how many entries are within the last x minutes.
timewindow = 10
for i, (t, count) in enumerate(data):
# Find the entries that happened within the last [...] minutes
withinwindow = filter( lambda x: x[0] > t - timewindow, data )
# now you can print out any kind of stats about this "within window" entries
print sum( count for (t, count) in withinwindow )
这篇关于滚动平均值以计算降雨强度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!