source: anuga_work/development/Hinwood_2008/plot.py @ 5413

Last change on this file since 5413 was 5413, checked in by duncan, 16 years ago

Current Hinwood scenario

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