1 | |
---|
2 | def plot_compare_csv(location_sim, file_sim, location_exp, file_exp, y_label, |
---|
3 | save_as=None, |
---|
4 | x_label='Time (s)', |
---|
5 | legend_sim='ANUGA simulation', |
---|
6 | legend_exp='Measured flume result', |
---|
7 | is_interactive=False): |
---|
8 | """ |
---|
9 | """ |
---|
10 | from pylab import ion, plot, xlabel, ylabel, close, legend, \ |
---|
11 | savefig |
---|
12 | from anuga.shallow_water.data_manager import csv2dict |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | # Load in the csv files and convert info from strings to floats |
---|
17 | simulation, _ = csv2dict(file_sim) |
---|
18 | experiment, _ = csv2dict(file_exp) |
---|
19 | time_sim = [float(x) for x in simulation['Time']] |
---|
20 | quantity_sim = [float(x) for x in simulation[location_sim]] |
---|
21 | #print "quantity_sim", quantity_sim |
---|
22 | time_exp = [float(x) for x in experiment['time']] |
---|
23 | quantity_exp = [float(x) for x in experiment[location_exp]] |
---|
24 | |
---|
25 | if is_interactive: |
---|
26 | ion() |
---|
27 | |
---|
28 | plot(time_sim, quantity_sim, time_exp, quantity_exp) |
---|
29 | |
---|
30 | # Add axis stuff and legend |
---|
31 | xlabel(x_label) |
---|
32 | ylabel(y_label) |
---|
33 | legend((legend_sim, legend_exp)) |
---|
34 | |
---|
35 | if is_interactive: |
---|
36 | # Wait for enter pressed |
---|
37 | raw_input() |
---|
38 | |
---|
39 | if save_as is not None: |
---|
40 | savefig(save_as) |
---|
41 | |
---|
42 | #Need to close this plot |
---|
43 | close() |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | #------------------------------------------------------------- |
---|
48 | if __name__ == "__main__": |
---|
49 | """ Plot the stage graph for the ANUGA validation papar |
---|
50 | """ |
---|
51 | |
---|
52 | import project |
---|
53 | import shutil |
---|
54 | from os import sep, path |
---|
55 | |
---|
56 | |
---|
57 | # T1R5 |
---|
58 | run_data = {'xleft':[-3.106,0.0], # Av' of ADV and Gauge A |
---|
59 | 'xtoe':[0.0,0.0], |
---|
60 | 'xbeach':[1.285,0.090], |
---|
61 | 'xright':[16.1,.960], |
---|
62 | 'offshore_water_depth':.4, |
---|
63 | 'scenario_id':'T1R5', |
---|
64 | 'gauge_names':['B','1','2','3','4','5','6','7','8', |
---|
65 | '9','10','11','12','13','14'], |
---|
66 | 'gauge_x':[-0.68, 1.572, 2.572, 3.572, 4.572, 5.572, |
---|
67 | 6.572, 7.572, 8.572, 9.572, 10.572, 11.572, |
---|
68 | 12.572, 13.572, 14.572], |
---|
69 | 'gauge_bed_elevation':[-0.400000, -0.293158, |
---|
70 | -0.234473, -0.175788, -0.117104, -0.058419, 0.000266, |
---|
71 | 0.058950, 0.117635, 0.176320, 0.235004, 0.293689, |
---|
72 | 0.352374, 0.411058, 0.469743] |
---|
73 | } |
---|
74 | id = run_data['scenario_id'] |
---|
75 | outputdir_name = id + "_test_long_time" |
---|
76 | pro_instance = project.Project(['data','flumes','Hinwood_2008'], |
---|
77 | outputdir_name=outputdir_name) |
---|
78 | |
---|
79 | file_exp = pro_instance.outputdir + "depth_" + id + ".csv" |
---|
80 | print "file_exp",file_exp |
---|
81 | file_sim = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_depth.csv' |
---|
82 | print "file_sim", file_sim |
---|
83 | location_sim = str(run_data['gauge_x'][0]) |
---|
84 | location_exp = str(run_data['gauge_x'][0]) + ':0.225' |
---|
85 | # create Depth plot |
---|
86 | plot_compare_csv(location_sim=location_sim, |
---|
87 | file_sim=file_sim, |
---|
88 | location_exp=location_exp, |
---|
89 | file_exp=file_exp, |
---|
90 | y_label='Water height (m)', |
---|
91 | is_interactive=True) |
---|
92 | #save_as="me.eps") |
---|
93 | |
---|