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

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

Current Hinwood scenario

File size: 4.3 KB
Line 
1
2"""
3Plot up files from the Hinwood project.
4"""
5from os import sep
6import project
7from time import localtime, strftime
8
9def 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   
57def 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
80#-------------------------------------------------------------
81if __name__ == "__main__":
82    """ Plot the stage graph for the ANUGA validation papar
83    """
84    from scenarios import scenarios
85    outputdir_tag = "_good_tri_area_0.01_A"
86    #scenarios = scenarios[1] # !!!!!!!!!!!!!!!!!!!!!!
87    scenarios = [scenarios[5]] # !!!!!!!!!!!!!!!!!!!!!!
88    # Supported formats: emf, eps, pdf, png, ps, raw, rgba, svg, svgz.
89    plot_type = ".pdf"
90    for run_data in scenarios:
91       
92        temp = Hinwood_files_locations(run_data, outputdir_tag, plot_type)
93        file_exp, file_sim, location_sims, location_exps, outputdir_name, \
94                  save_as_list = temp
95        print "run_data['scenario_id']", run_data['scenario_id']
96        #location_sims = [location_sims[0]]
97        #location_exps = [location_exps[0]]
98        #save_as_list = [save_as_list[0]]
99        for loc_sim, loc_exp, save_as, gauge in map(None, location_sims,
100                                                    location_exps,
101                                                    save_as_list,
102                                                    run_data['gauge_x']):
103            time_date = strftime('plot date: %d/%m/%Y Time: %H:%M:%S',
104                                      localtime())
105            plot_title = "Scenario: " + outputdir_name + "\n" + \
106                         "X Gauge (m):" + str(gauge) + "    " + time_date
107                         
108            print "Doing ", plot_title
109            plot_compare_csv(location_sim=loc_sim,
110                             file_sim=file_sim,
111                             location_exp=loc_exp,
112                             file_exp=file_exp,
113                             plot_title=plot_title,
114                             y_label='Water height (m)',
115                             is_interactive=False,
116                             save_as=save_as)
117
Note: See TracBrowser for help on using the repository browser.