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

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

Current Hinwood scenario

File size: 5.7 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                            y_location_tag=':0.0'):
65    """
66    run_data is a dictionary of data describing a Hinwood experiment
67    outputdir_tag a string at the end of an output dir; '_good_tri_area_0.01_A'
68    plot_type the file extension of the plot, eg '.pdf'
69    """
70    id = run_data['scenario_id']
71    outputdir_name = id + outputdir_tag
72    pro_instance = project.Project(['data','flumes','Hinwood_2008'],
73                                   outputdir_name=outputdir_name)
74   
75   
76    file_sim = pro_instance.outputdir + quantity + "_" + id + ".csv"
77    #print "file_exp",file_exp
78    file_exp = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_' \
79               + quantity + '.csv'
80    #print "file_sim", file_sim
81    location_sims = []
82    location_exps = []
83    save_as_list = []
84    for gauge_x in run_data['gauge_x']:
85        gauge_x = str(gauge_x)
86        location_sims.append(gauge_x + y_location_tag)
87        location_exps.append(gauge_x)
88        save_as_list.append(pro_instance.plots_dir + sep + \
89                            outputdir_name + "_" + quantity + "_" + \
90                            gauge_x + plot_type)
91    return file_exp, file_sim, location_sims, location_exps, outputdir_name, \
92           save_as_list
93
94def plot(scenarios, outputdir_tag, quantity = "stage",is_interactive=False,
95         y_location_tag=':0.0'):
96    plot_type = ".pdf"
97   
98    for run_data in scenarios:
99       
100        temp = Hinwood_files_locations(run_data, outputdir_tag,
101                                       plot_type, quantity,
102                                       y_location_tag=y_location_tag)
103                                   
104        file_exp, file_sim, location_sims, location_exps, outputdir_name, \
105                  save_as_list = temp
106        print "file_exp",file_exp
107        print "run_data['scenario_id']", run_data['scenario_id']
108        #location_sims = [location_sims[0]]
109        #location_exps = [location_exps[0]]
110        #save_as_list = [save_as_list[0]]
111        for loc_sim, loc_exp, save_as, gauge in map(None, location_sims,
112                                                    location_exps,
113                                                    save_as_list,
114                                                    run_data['gauge_x']):
115            time_date = strftime('plot date: %d/%m/%Y Time: %H:%M:%S',
116                                      localtime())
117            plot_title = "Scenario: " + outputdir_name + "\n" + \
118                         "X Gauge (m):" + str(gauge) + "    " + time_date
119            if gauge < run_data['axis_maximum_x']:
120                use_axis = run_data['axis']
121            else:
122                use_axis = None
123            print "Doing ", plot_title
124            plot_compare_csv(location_sim=loc_sim,
125                             file_sim=file_sim,
126                             location_exp=loc_exp,
127                             file_exp=file_exp,
128                             plot_title=plot_title,
129                             y_label='Water '+ quantity +' (m)',
130                             is_interactive=is_interactive,
131                             save_as=save_as,
132                             use_axis=use_axis)
133            if is_interactive is True:
134                break
135   
136#-------------------------------------------------------------
137if __name__ == "__main__":
138    """ Plot the stage graph for the ANUGA validation papar
139    """
140    from scenarios import scenarios
141    outputdir_tag = "_good_tri_area_0.01_limiterE"
142    outputdir_tag = ""
143    outputdir_tag = "_nolmts_wdth_0.1_z_0.012_ys_0.01_mta_0.01_H"
144    outputdir_tag = "_good_tri_area_0.01_D"
145    #outputdir_tag = "_nolmts_wdth_0.01_z_0.012_ys_0.01_mta_1e-05_G"
146    #outputdir_tag = "_test_C"
147    #scenarios = scenarios[1:]
148    #scenarios = [scenarios[4]]
149    is_interactive = False
150    #is_interactive = True
151    plot(scenarios, outputdir_tag,is_interactive=is_interactive,
152         y_location_tag=':0.5')
153
Note: See TracBrowser for help on using the repository browser.