-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiversionFlowCorrelation.py
More file actions
50 lines (39 loc) · 1.6 KB
/
DiversionFlowCorrelation.py
File metadata and controls
50 lines (39 loc) · 1.6 KB
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
#Elizabeth Mahon
#Calculate the covariance between flows in the Poudre and diversions
from Covariance import Covariance
import correlation
from RecordReader import RecordReader
from FlowReader import FlowReader
import math
def DivFlowCorrelation():
folder = '/home/elizabeth/Dropbox/Windows-LinuxShare/'
master = 'PercentStructures.csv'
diversions = list()
yearflow = list()
diffdiv = 0
diffflow = 0
rec_diffdiv = 0
rec_diffflow = 0
for i in range(62):
diversions.append(0)
yearflow.append(0)
data = RecordReader(folder, master)
flow = FlowReader((folder+'PoudreFlow.csv'))
for i in range(62):
for j in range(12):
yearflow[i] += float(flow[(str(i+1950)+'-'+('{0:{fill}2}'.format(j+1,fill='0')))])
#next part necessary because there's a bit of imprecision introduced in the indexes somewhere, so I can't just recalculate them
for thing in data.keys():
if(thing < (i+1950+.01*(j+1)+.005) and thing > (i+1950+.01*(j+1)-.005)):
diversions[i] += data[thing]
#remove 1983 (huge outlier - super wet year!)
yearflow.pop(33)
diversions.pop(33)
cov = Covariance(zip(yearflow, diversions))
for i in range(len(yearflow)):
diffdiv += (diversions[i] - (sum(diversions)/len(diversions)))**2
diffflow += (yearflow[i] - (sum(yearflow)/len(yearflow)))**2
dev_div = math.sqrt((1.0/len(diversions))*diffdiv)
dev_flow = math.sqrt((1.0/len(yearflow))*diffflow)
return cov/(dev_div*dev_flow), correlation.Corr(yearflow, diversions)
print DivFlowCorrelation()