1 | """Read in csv files and plot time series |
---|
2 | |
---|
3 | """ |
---|
4 | |
---|
5 | import project |
---|
6 | from pylab import plot, xlabel, ylabel, savefig, ion, hold, axis, close, figure |
---|
7 | from os import sep |
---|
8 | |
---|
9 | time_dir1 = '20070608_060316_run_final_1.5_onslow_nbartzis'# HAT onslow |
---|
10 | time_dir2 = '20070608_062811_run_final_1.5_exmouth_nbartzis'# HAT exmouth |
---|
11 | directory = project.outputdir |
---|
12 | filenames = [directory + time_dir1 + sep + 'gauges_time_series_100m.csv', |
---|
13 | directory + time_dir2 + sep + 'gauges_time_series_100m.csv', |
---|
14 | directory + time_dir1 + sep + 'gauges_time_series_50m.csv', |
---|
15 | directory + time_dir2 + sep + 'gauges_time_series_50m.csv', |
---|
16 | directory + time_dir1 + sep + 'gauges_time_series_20m.csv', |
---|
17 | directory + time_dir2 + sep + 'gauges_time_series_20m.csv', |
---|
18 | directory + time_dir1 + sep + 'gauges_time_series_3.5m.csv', |
---|
19 | directory + time_dir2 + sep + 'gauges_time_series_3.5m.csv', |
---|
20 | directory + time_dir1 + sep + 'gauges_time_series_closetown1.csv', |
---|
21 | directory + time_dir2 + sep + 'gauges_time_series_closetown1.csv', |
---|
22 | directory + time_dir1 + sep + 'gauges_time_series_closetown2.csv', |
---|
23 | directory + time_dir2 + sep + 'gauges_time_series_closetown2.csv'] |
---|
24 | |
---|
25 | def get_time_series_from_file(filename): |
---|
26 | fid = open(filename) |
---|
27 | lines = fid.readlines() |
---|
28 | fid.close() |
---|
29 | |
---|
30 | t = [] |
---|
31 | stage = [] |
---|
32 | depth = [] |
---|
33 | speed = [] |
---|
34 | momentum = [] |
---|
35 | for line in lines[1:]: |
---|
36 | fields = line.split(',') |
---|
37 | t.append((float(fields[0])/3600.0+5000./3600.)) |
---|
38 | stage.append(float(fields[1])) |
---|
39 | depth.append(float(fields[1])-float(fields[4])) |
---|
40 | speed.append(float(fields[3])) |
---|
41 | momentum.append(float(fields[2])) |
---|
42 | return t, stage, depth, speed, momentum |
---|
43 | |
---|
44 | max_st = 0. |
---|
45 | max_sp = 0. |
---|
46 | max_mom = 0. |
---|
47 | min_st = 0. |
---|
48 | min_sp = 0. |
---|
49 | min_mom = 0. |
---|
50 | max_t = 0.0 |
---|
51 | |
---|
52 | for filename in filenames: |
---|
53 | t, stage, depth, speed, momentum = get_time_series_from_file(filename) |
---|
54 | if max(t) > max_t: max_t = max(t) |
---|
55 | if max(stage) > max_st: max_st = max(stage) |
---|
56 | if max(speed) > max_sp: max_sp = max(speed) |
---|
57 | if max(momentum) > max_mom: max_mom = max(momentum) |
---|
58 | if min(stage) < min_st: min_st = min(stage) |
---|
59 | if min(speed) < min_sp: min_sp = min(speed) |
---|
60 | if min(momentum) < min_mom: min_mom = min(momentum) |
---|
61 | |
---|
62 | stage_axis = ([5000./3600.,max_t, min_st, max_st]) |
---|
63 | speed_axis = ([5000/3600.,max_t, min_sp, max_sp]) |
---|
64 | mom_axis = ([5000/3600.,max_t, min_mom, max_mom]) |
---|
65 | |
---|
66 | ion() |
---|
67 | """ |
---|
68 | hold(False) |
---|
69 | |
---|
70 | for i, filename in enumerate(filenames): |
---|
71 | t, stage, depth, speed, momentum = get_time_series_from_file(filename) |
---|
72 | |
---|
73 | i1 = filename.rfind('gauges') |
---|
74 | i2 = filename.rfind('csv') |
---|
75 | name = filename[i1:i2-1] |
---|
76 | loc = filename.rfind('1.5') + 4 |
---|
77 | if filename[loc] is 'o': community = 'onslow' |
---|
78 | if filename[loc] is 'e': community = 'exmouth' |
---|
79 | |
---|
80 | figure(1) |
---|
81 | plot(t, stage, '-b', linewidth=1) |
---|
82 | xlabel('time (hour)') |
---|
83 | ylabel('wave height (m)') |
---|
84 | axis(stage_axis) |
---|
85 | figname = 'stage_%s_%s.png' %(name,community) |
---|
86 | savefig(figname) |
---|
87 | |
---|
88 | figure(2) |
---|
89 | plot(t, speed, '-b', linewidth=1) |
---|
90 | xlabel('time (hour)') |
---|
91 | ylabel('speed (m/s)') |
---|
92 | axis(speed_axis) |
---|
93 | figname = 'speed_%s_%s.png' %(name,community) |
---|
94 | savefig(figname) |
---|
95 | |
---|
96 | figure(3) |
---|
97 | plot(t, momentum, '-b', linewidth=1) |
---|
98 | xlabel('time (hour)') |
---|
99 | ylabel('momentum (m^2/sec)') |
---|
100 | axis(mom_axis) |
---|
101 | figname = 'mom_%s_%s.png' %(name,community) |
---|
102 | savefig(figname) |
---|
103 | |
---|
104 | close('all') |
---|
105 | """ |
---|
106 | hold(True) |
---|
107 | count = 0 |
---|
108 | figcount = 0 |
---|
109 | cstr = ['b', 'r'] |
---|
110 | |
---|
111 | filenames = [#directory + time_dir1 + sep + 'gauges_time_series_100m.csv', |
---|
112 | #directory + time_dir2 + sep + 'gauges_time_series_100m.csv'] |
---|
113 | #directory + time_dir1 + sep + 'gauges_time_series_50m.csv', |
---|
114 | #directory + time_dir2 + sep + 'gauges_time_series_50m.csv'] |
---|
115 | #directory + time_dir1 + sep + 'gauges_time_series_20m.csv', |
---|
116 | #directory + time_dir2 + sep + 'gauges_time_series_20m.csv'] |
---|
117 | #directory + time_dir1 + sep + 'gauges_time_series_3.5m.csv', |
---|
118 | #directory + time_dir2 + sep + 'gauges_time_series_3.5m.csv'] |
---|
119 | #directory + time_dir1 + sep + 'gauges_time_series_closetown1.csv', |
---|
120 | #directory + time_dir2 + sep + 'gauges_time_series_closetown1.csv'] |
---|
121 | directory + time_dir1 + sep + 'gauges_time_series_closetown2.csv', |
---|
122 | directory + time_dir2 + sep + 'gauges_time_series_closetown2.csv'] |
---|
123 | |
---|
124 | |
---|
125 | for i, filename in enumerate(filenames): |
---|
126 | t, stage, depth, speed, momentum = get_time_series_from_file(filename) |
---|
127 | |
---|
128 | i1 = filename.rfind('gauges') |
---|
129 | i2 = filename.rfind('csv') |
---|
130 | name = filename[i1:i2-1] |
---|
131 | loc = filename.rfind('1.5') + 4 |
---|
132 | if filename[loc] is 'o': community = 'onslow' |
---|
133 | if filename[loc] is 'e': community = 'exmouth' |
---|
134 | |
---|
135 | figure(10+figcount) |
---|
136 | plot(t, stage, c = cstr[i], linewidth=1) |
---|
137 | xlabel('time (hour)') |
---|
138 | ylabel('wave height (m)') |
---|
139 | axis(stage_axis) |
---|
140 | figname = 'stage_%s_both.png' %(name) |
---|
141 | savefig(figname) |
---|
142 | |
---|
143 | figure(20+figcount) |
---|
144 | plot(t, speed, c = cstr[i], linewidth=1) |
---|
145 | xlabel('time (hour)') |
---|
146 | ylabel('speed (m/s)') |
---|
147 | axis(speed_axis) |
---|
148 | figname = 'speed_%s_both.png' %(name) |
---|
149 | savefig(figname) |
---|
150 | |
---|
151 | figure(30+figcount) |
---|
152 | plot(t, momentum, c = cstr[i], linewidth=1) |
---|
153 | xlabel('time (hour)') |
---|
154 | ylabel('momentum (m^2/sec)') |
---|
155 | axis(mom_axis) |
---|
156 | figname = 'mom_%s_both.png' %(name) |
---|
157 | savefig(figname) |
---|
158 | |
---|
159 | count += 1 |
---|
160 | if int(count/2.) - count/2. is 0.0: figcount += 1 |
---|
161 | else: |
---|
162 | figcount = 0 |
---|
163 | |
---|
164 | close('all') |
---|