1 | |
---|
2 | def plot_compare_csv(location, file_sim, |
---|
3 | file_exp, y_label,file_sim2=None, |
---|
4 | save_as=None, |
---|
5 | x_label='Time (s)', |
---|
6 | legend_sim='ANUGA simulation', |
---|
7 | legend_sim2=None, |
---|
8 | legend_exp='Measured flume result', |
---|
9 | is_interactive=False): |
---|
10 | """ |
---|
11 | """ |
---|
12 | from pylab import ion, plot, xlabel, ylabel, close, legend, \ |
---|
13 | savefig |
---|
14 | from anuga.shallow_water.data_manager import csv2dict |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | # Load in the csv files and convert info from strings to floats |
---|
19 | simulation, _ = csv2dict(file_sim) |
---|
20 | time_sim = [float(x) for x in simulation['time']] |
---|
21 | quantity_sim = [float(x) for x in simulation[location]] |
---|
22 | |
---|
23 | |
---|
24 | experiment, _ = csv2dict(file_exp) |
---|
25 | time_exp = [float(x) for x in experiment['time']] |
---|
26 | quantity_exp = [float(x) for x in experiment[location]] |
---|
27 | |
---|
28 | if file_sim2 is not None: |
---|
29 | simulation2, _ = csv2dict(file_sim2) |
---|
30 | time_sim2 = [float(x) for x in simulation2['time']] |
---|
31 | quantity_sim2 = [float(x) for x in simulation2[location]] |
---|
32 | |
---|
33 | |
---|
34 | if is_interactive: |
---|
35 | ion() |
---|
36 | |
---|
37 | if file_sim2 is None: |
---|
38 | plot(time_sim, quantity_sim, time_exp, quantity_exp) |
---|
39 | else: |
---|
40 | plot(time_sim, quantity_sim, time_sim2, quantity_sim2, |
---|
41 | time_exp, quantity_exp, ) |
---|
42 | |
---|
43 | |
---|
44 | # Add axis stuff and legend |
---|
45 | xlabel(x_label) |
---|
46 | ylabel(y_label) |
---|
47 | if legend_sim2 is None: |
---|
48 | legend((legend_sim, legend_exp)) |
---|
49 | else: |
---|
50 | legend((legend_sim, legend_sim2, legend_exp)) |
---|
51 | |
---|
52 | |
---|
53 | if is_interactive: |
---|
54 | # Wait for enter pressed |
---|
55 | raw_input() |
---|
56 | |
---|
57 | if save_as is not None: |
---|
58 | savefig(save_as) |
---|
59 | |
---|
60 | #Need to close this plot |
---|
61 | close() |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | #------------------------------------------------------------- |
---|
66 | if __name__ == "__main__": |
---|
67 | """ Plot the stage graph for the ANUGA validation papar |
---|
68 | """ |
---|
69 | |
---|
70 | import project |
---|
71 | import shutil |
---|
72 | from os import sep, path |
---|
73 | |
---|
74 | depth_file = "uq-friction-depth.eps" |
---|
75 | |
---|
76 | # create Depth plot |
---|
77 | plot_compare_csv(location='0.4:0.2', # testing location |
---|
78 | file_sim=project.depth_filename, |
---|
79 | file_sim2=project.depth_filename2, |
---|
80 | file_exp=project.experiment_depth_filename, |
---|
81 | legend_sim="ANUGA, Manning's friction 0.0", |
---|
82 | legend_sim2="ANUGA, Manning's friction 0.01", |
---|
83 | y_label='Water height (m)', |
---|
84 | save_as=depth_file) |
---|
85 | |
---|
86 | #import sys; sys.exit() |
---|
87 | # Move the files to the dir where the paper is being put together |
---|
88 | paper_dir = path.join('..','..','anuga_work','publications','anuga_2007') |
---|
89 | dest = path.join(paper_dir, depth_file) |
---|
90 | shutil.copyfile(depth_file,dest) |
---|