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, axis |
---|
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 | #axis([0,60,0.380,0.420]) |
---|
47 | |
---|
48 | if is_interactive: |
---|
49 | # Wait for enter pressed |
---|
50 | raw_input() |
---|
51 | |
---|
52 | if save_as is not None: |
---|
53 | savefig(save_as) |
---|
54 | |
---|
55 | #Need to close this plot |
---|
56 | close() |
---|
57 | |
---|
58 | def Hinwood_files_locations(run_data, outputdir_tag, plot_type, |
---|
59 | quantity = "depth"): |
---|
60 | """ |
---|
61 | run_data is a dictionary of data describing a Hinwood experiment |
---|
62 | outputdir_tag a string at the end of an output dir; '_good_tri_area_0.01_A' |
---|
63 | plot_type the file extension of the plot, eg '.pdf' |
---|
64 | """ |
---|
65 | id = run_data['scenario_id'] |
---|
66 | outputdir_name = id + outputdir_tag |
---|
67 | pro_instance = project.Project(['data','flumes','Hinwood_2008'], |
---|
68 | outputdir_name=outputdir_name) |
---|
69 | |
---|
70 | file_sim = pro_instance.outputdir + quantity + "_" + id + ".csv" |
---|
71 | #print "file_exp",file_exp |
---|
72 | file_exp = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_' \ |
---|
73 | + quantity + '.csv' |
---|
74 | #print "file_sim", file_sim |
---|
75 | location_sims = [] |
---|
76 | location_exps = [] |
---|
77 | save_as_list = [] |
---|
78 | for gauge_x in run_data['gauge_x']: |
---|
79 | gauge_x = str(gauge_x) |
---|
80 | location_sims.append(gauge_x + ':0.5') |
---|
81 | location_exps.append(gauge_x) |
---|
82 | save_as_list.append(pro_instance.plots_dir + sep + \ |
---|
83 | outputdir_name + "_" + quantity + "_" + \ |
---|
84 | gauge_x + plot_type) |
---|
85 | return file_exp, file_sim, location_sims, location_exps, outputdir_name, \ |
---|
86 | save_as_list |
---|
87 | def plot(scenarios, outputdir_tag, quantity = "stage"): |
---|
88 | plot_type = ".pdf" |
---|
89 | |
---|
90 | for run_data in scenarios: |
---|
91 | |
---|
92 | temp = Hinwood_files_locations(run_data, outputdir_tag, |
---|
93 | plot_type, quantity) |
---|
94 | |
---|
95 | file_exp, file_sim, location_sims, location_exps, outputdir_name, \ |
---|
96 | save_as_list = temp |
---|
97 | print "run_data['scenario_id']", run_data['scenario_id'] |
---|
98 | #location_sims = [location_sims[0]] |
---|
99 | #location_exps = [location_exps[0]] |
---|
100 | #save_as_list = [save_as_list[0]] |
---|
101 | for loc_sim, loc_exp, save_as, gauge in map(None, location_sims, |
---|
102 | location_exps, |
---|
103 | save_as_list, |
---|
104 | run_data['gauge_x']): |
---|
105 | time_date = strftime('plot date: %d/%m/%Y Time: %H:%M:%S', |
---|
106 | localtime()) |
---|
107 | plot_title = "Scenario: " + outputdir_name + "\n" + \ |
---|
108 | "X Gauge (m):" + str(gauge) + " " + time_date |
---|
109 | |
---|
110 | print "Doing ", plot_title |
---|
111 | plot_compare_csv(location_sim=loc_sim, |
---|
112 | file_sim=file_sim, |
---|
113 | location_exp=loc_exp, |
---|
114 | file_exp=file_exp, |
---|
115 | plot_title=plot_title, |
---|
116 | y_label='Water '+ quantity +' (m)', |
---|
117 | is_interactive=False, |
---|
118 | save_as=save_as) |
---|
119 | |
---|
120 | #------------------------------------------------------------- |
---|
121 | if __name__ == "__main__": |
---|
122 | """ Plot the stage graph for the ANUGA validation papar |
---|
123 | """ |
---|
124 | from scenarios import scenarios |
---|
125 | outputdir_tag = "_test_C" |
---|
126 | #scenarios = scenarios[1] |
---|
127 | #scenarios = [scenarios[5]] |
---|
128 | plot(scenarios, outputdir_tag) |
---|
129 | |
---|