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 = '20070419_065050_run'# HAT dampier |
---|
10 | directory = project.output_dir |
---|
11 | filenames = [directory + time_dir1 + sep + 'gauges_time_series_p12.csv', |
---|
12 | directory + time_dir1 + sep + 'gauges_time_series_p13.csv', |
---|
13 | directory + time_dir1 + sep + 'gauges_time_series_p14.csv', |
---|
14 | directory + time_dir1 + sep + 'gauges_time_series_p15.csv', |
---|
15 | directory + time_dir1 + sep + 'gauges_time_series_p20.csv', |
---|
16 | directory + time_dir1 + sep + 'gauges_time_series_p21.csv', |
---|
17 | directory + time_dir1 + sep + 'gauges_time_series_p22.csv', |
---|
18 | directory + time_dir1 + sep + 'gauges_time_series_p23.csv'] |
---|
19 | |
---|
20 | def get_time_series_from_file(filename): |
---|
21 | fid = open(filename) |
---|
22 | lines = fid.readlines() |
---|
23 | fid.close() |
---|
24 | |
---|
25 | t = [] |
---|
26 | stage = [] |
---|
27 | depth = [] |
---|
28 | speed = [] |
---|
29 | momentum = [] |
---|
30 | for line in lines[1:]: |
---|
31 | fields = line.split(',') |
---|
32 | t.append((float(fields[0])/3600.0+4000./3600.)) # 4000 for Dampier run |
---|
33 | stage.append(float(fields[1])) |
---|
34 | depth.append(float(fields[1])-float(fields[4])) |
---|
35 | speed.append(float(fields[3])) |
---|
36 | momentum.append(float(fields[2])) |
---|
37 | return t, stage, depth, speed, momentum |
---|
38 | |
---|
39 | max_st = 0. |
---|
40 | max_sp = 0. |
---|
41 | max_mom = 0. |
---|
42 | min_st = 0. |
---|
43 | min_sp = 0. |
---|
44 | min_mom = 0. |
---|
45 | max_t = 0.0 |
---|
46 | |
---|
47 | for filename in filenames: |
---|
48 | t, stage, depth, speed, momentum = get_time_series_from_file(filename) |
---|
49 | if max(t) > max_t: max_t = max(t) |
---|
50 | if max(stage) > max_st: max_st = max(stage) |
---|
51 | if max(speed) > max_sp: max_sp = max(speed) |
---|
52 | if max(momentum) > max_mom: max_mom = max(momentum) |
---|
53 | if min(stage) < min_st: min_st = min(stage) |
---|
54 | if min(speed) < min_sp: min_sp = min(speed) |
---|
55 | if min(momentum) < min_mom: min_mom = min(momentum) |
---|
56 | |
---|
57 | #stage_axis = ([5000./3600.,max_t, min_st, max_st]) |
---|
58 | #speed_axis = ([5000/3600.,max_t, min_sp, max_sp]) |
---|
59 | #mom_axis = ([5000/3600.,max_t, min_mom, max_mom]) |
---|
60 | |
---|
61 | stage_axis = ([5000./3600.,max_t, -2.5,6.5]) |
---|
62 | |
---|
63 | ion() |
---|
64 | |
---|
65 | hold(False) |
---|
66 | |
---|
67 | for i, filename in enumerate(filenames): |
---|
68 | t, stage, depth, speed, momentum = get_time_series_from_file(filename) |
---|
69 | |
---|
70 | i1 = filename.rfind('gauges') |
---|
71 | i2 = filename.rfind('csv') |
---|
72 | name = filename[i1:i2-1] |
---|
73 | |
---|
74 | community = 'dampier' |
---|
75 | figure(1) |
---|
76 | plot(t, stage, '-b', linewidth=1) |
---|
77 | xlabel('time (hour)') |
---|
78 | ylabel('wave height (m)') |
---|
79 | axis(stage_axis) |
---|
80 | figname = 'stage_%s_%s.png' %(name,community) |
---|
81 | savefig(figname) |
---|
82 | |
---|
83 | |
---|
84 | close('all') |
---|
85 | |
---|