1 | |
---|
2 | """ |
---|
3 | Plot up files from the Hinwood project. |
---|
4 | """ |
---|
5 | from os import sep |
---|
6 | import project |
---|
7 | from time import localtime, strftime |
---|
8 | |
---|
9 | def plot_compare_csv(location_sim, file_sim, location_exp, file_exp, |
---|
10 | y_label, |
---|
11 | save_as=None, |
---|
12 | plot_title="", |
---|
13 | x_label='Time (s)', |
---|
14 | legend_sim='ANUGA simulation', |
---|
15 | legend_exp='Measured flume result', |
---|
16 | is_interactive=False): |
---|
17 | """ |
---|
18 | """ |
---|
19 | from pylab import ion, plot, xlabel, ylabel, close, legend, \ |
---|
20 | savefig, title |
---|
21 | from anuga.shallow_water.data_manager import csv2dict |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | # Load in the csv files and convert info from strings to floats |
---|
26 | simulation, _ = csv2dict(file_sim) |
---|
27 | experiment, _ = csv2dict(file_exp) |
---|
28 | time_sim = [float(x) for x in simulation['time']] |
---|
29 | quantity_sim = [float(x) for x in simulation[location_sim]] |
---|
30 | #print "quantity_sim", quantity_sim |
---|
31 | time_exp = [float(x) for x in experiment['Time']] |
---|
32 | quantity_exp = [float(x) for x in experiment[location_exp]] |
---|
33 | |
---|
34 | if is_interactive: |
---|
35 | ion() |
---|
36 | |
---|
37 | plot(time_sim, quantity_sim, time_exp, quantity_exp) |
---|
38 | |
---|
39 | # Add axis stuff and legend |
---|
40 | xlabel(x_label) |
---|
41 | ylabel(y_label) |
---|
42 | # The order defines the label |
---|
43 | #legend((legend_exp, legend_sim),'upper left') |
---|
44 | legend((legend_sim, legend_exp),'upper left') |
---|
45 | title(plot_title) |
---|
46 | |
---|
47 | if is_interactive: |
---|
48 | # Wait for enter pressed |
---|
49 | raw_input() |
---|
50 | |
---|
51 | if save_as is not None: |
---|
52 | savefig(save_as) |
---|
53 | |
---|
54 | #Need to close this plot |
---|
55 | close() |
---|
56 | |
---|
57 | def Hinwood_files_locations(run_data, outputdir_tag, plot_type): |
---|
58 | |
---|
59 | id = run_data['scenario_id'] |
---|
60 | outputdir_name = id + outputdir_tag |
---|
61 | pro_instance = project.Project(['data','flumes','Hinwood_2008'], |
---|
62 | outputdir_name=outputdir_name) |
---|
63 | |
---|
64 | file_sim = pro_instance.outputdir + "depth_" + id + ".csv" |
---|
65 | #print "file_exp",file_exp |
---|
66 | file_exp = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_depth.csv' |
---|
67 | #print "file_sim", file_sim |
---|
68 | location_sims = [] |
---|
69 | location_exps = [] |
---|
70 | save_as_list = [] |
---|
71 | for gauge_x in run_data['gauge_x']: |
---|
72 | gauge_x = str(gauge_x) |
---|
73 | location_sims.append(gauge_x + ':0.5') |
---|
74 | location_exps.append(gauge_x) |
---|
75 | save_as_list.append(pro_instance.plots_dir + sep + \ |
---|
76 | outputdir_name + "_" + gauge_x + plot_type) |
---|
77 | return file_exp, file_sim, location_sims, location_exps, outputdir_name, \ |
---|
78 | save_as_list |
---|
79 | def plot(): |
---|
80 | from scenarios import scenarios |
---|
81 | outputdir_tag = "_good_tri_area_0.01_A" |
---|
82 | outputdir_tag = "_test" |
---|
83 | #scenarios = scenarios[1] # !!!!!!!!!!!!!!!!!!!!!! |
---|
84 | #scenarios = [scenarios[5]] # !!!!!!!!!!!!!!!!!!!!!! |
---|
85 | # Supported formats: emf, eps, pdf, png, ps, raw, rgba, svg, svgz. |
---|
86 | plot_type = ".pdf" |
---|
87 | for run_data in scenarios: |
---|
88 | |
---|
89 | temp = Hinwood_files_locations(run_data, outputdir_tag, plot_type) |
---|
90 | file_exp, file_sim, location_sims, location_exps, outputdir_name, \ |
---|
91 | save_as_list = temp |
---|
92 | print "run_data['scenario_id']", run_data['scenario_id'] |
---|
93 | #location_sims = [location_sims[0]] |
---|
94 | #location_exps = [location_exps[0]] |
---|
95 | #save_as_list = [save_as_list[0]] |
---|
96 | for loc_sim, loc_exp, save_as, gauge in map(None, location_sims, |
---|
97 | location_exps, |
---|
98 | save_as_list, |
---|
99 | run_data['gauge_x']): |
---|
100 | time_date = strftime('plot date: %d/%m/%Y Time: %H:%M:%S', |
---|
101 | localtime()) |
---|
102 | plot_title = "Scenario: " + outputdir_name + "\n" + \ |
---|
103 | "X Gauge (m):" + str(gauge) + " " + time_date |
---|
104 | |
---|
105 | print "Doing ", plot_title |
---|
106 | plot_compare_csv(location_sim=loc_sim, |
---|
107 | file_sim=file_sim, |
---|
108 | location_exp=loc_exp, |
---|
109 | file_exp=file_exp, |
---|
110 | plot_title=plot_title, |
---|
111 | y_label='Water height (m)', |
---|
112 | is_interactive=False, |
---|
113 | save_as=save_as) |
---|
114 | |
---|
115 | #------------------------------------------------------------- |
---|
116 | if __name__ == "__main__": |
---|
117 | """ Plot the stage graph for the ANUGA validation papar |
---|
118 | """ |
---|
119 | from scenarios import scenarios |
---|
120 | outputdir_tag = "_good_tri_area_0.01_A" |
---|
121 | #scenarios = scenarios[1] # !!!!!!!!!!!!!!!!!!!!!! |
---|
122 | scenarios = [scenarios[5]] # !!!!!!!!!!!!!!!!!!!!!! |
---|
123 | # Supported formats: emf, eps, pdf, png, ps, raw, rgba, svg, svgz. |
---|
124 | plot_type = ".pdf" |
---|
125 | for run_data in scenarios: |
---|
126 | |
---|
127 | temp = Hinwood_files_locations(run_data, outputdir_tag, plot_type) |
---|
128 | file_exp, file_sim, location_sims, location_exps, outputdir_name, \ |
---|
129 | save_as_list = temp |
---|
130 | print "run_data['scenario_id']", run_data['scenario_id'] |
---|
131 | #location_sims = [location_sims[0]] |
---|
132 | #location_exps = [location_exps[0]] |
---|
133 | #save_as_list = [save_as_list[0]] |
---|
134 | for loc_sim, loc_exp, save_as, gauge in map(None, location_sims, |
---|
135 | location_exps, |
---|
136 | save_as_list, |
---|
137 | run_data['gauge_x']): |
---|
138 | time_date = strftime('plot date: %d/%m/%Y Time: %H:%M:%S', |
---|
139 | localtime()) |
---|
140 | plot_title = "Scenario: " + outputdir_name + "\n" + \ |
---|
141 | "X Gauge (m):" + str(gauge) + " " + time_date |
---|
142 | |
---|
143 | print "Doing ", plot_title |
---|
144 | plot_compare_csv(location_sim=loc_sim, |
---|
145 | file_sim=file_sim, |
---|
146 | location_exp=loc_exp, |
---|
147 | file_exp=file_exp, |
---|
148 | plot_title=plot_title, |
---|
149 | y_label='Water height (m)', |
---|
150 | is_interactive=False, |
---|
151 | save_as=save_as) |
---|
152 | |
---|