def plot_compare_csv(location, file_sim, file_exp, y_label,file_sim2=None, save_as=None, x_label='Time (s)', legend_sim='ANUGA simulation', legend_sim2=None, legend_exp='Measured flume result', is_interactive=False): """ """ from pylab import ion, plot, xlabel, ylabel, close, legend, \ savefig from anuga.shallow_water.data_manager import csv2dict # Load in the csv files and convert info from strings to floats simulation, _ = csv2dict(file_sim) time_sim = [float(x) for x in simulation['time']] quantity_sim = [float(x) for x in simulation[location]] experiment, _ = csv2dict(file_exp) time_exp = [float(x) for x in experiment['time']] quantity_exp = [float(x) for x in experiment[location]] if file_sim2 is not None: simulation2, _ = csv2dict(file_sim2) time_sim2 = [float(x) for x in simulation2['time']] quantity_sim2 = [float(x) for x in simulation2[location]] if is_interactive: ion() if file_sim2 is None: plot(time_sim, quantity_sim, time_exp, quantity_exp) else: plot(time_sim, quantity_sim, time_sim2, quantity_sim2, time_exp, quantity_exp, ) # Add axis stuff and legend xlabel(x_label) ylabel(y_label) if legend_sim2 is None: legend((legend_sim, legend_exp)) else: legend((legend_sim, legend_sim2, legend_exp)) if is_interactive: # Wait for enter pressed raw_input() if save_as is not None: savefig(save_as) #Need to close this plot close() #------------------------------------------------------------- if __name__ == "__main__": """ Plot the stage graph for the ANUGA validation papar """ import project import shutil from os import sep, path depth_file = "uq-friction-depth.eps" # create Depth plot plot_compare_csv(location='0.4:0.2', # testing location file_sim=project.depth_filename, file_sim2=project.depth_filename2, file_exp=project.experiment_depth_filename, legend_sim="ANUGA, Manning's friction 0.0", legend_sim2="ANUGA, Manning's friction 0.01", y_label='Water height (m)', save_as=depth_file) #import sys; sys.exit() # Move the files to the dir where the paper is being put together paper_dir = path.join('..','..','anuga_work','publications','anuga_2007') dest = path.join(paper_dir, depth_file) shutil.copyfile(depth_file,dest)