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

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

Current Hinwood scenario

File size: 5.0 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                     use_axis=None):
18    """
19    """
20    from pylab import ion, plot, xlabel, ylabel, close, legend, \
21         savefig, title, axis
22    from anuga.shallow_water.data_manager import csv2dict
23
24
25
26    # Load in the csv files and convert info from strings to floats
27    simulation, _ = csv2dict(file_sim)
28    experiment, _ = csv2dict(file_exp)
29    time_sim = [float(x) for x in simulation['time']]
30    quantity_sim = [float(x) for x in simulation[location_sim]]
31    #print "quantity_sim", quantity_sim
32    time_exp = [float(x) for x in experiment['Time']]
33    quantity_exp = [float(x) for x in experiment[location_exp]]
34
35    if is_interactive:
36        ion()
37   
38    plot(time_sim, quantity_sim, time_exp, quantity_exp)
39
40    # Add axis stuff and legend
41    xlabel(x_label)
42    ylabel(y_label)
43    # The order defines the label
44    #legend((legend_exp, legend_sim),'upper left')
45    legend((legend_sim, legend_exp),'upper left')
46    title(plot_title)
47    if use_axis is not None:
48        axis(use_axis)
49   
50    if is_interactive:
51        # Wait for enter pressed
52        raw_input()
53
54    if save_as is not None:
55        savefig(save_as)
56   
57    #Need to close this plot
58    close()
59   
60def Hinwood_files_locations(run_data, outputdir_tag, plot_type,
61                            quantity = "depth"):
62    """
63    run_data is a dictionary of data describing a Hinwood experiment
64    outputdir_tag a string at the end of an output dir; '_good_tri_area_0.01_A'
65    plot_type the file extension of the plot, eg '.pdf'
66    """
67    id = run_data['scenario_id']
68    outputdir_name = id + outputdir_tag
69    pro_instance = project.Project(['data','flumes','Hinwood_2008'],
70                                   outputdir_name=outputdir_name)
71   
72    file_sim = pro_instance.outputdir + quantity + "_" + id + ".csv"
73    #print "file_exp",file_exp
74    file_exp = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_' \
75               + quantity + '.csv'
76    #print "file_sim", file_sim
77    location_sims = []
78    location_exps = []
79    save_as_list = []
80    for gauge_x in run_data['gauge_x']:
81        gauge_x = str(gauge_x)
82        location_sims.append(gauge_x + ':0.5')
83        location_exps.append(gauge_x)
84        save_as_list.append(pro_instance.plots_dir + sep + \
85                            outputdir_name + "_" + quantity + "_" + \
86                            gauge_x + plot_type)
87    return file_exp, file_sim, location_sims, location_exps, outputdir_name, \
88           save_as_list
89def plot(scenarios, outputdir_tag, quantity = "stage"):
90    plot_type = ".pdf"
91   
92    for run_data in scenarios:
93       
94        temp = Hinwood_files_locations(run_data, outputdir_tag,
95                                       plot_type, quantity)
96                                   
97        file_exp, file_sim, location_sims, location_exps, outputdir_name, \
98                  save_as_list = temp
99        print "run_data['scenario_id']", run_data['scenario_id']
100        #location_sims = [location_sims[0]]
101        #location_exps = [location_exps[0]]
102        #save_as_list = [save_as_list[0]]
103        for loc_sim, loc_exp, save_as, gauge in map(None, location_sims,
104                                                    location_exps,
105                                                    save_as_list,
106                                                    run_data['gauge_x']):
107            time_date = strftime('plot date: %d/%m/%Y Time: %H:%M:%S',
108                                      localtime())
109            plot_title = "Scenario: " + outputdir_name + "\n" + \
110                         "X Gauge (m):" + str(gauge) + "    " + time_date
111            if gauge < run_data['axis_maximum_x']:
112                use_axis = run_data['axis']
113            else:
114                use_axis = None
115            print "Doing ", plot_title
116            plot_compare_csv(location_sim=loc_sim,
117                             file_sim=file_sim,
118                             location_exp=loc_exp,
119                             file_exp=file_exp,
120                             plot_title=plot_title,
121                             y_label='Water '+ quantity +' (m)',
122                             is_interactive=False,
123                             save_as=save_as,
124                             use_axis=use_axis)
125   
126#-------------------------------------------------------------
127if __name__ == "__main__":
128    """ Plot the stage graph for the ANUGA validation papar
129    """
130    from scenarios import scenarios
131    outputdir_tag = "_good_tri_area_0.01_C"
132    #scenarios = scenarios[1:]
133    #scenarios = [scenarios[5]]
134    plot(scenarios, outputdir_tag)
135
Note: See TracBrowser for help on using the repository browser.