source: anuga_work/production/onslow_2006/boundary_plot.py @ 6741

Last change on this file since 6741 was 4613, checked in by nick, 18 years ago

update onslow

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