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

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

Current Hinwood - calc norm set up for _G end tag comparison

File size: 6.2 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                     x_axis=None,
18                     y_axis=None):
19    """
20    """
21    from pylab import ion, plot, xlabel, ylabel, close, legend, \
22         savefig, title, axis, setp
23    from anuga.shallow_water.data_manager import csv2dict
24
25
26
27    # Load in the csv files and convert info from strings to floats
28    simulation, _ = csv2dict(file_sim)
29    experiment, _ = csv2dict(file_exp)
30    time_sim = [float(x) for x in simulation['time']]
31    quantity_sim = [float(x) for x in simulation[location_sim]]
32    #print "quantity_sim", quantity_sim
33    time_exp = [float(x) for x in experiment['Time']]
34    quantity_exp = [float(x) for x in experiment[location_exp]]
35
36    if is_interactive:
37        ion()
38   
39    l_sim, l_exp = plot(time_sim, quantity_sim, time_exp, quantity_exp)
40    setp(l_sim, color='r')
41    setp(l_exp, color='b')
42
43    # Add axis stuff and legend
44    xlabel(x_label)
45    ylabel(y_label)
46    # The order defines the label
47    #legend((legend_exp, legend_sim),'upper left')
48    legend((legend_sim, legend_exp),'upper left')
49    title(plot_title)
50    if x_axis is not None:
51        axis(xmin=x_axis[0], xmax=x_axis[1])
52   
53    if y_axis is not None:
54        axis(ymin=y_axis[0], ymax=y_axis[1])
55       
56    if is_interactive:
57        # Wait for enter pressed
58        raw_input()
59
60    if save_as is not None:
61        savefig(save_as)
62   
63    #Need to close this plot
64    close()
65   
66def Hinwood_files_locations(run_data, outputdir_tag, plot_type,
67                            quantity = "depth",
68                            y_location_tag=':0.0'):
69    """
70    run_data is a dictionary of data describing a Hinwood experiment
71    outputdir_tag a string at the end of an output dir; '_good_tri_area_0.01_A'
72    plot_type the file extension of the plot, eg '.pdf'
73    """
74    id = run_data['scenario_id']
75    outputdir_name = id + outputdir_tag
76    pro_instance = project.Project(['data','flumes','Hinwood_2008'],
77                                   outputdir_name=outputdir_name)
78   
79   
80    file_sim = pro_instance.outputdir + quantity + "_" + id + ".csv"
81    #print "file_exp",file_exp
82    file_exp = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_' \
83               + quantity + '.csv'
84    #print "file_sim", file_sim
85    location_sims = []
86    location_exps = []
87    save_as_list = []
88    for gauge_x in run_data['gauge_x']:
89        gauge_x = str(gauge_x)
90        location_sims.append(gauge_x + y_location_tag)
91        location_exps.append(gauge_x)
92        save_as_list.append(pro_instance.plots_dir + sep + \
93                            outputdir_name + "_" + quantity + "_" + \
94                            gauge_x + plot_type)
95    return file_exp, file_sim, location_sims, location_exps, outputdir_name, \
96           save_as_list
97
98def plot(scenarios, outputdir_tag, quantity = "stage",is_interactive=False,
99         y_location_tag=':0.0'):
100    plot_type = ".pdf"
101   
102    for run_data in scenarios:
103       
104        temp = Hinwood_files_locations(run_data, outputdir_tag,
105                                       plot_type, quantity,
106                                       y_location_tag=y_location_tag)
107                                   
108        file_exp, file_sim, location_sims, location_exps, outputdir_name, \
109                  save_as_list = temp
110        print "file_exp",file_exp
111        print "run_data['scenario_id']", run_data['scenario_id']
112        #location_sims = [location_sims[0]]
113        #location_exps = [location_exps[0]]
114        #save_as_list = [save_as_list[0]]
115        for loc_sim, loc_exp, save_as, gauge, gauge_elev in \
116                map(None, location_sims,
117                    location_exps,
118                    save_as_list,
119                    run_data['gauge_x'],
120                    run_data['gauge_bed_elevation']):
121            time_date = strftime('plot date: %d/%m/%Y Time: %H:%M:%S',
122                                      localtime())
123            plot_title = "Scenario: " + outputdir_name + "\n" + \
124                         "X Gauge (m):" + str(gauge) + "    " + time_date
125
126            # When the shore gauges out of the are used, don't
127            # use the standard y axis scale
128            x_axis = run_data['wave_times']
129            if gauge < run_data['axis_maximum_x']:
130                y_axis = [run_data['axis'][2],run_data['axis'][3]]
131       
132            else:
133                y_axis = [run_data['axis'][2] + gauge_elev,
134                          run_data['axis'][3] + gauge_elev]
135            print "Doing ", plot_title
136            plot_compare_csv(location_sim=loc_sim,
137                             file_sim=file_sim,
138                             location_exp=loc_exp,
139                             file_exp=file_exp,
140                             plot_title=plot_title,
141                             y_label='Water '+ quantity +' (m)',
142                             is_interactive=is_interactive,
143                             save_as=save_as,
144                             x_axis=x_axis,
145                             y_axis=y_axis)
146            if is_interactive is True:
147                break
148   
149#-------------------------------------------------------------
150if __name__ == "__main__":
151    """ Plot the stage graph for the ANUGA validation papar
152    """
153    from scenarios import scenarios
154    outputdir_tag = "_good_tri_area_0.01_limiterE"
155    outputdir_tag = "_nolmts_wdth_0.1_z_0.012_ys_0.01_mta_0.01_H"
156    outputdir_tag = "_good_lmts_wdth_0.1_z_0.0_ys_0.01_mta_0.01_F"
157    outputdir_tag = "_nolmts_wdth_0.1_z_0.0_ys_0.01_mta_0.01_G"
158    #outputdir_tag = "_nolmts_wdth_0.01_z_0.012_ys_0.01_mta_1e-05_G"
159    #outputdir_tag = "_test_C"
160    #scenarios = scenarios[1:]
161    #scenarios = [scenarios[7]]
162    is_interactive = False
163    #is_interactive = True
164    plot(scenarios, outputdir_tag,is_interactive=is_interactive,
165         y_location_tag=':0.0')
166
Note: See TracBrowser for help on using the repository browser.