2

実際の降雨データを日付と時刻として記録し、転倒バケツの雨量計に蓄積されたヒントの数を記録しています。傾斜バケットは、0.5mm の降雨量を表します。ファイルを循環して、強度の変動 (降雨量/時間) を決定したいので、複数の固定された時間枠にわたるローリング平均が必要です: したがって、5 分間の雨が蓄積されるまで降雨量を累積し、強度を mm/ 単位で決定したいと考えています。時間。したがって、3mm が 5 分で記録される場合、3/5*60 = 36mm/hr に等しくなります。10 分間の同じ降雨量は 18 mm/hr になります...

したがって、数時間にわたる降雨がある場合は、5、10、15、20、25、30、45、60 分など、いくつかの標準的な間隔で確認する必要がある場合があります。また、データは逆の順序で記録されます。生ファイルなので、最も早い時間がファイルの最後にあり、後の最後の時間ステップがヘッダーの後に最初に表示されます。 hr ただし、16:27 から 16:34 の間 967-961 = 6 本のチップ = 7 分で 3mm = 27.71mm/時間

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

助言がありますか?

4

2 に答える 2

1

あなたが何について質問しているのか、私にはよくわかりません。

ファイルの読み方はわかりますか?次のようなことができます:

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()

データは累積的であるため、2 つのエントリごとに減算する必要があります。これは、Python のリスト内包表記が非常に優れているところです。

data = [(t1, d2 - d1) for ((t1,d1), (t2, d2)) in zip(data, data[1:])]
print data

ここで、ループして、過去 x 分間のエントリ数を確認する必要があります。

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 )
于 2011-11-28T11:21:11.227 に答える
0

タイム スタンプは一定の間隔で取得されるわけではないため、最も正確な結果を得るには補間を使用する必要があります。これにより、ローリング平均も簡単になります。以下のコードで、この回答Interpolateのクラスを使用しています。

from time import strptime, mktime

totime = lambda x: int(mktime(strptime(x, "%d/%m/%Y %H:%M")))
with open("my_file.txt", "r") as myfile:
    # Skip header
    for line in myfile:
        if line.startswith("DATE"):
            break
    times = []
    values = []
    for line in myfile:
        date, time, value = line.split()
        times.append(totime(" ".join((date, time))))
        values.append(int(value))
times.reverse()
values.reverse()
i = Interpolate(times, values)

あとは、間隔を選択して、各間隔のエンドポイント間の差を計算するだけです。そのためのジェネレーター関数を作成しましょう。

def rolling_avg(cumulative_lookup, start, stop, step_size, window_size):
    for t in range(start + window_size, stop, step_size):
        total = cumulative_lookup[t] - cumulative_lookup[t - window_size]
        yield total / window_size

以下に、前の 1 時間の 1 時間あたりのヒント数を 10 分間隔で出力しています。

start = totime("8/11/2011 15:30")
stop = totime("8/11/2011 20:33")
for avg in rolling_avg(i, start, stop, 600, 3600):
    print avg * 3600

編集: inttotimeを返すようにし、rolling_avgジェネレーターを作成しました。

于 2011-11-28T11:40:34.997 に答える