[5399] | 1 | |
---|
[5410] | 2 | """ |
---|
| 3 | Plot up files from the Hinwood project. |
---|
| 4 | """ |
---|
| 5 | from os import sep |
---|
| 6 | import project |
---|
[5426] | 7 | from time import localtime, strftime |
---|
[5410] | 8 | |
---|
| 9 | def 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, \ |
---|
[5455] | 21 | savefig, title, axis |
---|
[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 | |
---|
| 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) |
---|
[5410] | 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) |
---|
[5459] | 47 | if use_axis is not None: |
---|
| 48 | axis(use_axis) |
---|
[5399] | 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 | |
---|
[5455] | 60 | def 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 | """ |
---|
[5410] | 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 | |
---|
[5455] | 72 | file_sim = pro_instance.outputdir + quantity + "_" + id + ".csv" |
---|
[5410] | 73 | #print "file_exp",file_exp |
---|
[5455] | 74 | file_exp = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_' \ |
---|
| 75 | + quantity + '.csv' |
---|
[5410] | 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 + \ |
---|
[5455] | 85 | outputdir_name + "_" + quantity + "_" + \ |
---|
| 86 | gauge_x + plot_type) |
---|
[5410] | 87 | return file_exp, file_sim, location_sims, location_exps, outputdir_name, \ |
---|
| 88 | save_as_list |
---|
[5455] | 89 | def plot(scenarios, outputdir_tag, quantity = "stage"): |
---|
[5449] | 90 | plot_type = ".pdf" |
---|
[5455] | 91 | |
---|
[5449] | 92 | for run_data in scenarios: |
---|
| 93 | |
---|
[5455] | 94 | temp = Hinwood_files_locations(run_data, outputdir_tag, |
---|
| 95 | plot_type, quantity) |
---|
| 96 | |
---|
[5449] | 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 |
---|
[5459] | 111 | if gauge < run_data['axis_maximum_x']: |
---|
| 112 | use_axis = run_data['axis'] |
---|
| 113 | else: |
---|
| 114 | use_axis = None |
---|
[5449] | 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, |
---|
[5455] | 121 | y_label='Water '+ quantity +' (m)', |
---|
[5449] | 122 | is_interactive=False, |
---|
[5459] | 123 | save_as=save_as, |
---|
| 124 | use_axis=use_axis) |
---|
[5449] | 125 | |
---|
[5399] | 126 | #------------------------------------------------------------- |
---|
| 127 | if __name__ == "__main__": |
---|
| 128 | """ Plot the stage graph for the ANUGA validation papar |
---|
| 129 | """ |
---|
[5410] | 130 | from scenarios import scenarios |
---|
[5459] | 131 | outputdir_tag = "_good_tri_area_0.01_C" |
---|
| 132 | #scenarios = scenarios[1:] |
---|
[5455] | 133 | #scenarios = [scenarios[5]] |
---|
| 134 | plot(scenarios, outputdir_tag) |
---|
[5399] | 135 | |
---|