""" Plot up files from the Hinwood project. """ from os import sep import project from time import localtime, strftime def plot_compare_csv(location_sim, file_sim, location_exp, file_exp, y_label, save_as=None, plot_title="", x_label='Time (s)', legend_sim='ANUGA simulation', legend_exp='Measured flume result', is_interactive=False, use_axis=None): """ """ from pylab import ion, plot, xlabel, ylabel, close, legend, \ savefig, title, axis, setp from anuga.shallow_water.data_manager import csv2dict # Load in the csv files and convert info from strings to floats simulation, _ = csv2dict(file_sim) experiment, _ = csv2dict(file_exp) time_sim = [float(x) for x in simulation['time']] quantity_sim = [float(x) for x in simulation[location_sim]] #print "quantity_sim", quantity_sim time_exp = [float(x) for x in experiment['Time']] quantity_exp = [float(x) for x in experiment[location_exp]] if is_interactive: ion() l_sim, l_exp = plot(time_sim, quantity_sim, time_exp, quantity_exp) setp(l_sim, color='r') setp(l_exp, color='b') # Add axis stuff and legend xlabel(x_label) ylabel(y_label) # The order defines the label #legend((legend_exp, legend_sim),'upper left') legend((legend_sim, legend_exp),'upper left') title(plot_title) if use_axis is not None: axis(use_axis) if is_interactive: # Wait for enter pressed raw_input() if save_as is not None: savefig(save_as) #Need to close this plot close() def Hinwood_files_locations(run_data, outputdir_tag, plot_type, quantity = "depth", y_location_tag=':0.0'): """ run_data is a dictionary of data describing a Hinwood experiment outputdir_tag a string at the end of an output dir; '_good_tri_area_0.01_A' plot_type the file extension of the plot, eg '.pdf' """ id = run_data['scenario_id'] outputdir_name = id + outputdir_tag pro_instance = project.Project(['data','flumes','Hinwood_2008'], outputdir_name=outputdir_name) file_sim = pro_instance.outputdir + quantity + "_" + id + ".csv" #print "file_exp",file_exp file_exp = pro_instance.raw_data_dir + sep + id + 'pressfilt_exp_' \ + quantity + '.csv' #print "file_sim", file_sim location_sims = [] location_exps = [] save_as_list = [] for gauge_x in run_data['gauge_x']: gauge_x = str(gauge_x) location_sims.append(gauge_x + y_location_tag) location_exps.append(gauge_x) save_as_list.append(pro_instance.plots_dir + sep + \ outputdir_name + "_" + quantity + "_" + \ gauge_x + plot_type) return file_exp, file_sim, location_sims, location_exps, outputdir_name, \ save_as_list def plot(scenarios, outputdir_tag, quantity = "stage",is_interactive=False, y_location_tag=':0.0'): plot_type = ".pdf" for run_data in scenarios: temp = Hinwood_files_locations(run_data, outputdir_tag, plot_type, quantity, y_location_tag=y_location_tag) file_exp, file_sim, location_sims, location_exps, outputdir_name, \ save_as_list = temp print "file_exp",file_exp print "run_data['scenario_id']", run_data['scenario_id'] #location_sims = [location_sims[0]] #location_exps = [location_exps[0]] #save_as_list = [save_as_list[0]] for loc_sim, loc_exp, save_as, gauge in map(None, location_sims, location_exps, save_as_list, run_data['gauge_x']): time_date = strftime('plot date: %d/%m/%Y Time: %H:%M:%S', localtime()) plot_title = "Scenario: " + outputdir_name + "\n" + \ "X Gauge (m):" + str(gauge) + " " + time_date if gauge < run_data['axis_maximum_x']: use_axis = run_data['axis'] else: use_axis = None print "Doing ", plot_title plot_compare_csv(location_sim=loc_sim, file_sim=file_sim, location_exp=loc_exp, file_exp=file_exp, plot_title=plot_title, y_label='Water '+ quantity +' (m)', is_interactive=is_interactive, save_as=save_as, use_axis=use_axis) if is_interactive is True: break #------------------------------------------------------------- if __name__ == "__main__": """ Plot the stage graph for the ANUGA validation papar """ from scenarios import scenarios outputdir_tag = "_good_tri_area_0.01_limiterE" outputdir_tag = "_nolmts_wdth_0.1_z_0.012_ys_0.01_mta_0.01_H" outputdir_tag = "_good_lmts_wdth_0.1_z_0.0_ys_0.01_mta_0.01_F" outputdir_tag = "_nolmts_wdth_0.1_z_0.0_ys_0.01_mta_0.01_G" #outputdir_tag = "_nolmts_wdth_0.01_z_0.012_ys_0.01_mta_1e-05_G" #outputdir_tag = "_test_C" #scenarios = scenarios[1:] #scenarios = [scenarios[4]] is_interactive = False #is_interactive = True plot(scenarios, outputdir_tag,is_interactive=is_interactive, y_location_tag=':0.0')