-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotresults.py
executable file
·148 lines (135 loc) · 3.88 KB
/
plotresults.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python
#Load in the plotting package
from matplotlib.pyplot import (figure,plot,xlabel,ylabel,title,legend,savefig,xlim,xticks)
from multiprocessing import Pool
#Read in the data file
network = 'US'
filename = network + 'results.csv'
outputDir = 'pics/'
debug = True
def main():
stage = stageSLC(contents)
for index in range(len(stage)):
plotContents(stage[index])
# pool = Pool(1)
# pool.map(plotContents,stage)
def readFile():
fob = open(filename, 'r')
contents = fob.read().strip().split('\n')
fob.close()
return contents
def stageSLC(contents):
stations = []
locations = []
channels = []
stage = []
for index in range(len(contents)):
line = contents[index].split(',')
if line[0] not in stations:
stations.append(line[0])
if line[1] not in locations:
locations.append(line[1])
if line[2] not in channels:
channels.append(line[2])
for station in stations:
for location in locations:
for channel in channels:
stage.append(' '.join([station,location,channel]))
return stage
def plotContents(station):
station = station.split(' ')
sta = station[0]
loc = station[1]
chan = station[2]
power1 = []
power2 = []
power3 = []
power4 = []
date = []
for index in range(len(contents)):
line = contents[index].split(',')
if line[0] == sta and line[1] == loc and line[2] == chan:
power1.append(float(line[5]) - float(line[6]))
power2.append(float(line[7]) - float(line[8]))
power3.append(float(line[9]) - float(line[10]))
power4.append(float(line[11]) - float(line[12]))
date.append(round(float(line[3]) + float(line[4])/365,6))
print date
#Now it is time to plot
if len(date) > 0:
if debug:
print 'Plotting', ' '.join(station)
plotme = figure()
plot(date,power1, label='4 to 8 s. period')
plot(date,power2, label='18 to 22 s. period')
plot(date,power3, label='90 to 110 s. period')
plot(date,power4, label='200 to 500 s. period')
#Here we fix up the lengend and the labels
legend(prop={'size':12})
xlabel('Time (year)')
ylabel('DQA - Computed Diff (dB)')
xlim((min(date),max(date)))
#Here we change the ticks to a more readable format
xx,locs = xticks()
ll = ['%.1f' % a for a in xx]
xticks(xx,ll)
title(network + ' ' + sta + ' ' + loc + ' ' + chan)
savefig(outputDir + network + sta + loc + chan + '.png',format='png')
else:
print 'No date range for', ' '.join(station)
contents = readFile()
main()
# #Here is what we want to plot out of it
# sta = 'GTBY'
# loc = '00'
# chan = 'LHZ'
#
# fob = open(filename,'r')
# contents = fob.read().split('\n')
# fob.close()
#
# power1a = []
# power2a = []
# power3a = []
# power4a = []
# datea = []
#
#
#
# #Get these values from the data file
# for line in contents:
# line = line.split(',')
# if line[0] == sta and line[1] == loc:
# comps = line[2]
# years = line[3]
# days = line[4]
# power1 = float(line[5]) - float(line[6])
# power2 = float(line[7]) - float(line[8])
# power3 = float(line[9]) - float(line[10])
# power4 = float(line[11]) - float(line[12])
# #Append if they match the correct channel
# if comps == chan:
# datea.append(round(float(years) + float(days)/365,2))
# power1a.append(power1)
# power2a.append(power2)
# power3a.append(power3)
# power4a.append(power4)
#
#
# #Now it is time to plot
# plotme = figure(1)
# plot(datea,power1a,label='4 to 8 s. period')
# plot(datea,power2a,label='18 to 22 s. period')
# plot(datea,power3a,label='90 to 110 s. period')
# plot(datea,power4a,label='200 to 500 s. period')
# #Here we fix up the lengend and the labels
# legend(prop={'size':12})
# xlabel('Time (year)')
# ylabel('Diff (dB)')
# xlim((min(datea),max(datea)))
# #Here we change the ticks to a more readable format
# xx,locs = xticks()
# ll = ['%.1f' % a for a in xx]
# xticks(xx,ll)
# title(network + ' ' + sta + ' ' + loc + ' ' + chan)
# savefig(network + sta + loc + chan + '.jpg',format='jpeg')