forked from wallissoncarvalho/Cluster_SF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flowsignatures.py
65 lines (56 loc) · 1.96 KB
/
flowsignatures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'''
Created by the authors.
@wallissoncarvalho
@machadoyang
'''
import pandas as pd
import numpy as np
def quantiles(data):
return pd.DataFrame({'Q90':data.quantile(.1),'Qmean':data.mean(),'Q10':data.quantile(.9)})
def coefficient_variation(data):
return pd.DataFrame({'CV':(data.std()/data.mean())})
def rbf(data):
values = []
for column in data.columns:
denominator = 0
numerator = 0
for i in range(len(data[column])-1):
if pd.notna(data[column][i]) and pd.notna(data[column][i+1]):
numerator += abs(data[column][i+1]-data[column][i])
denominator += data[column][i]
if pd.notna(data[column][-2]) and pd.notna(data[column][-1]):
denominator += data[column][-1]
rbf = numerator/denominator
values.append(rbf)
df = pd.DataFrame({'RBF':values}, index=data.columns)
return df
def baseflow_index(data):
values = []
for column in data.columns:
values.append(data[column].rolling(7).mean().min()/data[column].mean())
df = pd.DataFrame({'IBF':values}, index=data.columns)
return df
def peak_distribution(data):
values = []
for column in data.columns:
try:
values.append((data[column].quantile(.9)-data[column].quantile(.5))/.4)
except:
values.append(np.nan)
df = pd.DataFrame({'PD':values}, index=data.columns)
return df
def auto_correlation(data):
values = []
for column in data.columns:
values.append(data[column].autocorr())
df = pd.DataFrame({'AC':values}, index=data.columns)
return df
def all_signatures(data):
df = pd.DataFrame()
df = pd.concat([df, quantiles(data)],axis=1)
df = pd.concat([df, coefficient_variation(data)],axis=1)
df = pd.concat([df, rbf(data)],axis=1)
df = pd.concat([df, baseflow_index(data)],axis=1)
df = pd.concat([df, peak_distribution(data)],axis=1)
df = pd.concat([df, auto_correlation(data)],axis=1)
return df