def run(name, config): """ Runs the analysis of the coverage of the ice sheet over the land mass. Produces both an overall coverage percentage metric and a coverage plot. Args: name: The name of the test config: A dictionary representation of the configuration file Returns: An elements.page with the list of elements to display """ greenland_data = os.path.join(livvkit.__path__[0], config['data_dir'], config['gl_data']) velocity_data = os.path.join(livvkit.__path__[0], config['data_dir'], config['vel_data']) if not (os.path.exists(greenland_data) and os.path.exists(velocity_data)): # Add more handling here -- what do we want to return for failed tests return elements.error("lvargo13", "Could not find necessary data for validation!") # Generate the script output_dir = os.path.join(livvkit.index_dir, 'validation', 'imgs') output_file_base = os.path.join(output_dir, 'lvargo13') functions.mkdir_p(output_dir) ncl_command = 'ncl \'gl_data = addfile("' + greenland_data + '", "r")\' ' \ + '\'vel_data = addfile("' + velocity_data + '", "r")\' ' \ + '\'model_prefix = "' \ + os.path.join(livvkit.__path__[0], config['data_dir'], config['model_prefix']) \ + '"\' ' \ + '\'model_suffix = "' + config['model_suffix'] + '"\' ' \ + '\'model_start = ' + config['model_start'] + '\' ' \ + '\'model_end = ' + config['model_end'] + '\' ' \ + '\'plot_file_base = "' + output_file_base + '"\' ' \ + os.path.join(livvkit.__path__[0], config['plot_script']) # Be cautious about running subprocesses p = subprocess.Popen(ncl_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ncl_out, ncl_err = p.communicate() # TODO: Put some error checking here output_plots = [ os.path.basename(p) for p in glob.glob(output_file_base + "*.png") ] plot_list = [] for plot in output_plots: plot_list.append(elements.image(plot, "", plot)) the_page = elements.page("lvargo13", config['description'], elements.gallery("Plots", plot_list)) return the_page
def generate_scaling_plot(timing_data, title, ylabel, description, plot_file): """ Generate a scaling plot. Args: timing_data: data returned from a `*_scaling` method title: the title of the plot ylabel: the y-axis label of the plot description: a description of the plot plot_file: the file to write out to Returns: an image element containing the plot file and metadata """ proc_counts = timing_data['proc_counts'] if len(proc_counts) > 2: plt.figure(figsize=(10, 8), dpi=150) plt.title(title) plt.xlabel("Number of processors") plt.ylabel(ylabel) for case, case_color in zip(['bench', 'model'], ['#91bfdb', '#fc8d59']): case_data = timing_data[case] means = case_data['means'] mins = case_data['mins'] maxs = case_data['maxs'] plt.fill_between(proc_counts, mins, maxs, facecolor=case_color, alpha=0.5) plt.plot(proc_counts, means, 'o-', color=case_color, label=case) plt.legend(loc='best') else: plt.figure(figsize=(5, 3)) plt.axis('off') plt.text(0.4, 0.8, "ERROR:") plt.text(0.0, 0.6, "Not enough data points to draw scaling plot") plt.text(0.0, 0.44, "To generate this data rerun BATS with the") plt.text(0.0, 0.36, "performance option enabled.") if livvkit.publish: plt.savefig(os.path.splitext(plot_file)[0] + '.eps', dpi=600) plt.savefig(plot_file) plt.close() return elements.image(title, description, os.path.basename(plot_file))
def generate_scaling_plot(timing_data, title, ylabel, description, plot_file): """ Generate a scaling plot. Args: timing_data: data returned from a `*_scaling` method title: the title of the plot ylabel: the y-axis label of the plot description: a description of the plot plot_file: the file to write out to Returns: an image element containing the plot file and metadata """ proc_counts = timing_data['proc_counts'] if len(proc_counts) > 2: plt.figure(figsize=(10, 8), dpi=150) plt.title(title) plt.xlabel("Number of processors") plt.ylabel(ylabel) for case, case_color in zip(['bench', 'model'], ['#91bfdb', '#fc8d59']): case_data = timing_data[case] means = case_data['means'] mins = case_data['mins'] maxs = case_data['maxs'] plt.fill_between(proc_counts, mins, maxs, facecolor=case_color, alpha=0.5) plt.plot(proc_counts, means, 'o-', color=case_color, label=case) plt.legend(loc='best') else: plt.figure(figsize=(5, 3)) plt.axis('off') plt.text(0.4, 0.8, "ERROR:") plt.text(0.0, 0.6, "Not enough data points to draw scaling plot") plt.text(0.0, 0.44, "To generate this data rerun BATS with the") plt.text(0.0, 0.36, "performance option enabled.") if livvkit.publish: plt.savefig(os.path.splitext(plot_file)[0]+'.eps', dpi=600) plt.savefig(plot_file) plt.close() return elements.image(title, description, os.path.basename(plot_file))
def run(name, config): """ Runs the analysis of the coverage of the ice sheet over the land mass. Produces both an overall coverage percentage metric and a coverage plot. Args: name: The name of the test config: A dictionary representation of the configuration file Returns: An elements.page with the list of elements to display """ bench_data = os.path.join(livvkit.__path__[0], config['data_dir'], config['bench_data']) model_data = os.path.join(livvkit.__path__[0], config['data_dir'], config['model_data']) if not (os.path.exists(model_data) and os.path.exists(bench_data)): # Add more handling here -- what do we want to return for failed tests print( "ERROR: Could not find necessary data to run the coverage validation!" ) print(model_data) print(bench_data) print("") return elements.error( "coverage", "Could not find necessary data to run the coverage validation!") # Generate the script plot_name = "coverage.png" output_dir = os.path.join(livvkit.index_dir, 'validation', 'imgs') output_path = os.path.join(output_dir, plot_name) functions.mkdir_p(output_dir) plot_coverage(config['plot_script'], model_data, bench_data, output_path) plot_list = [elements.image(plot_name, " ", plot_name)] the_page = elements.page('coverage', config['description'], elements.gallery("Plots", plot_list)) return the_page
def generate_timing_breakdown_plot(timing_stats, scaling_var, title, description, plot_file): """ Description Args: timing_stats: a dictionary of the form {proc_count : {model||bench : { var : { stat : val }}}} scaling_var: the variable that accounts for the total runtime title: the title of the plot description: the description of the plot plot_file: the file to write the plot out to Returns: an image element containing the plot file and metadata """ # noinspection PyProtectedMember cmap_data = colormaps._viridis_data n_subplots = len(six.viewkeys(timing_stats)) fig, ax = plt.subplots(1, n_subplots + 1, figsize=(3 * (n_subplots + 2), 5)) for plot_num, p_count in enumerate( sorted(six.iterkeys(timing_stats), key=functions.sort_processor_counts)): case_data = timing_stats[p_count] all_timers = set(six.iterkeys(case_data['model'])) | set( six.iterkeys(case_data['bench'])) all_timers = sorted(list(all_timers), reverse=True) cmap_stride = int(len(cmap_data) / (len(all_timers) + 1)) colors = { all_timers[i]: cmap_data[i * cmap_stride] for i in range(len(all_timers)) } sub_ax = plt.subplot(1, n_subplots + 1, plot_num + 1) sub_ax.set_title(p_count) sub_ax.set_ylabel('Runtime (s)') for case, var_data in case_data.items(): if case == 'bench': bar_num = 2 else: bar_num = 1 offset = 0 if var_data != {}: for var in sorted(six.iterkeys(var_data), reverse=True): if var != scaling_var: plt.bar(bar_num, var_data[var]['mean'], 0.8, bottom=offset, color=colors[var], label=(var if bar_num == 1 else '_none')) offset += var_data[var]['mean'] plt.bar(bar_num, var_data[scaling_var]['mean'] - offset, 0.8, bottom=offset, color=colors[scaling_var], label=(scaling_var if bar_num == 1 else '_none')) sub_ax.set_xticks([1.4, 2.4]) sub_ax.set_xticklabels(('test', 'bench')) plt.legend(loc=6, bbox_to_anchor=(1.05, 0.5)) plt.tight_layout() sub_ax = plt.subplot(1, n_subplots + 1, n_subplots + 1) hid_bar = plt.bar(1, 100) for group in hid_bar: group.set_visible(False) sub_ax.set_visible(False) if livvkit.publish: plt.savefig(os.path.splitext(plot_file)[0] + '.eps', dpi=600) plt.savefig(plot_file) plt.close() return elements.image(title, description, os.path.basename(plot_file))
for a in six.iterkeys(analysis): for model in sorted(six.iterkeys(analysis[a])): plt.plot(analysis[a][model][coord], analysis[a][model][config['plot_vars'][p]], line_style[model], color=case_color[model], linewidth=2, label=a+'-'+model) plt.legend(loc='best') if livvkit.publish: plt.savefig( os.path.splitext(plot_file)[0]+'.eps', dpi=600 ) plt.savefig(plot_file) plt.close() plot_list.append(elements.image(title, description, os.path.basename(plot_file))) return elements.gallery("Numerics Plots", plot_list) def summarize_result(data, config): case = config['name'] summary = LIVVDict() lengths = list(set([get_case_length(d) for d in six.iterkeys(data)])) for p, pattern in enumerate(sorted(setup[case]['pattern'])): for l in sorted(lengths): recreate_file = os.path.join( livvkit.__path__[0], setup[case]["data_dir"], pattern ).replace('???', l)
def run(config, analysis_data): case = config['name'] if case in ['ismip-hom-a', 'ismip-hom-c', 'ismip-hom-f']: coord = 'x_hat' else: coord = 'y_hat' lengths = list(set( [get_case_length(d) for d in six.iterkeys(analysis_data)] )) plot_list = [] for p, pattern in enumerate(sorted(setup[case]['pattern'])): fig_label = pattern.split('_')[1] description = '' for l in sorted(lengths): plt.figure(figsize=(10, 8), dpi=150) plt.xlabel(setup[case]['xlabel'][p]) plt.ylabel(setup[case]['ylabel'][p]) if case in ['ismip-hom-a', 'ismip-hom-c']: plt.title(str(int(l))+' km') title = fig_label[0:-1]+'. '+fig_label[-1]+': '+str(int(l))+' km' else: plt.title('No-Slip Bed') title = fig_label[0:-2]+'. '+fig_label[-2:]+': No-Slip Bed' plot_file = os.path.join(config["plot_dir"], config['name']+'_'+fig_label+'_'+l+'.png') recreate_file = os.path.join( livvkit.__path__[0], setup[case]["data_dir"], pattern ).replace('???', l) axis, fs_amin, fs_amax, fs_mean, fs_std, ho_amin, ho_amax, ho_mean, ho_std = \ np.genfromtxt(recreate_file, delimiter=',', missing_values='nan', unpack=True) if case in ['ismip-hom-f']: axis = axis*100.0 - 50.0 plt.fill_between(axis, ho_amin, ho_amax, facecolor='green', alpha=0.5) plt.fill_between(axis, fs_amin, fs_amax, facecolor='blue', alpha=0.5) plt.plot(axis, fs_mean, 'b-', linewidth=2, label='Full stokes') plt.plot(axis, ho_mean, 'g-', linewidth=2, label='Higher order') analysis = {} for a in six.iterkeys(analysis_data): if int(l) == int(a.split('-')[-1][1:]): analysis[a] = analysis_data[a] for a in six.iterkeys(analysis): for model in sorted(six.iterkeys(analysis[a])): plt.plot(analysis[a][model][coord], analysis[a][model][config['plot_vars'][p]], line_style[model], color=case_color[model], linewidth=2, label=a+'-'+model) plt.legend(loc='best') if livvkit.publish: plt.savefig(os.path.splitext(plot_file)[0]+'.eps', dpi=600) plt.savefig(plot_file) plt.close() plot_list.append(elements.image(title, description, os.path.basename(plot_file))) return elements.gallery("Numerics Plots", plot_list)
details[var]['std (case 1, case 2)'] = ( np.std(averages[args.case1][var]['annuals']), np.std(averages[args.case2][var]['annuals'])) if details[var]['T test (t, p)'][0] is None: details[var]['h0'] = '-' elif details[var]['K-S test (D, p)'][1] < 0.05: details[var]['h0'] = 'reject' else: details[var]['h0'] = 'accept' img_file = os.path.relpath(os.path.join(args.img_dir, var + '.png'), os.getcwd()) prob_plot(args, var, averages, 20, img_file) img_desc = 'Mean annual global average of {} for <em>{}</em> is {:.3e} and for <em>{}</em> is {:.3e}'.format( var, args.case1, details[var]['mean (case 1, case 2)'][0], args.case2, details[var]['mean (case 1, case 2)'][1]) img_link = os.path.join(os.path.basename(args.img_dir), os.path.basename(img_file)) img_list.append(el.image(var, img_desc, img_link)) img_gal = el.gallery('Analyzed variables', img_list) return details, img_gal if __name__ == '__main__': print_details(main(parse_args()))
def generate_timing_breakdown_plot(timing_stats, scaling_var, title, description, plot_file): """ Description Args: timing_stats: a dictionary of the form {proc_count : {model||bench : { var : { stat : val }}}} scaling_var: the variable that accounts for the total runtime title: the title of the plot description: the description of the plot plot_file: the file to write the plot out to Returns: an image element containing the plot file and metadata """ # noinspection PyProtectedMember cmap_data = colormaps._viridis_data n_subplots = len(six.viewkeys(timing_stats)) fig, ax = plt.subplots(1, n_subplots+1, figsize=(3*(n_subplots+2), 5)) for plot_num, p_count in enumerate( sorted(six.iterkeys(timing_stats), key=functions.sort_processor_counts)): case_data = timing_stats[p_count] all_timers = set(six.iterkeys(case_data['model'])) | set(six.iterkeys(case_data['bench'])) all_timers = sorted(list(all_timers), reverse=True) cmap_stride = int(len(cmap_data)/(len(all_timers)+1)) colors = {all_timers[i]: cmap_data[i*cmap_stride] for i in range(len(all_timers))} sub_ax = plt.subplot(1, n_subplots+1, plot_num+1) sub_ax.set_title(p_count) sub_ax.set_ylabel('Runtime (s)') for case, var_data in case_data.items(): if case == 'bench': bar_num = 2 else: bar_num = 1 offset = 0 if var_data != {}: for var in sorted(six.iterkeys(var_data), reverse=True): if var != scaling_var: plt.bar(bar_num, var_data[var]['mean'], 0.8, bottom=offset, color=colors[var], label=(var if bar_num == 1 else '_none')) offset += var_data[var]['mean'] plt.bar(bar_num, var_data[scaling_var]['mean']-offset, 0.8, bottom=offset, color=colors[scaling_var], label=(scaling_var if bar_num == 1 else '_none')) sub_ax.set_xticks([1.4, 2.4]) sub_ax.set_xticklabels(('test', 'bench')) plt.legend(loc=6, bbox_to_anchor=(1.05, 0.5)) plt.tight_layout() sub_ax = plt.subplot(1, n_subplots+1, n_subplots+1) hid_bar = plt.bar(1, 100) for group in hid_bar: group.set_visible(False) sub_ax.set_visible(False) if livvkit.publish: plt.savefig(os.path.splitext(plot_file)[0]+'.eps', dpi=600) plt.savefig(plot_file) plt.close() return elements.image(title, description, os.path.basename(plot_file))