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

Last change on this file since 5494 was 5494, checked in by duncan, 15 years ago

Current Hinwood scenario - added plotting of froude number

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