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

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

Current Hinwood - Removed sensor 8 from last 4 runs

File size: 5.8 KB
RevLine 
[5399]1
[5410]2"""
3Plot up files from the Hinwood project.
4"""
5from os import sep
6import project
[5426]7from time import localtime, strftime
[5410]8
9def plot_compare_csv(location_sim, file_sim, location_exp, file_exp,
10                     y_label,
[5399]11                     save_as=None,
[5410]12                     plot_title="",
[5399]13                     x_label='Time (s)',
14                     legend_sim='ANUGA simulation',
15                     legend_exp='Measured flume result',
[5459]16                     is_interactive=False,
17                     use_axis=None):
[5399]18    """
19    """
20    from pylab import ion, plot, xlabel, ylabel, close, legend, \
[5494]21         savefig, title, axis, setp
[5399]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)
[5410]29    time_sim = [float(x) for x in simulation['time']]
[5399]30    quantity_sim = [float(x) for x in simulation[location_sim]]
31    #print "quantity_sim", quantity_sim
[5410]32    time_exp = [float(x) for x in experiment['Time']]
[5399]33    quantity_exp = [float(x) for x in experiment[location_exp]]
34
35    if is_interactive:
36        ion()
37   
[5494]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')
[5399]41
42    # Add axis stuff and legend
43    xlabel(x_label)
44    ylabel(y_label)
[5410]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)
[5459]49    if use_axis is not None:
50        axis(use_axis)
[5399]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   
[5455]62def Hinwood_files_locations(run_data, outputdir_tag, plot_type,
[5616]63                            quantity = "depth",
64                            y_location_tag=':0.0'):
[5455]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    """
[5410]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   
[5494]75   
[5455]76    file_sim = pro_instance.outputdir + quantity + "_" + id + ".csv"
[5410]77    #print "file_exp",file_exp
[5455]78    file_exp = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_' \
79               + quantity + '.csv'
[5410]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)
[5616]86        location_sims.append(gauge_x + y_location_tag)
[5410]87        location_exps.append(gauge_x)
88        save_as_list.append(pro_instance.plots_dir + sep + \
[5455]89                            outputdir_name + "_" + quantity + "_" + \
90                            gauge_x + plot_type)
[5410]91    return file_exp, file_sim, location_sims, location_exps, outputdir_name, \
92           save_as_list
[5616]93
94def plot(scenarios, outputdir_tag, quantity = "stage",is_interactive=False,
95         y_location_tag=':0.0'):
[5449]96    plot_type = ".pdf"
[5455]97   
[5449]98    for run_data in scenarios:
99       
[5455]100        temp = Hinwood_files_locations(run_data, outputdir_tag,
[5616]101                                       plot_type, quantity,
102                                       y_location_tag=y_location_tag)
[5455]103                                   
[5449]104        file_exp, file_sim, location_sims, location_exps, outputdir_name, \
105                  save_as_list = temp
[5616]106        print "file_exp",file_exp
[5449]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
[5459]119            if gauge < run_data['axis_maximum_x']:
120                use_axis = run_data['axis']
121            else:
122                use_axis = None
[5449]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,
[5455]129                             y_label='Water '+ quantity +' (m)',
[5494]130                             is_interactive=is_interactive,
[5459]131                             save_as=save_as,
132                             use_axis=use_axis)
[5494]133            if is_interactive is True:
134                break
[5449]135   
[5399]136#-------------------------------------------------------------
137if __name__ == "__main__":
138    """ Plot the stage graph for the ANUGA validation papar
139    """
[5410]140    from scenarios import scenarios
[5577]141    outputdir_tag = "_good_tri_area_0.01_limiterE"
[5616]142    outputdir_tag = "_nolmts_wdth_0.1_z_0.012_ys_0.01_mta_0.01_H"
[5659]143    outputdir_tag = "_good_lmts_wdth_0.1_z_0.0_ys_0.01_mta_0.01_F"
144    outputdir_tag = "_nolmts_wdth_0.1_z_0.0_ys_0.01_mta_0.01_G"
[5595]145    #outputdir_tag = "_nolmts_wdth_0.01_z_0.012_ys_0.01_mta_1e-05_G"
[5494]146    #outputdir_tag = "_test_C"
[5459]147    #scenarios = scenarios[1:]
[5616]148    #scenarios = [scenarios[4]]
[5494]149    is_interactive = False
150    #is_interactive = True
[5616]151    plot(scenarios, outputdir_tag,is_interactive=is_interactive,
[5659]152         y_location_tag=':0.0')
[5399]153
Note: See TracBrowser for help on using the repository browser.