def show_features(self, feature_key='tke', show_all=False, show_geometry=True): """ Display the feature in the physical domain. :param show_geometry: Print outline of the boundary. :param feature_key: Key for the feature (see utilties.py and features.py) :param show_all: Display all features (WARNING >50 plots). :return: 1:success. """ # Plot all features if show_all: for key in self.feature_dict: # 2D Geometry outline if show_geometry: fig, ax = self.show_geometry() else: fig, ax = plot.empty_plot() plot.scattering(self.flow_dict['x'], self.flow_dict['y'], self.feature_dict[key], scale=5, alpha=1.0, xlabel='x', ylabel='y', title=key, colorbar=True, append_to_fig_ax=(fig, ax)) # Plot requested feature else: assert ( feature_key in self.feature_dict ), "feature_key is not a valid key for features: %r" % feature_key # 2D Geometry outline if show_geometry: fig, ax = self.show_geometry() else: fig, ax = plot.empty_plot() plot.scattering(self.flow_dict['x'], self.flow_dict['y'], self.feature_dict[feature_key], scale=5, alpha=1.0, xlabel='x/h', ylabel='y/h', title=feature_key, cmap='viridis', colorbar=True, append_to_fig_ax=(fig, ax)) return 1
def performance_complexity(name, highlight_idx=None): df_quant = pd.read_csv("./results/" + name + "/quantitative.csv") complexitys = df_quant['complexity'].to_list() f1_tests = df_quant['f1_test'].to_list() f1_best = np.sort(f1_tests)[-1] idx_best = f1_tests.index(f1_best) complexity_best = complexitys[idx_best] print( f"Best model: {idx_best}\tF1: {f1_best}\t\tcomplexity: {complexity_best}" ) # All models fig, ax = empty_plot(figwidth=latex_textwidth * 0.9) lining(complexitys, f1_tests, linestyle='o', marker='o', markeredgewidth=0, color=cgrey, xlim=[0.9, 1200], ylim=[0.0, 1.01], xlog=True, append_to_fig_ax=(fig, ax)) # Best model scattering(complexity_best, f1_best, 1, color=cred, marker='X', scale=100, xlabel="Model complexity", ylabel="F-measure", zorder=2.5, append_to_fig_ax=(fig, ax)) sname_add = "_" # Highlights if isinstance(highlight_idx, int): highlight_idx = [highlight_idx] if isinstance(highlight_idx, list): for idx, color in zip( highlight_idx, cycle([corange, cyellow, cdarkred, clightyellow, cdarkred])): complexity_high = complexitys[idx] f1_high = f1_tests[idx] print( f"Highlight {idx} at:\tF1: {f1_high}\t\tcomplexity: {complexity_high}" ) scattering(complexity_high, f1_high, 1, color=color, scale=100, marker='^', xlabel="Model complexity", ylabel="F-measure", zorder=2.5, append_to_fig_ax=(fig, ax)) sname_add = "highlight_" legend_elements = [ Line2D([0], [0], marker="X", linestyle='', lw=0, markersize=10, color=cred, label="Best"), Line2D([0], [0], marker="^", linestyle='', lw=0, markersize=10, color=corange, label="Algebraic") ] # Legend ax.legend(handles=legend_elements, loc="lower right", numpoints=1) # save("./results/" + name + "/figures/performance_vs_complexity" + sname_add + ".pdf") save("figures/" + "performance_vs_complexity_" + sname_add + str(algo) + "_" + str(scenario) + "_" + str(test_set.replace("-", "_")) + "_" + str(emetric) + "_" + ".pdf") # show() return idx_best
# Test laminar criteria idx = dit['k'] < 0.002 lam = arr[idx] # sij = dit['Sij'][:,:,idx] # tij = dit['tauij'][:,:,idx] # Sij >> tij for "laminar" flow # Show laminar points # fig, ax = plot.scattering(x, y, np.ones_like(x), cmap='viridis', scale=10) # plot.scattering(x[idx], y[idx], lam, cmap='gray', scale=10, append_to_fig_ax=(fig, ax)) # plot.show() # Compare with/-out criteria plot.scattering(x, y, arr, scale=10, title='Without laminar flow criteria', xlabel='x/h', ylabel='y/h', save='without_laminar_criteria') plot.scattering(x, y, arr_lam, scale=10, title='With laminar flow criteria', xlabel='x/h', ylabel='y/h', save='with_laminar_criteria') plot.show() print('EOF test_laminar_criteria')
error = np.ones(nx * ny) error_x = np.ones(nx * ny) error_y = np.ones(nx * ny) for i in range(nx * ny): error[i] = np.linalg.norm(exact_gradient[:, i] - approx_gradient[:, i]) error_x[i] = exact_gradient[0, i] - approx_gradient[0, i] error_y[i] = exact_gradient[1, i] - approx_gradient[1, i] # Plot print("The mean error is " + str(np.mean(error))) print("The max error is " + str(np.max(error))) print("The min error is " + str(np.min(error))) # plot.scattering(x, y, f, title="f", save='sample_function_sinx_cosy') # plot.scattering(x, y, exact_gradient[0].reshape(nx, ny), # title="exact") # plot.scattering(x, y, approx_gradient[0].reshape(nx, ny), # title="approx") plot.scattering(x, y, error.reshape(nx, ny), title="error", colorbar=True) # plot.scattering(x[3:-3, 1:-1], y[3:-3, 1:-1], error.reshape(nx, ny)[3:-3, 1:-1], title="error", # save='gradient_approximation_error', colorbar=True) # plot.scattering(x, y, error_x.reshape(nx, ny), title="error x", # save='gradient_approximation_error_x', colorbar=True) # plot.scattering(x, y, error_y.reshape(nx, ny), title="error y", # save='gradient_approximation_error_y', colorbar=True) plot.show() print("TEST OF GRADIENT COMPUTATION COMPLETED")
def show_label(self, label_key='non_negative', show_all=False, show_geometry=True, show_background=False, labelpos='center', only_positive=False, zoom_box=False): """ Display the labels in the physical coordinates. :param show_geometry: Print outline of the boundary. :param label_key: Key for the label (see utilities.py) :param show_all: Display all labels. :return: void. """ if show_all: for key in self.label_dict: # Create figure fig, ax = plot.empty_plot(figwidth=plot.latex_textwidth) boundaries, xlabel, ylabel, title, xlim, ylim, mask, seeding = plot.get_geometry_plot_data( self, return_seeding=True) plot.scattering(self.flow_dict['x'][~mask], self.flow_dict['y'][~mask], self.label_dict[key][~mask], scale=10, alpha=1.0, title=key, cmap=plot.confusion_cmap, append_to_fig_ax=(fig, ax)) # 2D Geometry outline if show_geometry: for boundary in boundaries: plot.lining(*boundary, linestyle='-', color=plot.cblack, append_to_fig_ax=(fig, ax)) plot.set_labels_title(ax, xlabel, ylabel, title) plot.set_limits(ax, xlim=xlim, ylim=ylim) else: fig, ax = plot.empty_plot(figwidth=plot.latex_textwidth) # Background flow if show_background: nx, ny = self.nx, self.ny X, Y = self.flow_dict['x'].reshape( nx, ny), self.flow_dict['y'].reshape(nx, ny) U, V = self.flow_dict['um'].reshape( nx, ny), self.flow_dict['vm'].reshape(nx, ny) if "NACA" in self.case_name: pass else: plot.streams(ax, X, Y, U, V, start_points=seeding, color=plot.cblack) pass else: assert ( label_key in self.label_dict ), "label_key is not a valid key for labels: %r" % label_key # Create figure fig, ax = plot.empty_plot(figwidth=plot.latex_textwidth * 0.9) boundaries, xlabel, ylabel, title, xlim, ylim, mask, seeding = plot.get_geometry_plot_data( self, return_seeding=True) # plot.scattering(self.flow_dict['x'][~mask], # self.flow_dict['y'][~mask], # self.label_dict[label_key][~mask], # scale=10, # alpha=1.0, # cmap=plot.confusion_cmap, # append_to_fig_ax=(fig, ax)) X, Y, LABEL = self.flow_dict['x'][~mask], self.flow_dict['y'][ ~mask], self.label_dict[label_key][~mask] positive = LABEL == 1 negative = LABEL == 0 xs = [X[positive], X[negative]] ys = [Y[positive], Y[negative]] labels = [LABEL[positive], LABEL[negative]] zorders = [3, 2.9, 2.7, 2.8] if only_positive: xs = [xs[0]] ys = [ys[0]] labels = [labels[0]] for x, y, label, zorder in zip(xs, ys, labels, zorders): ax.scatter(x, y, s=10, c=label, cmap=plot.confusion_cmap, vmin=0, vmax=1, zorder=zorder) # Background flow if show_background: nx, ny = self.nx, self.ny X, Y = self.flow_dict['x'].reshape( nx, ny), self.flow_dict['y'].reshape(nx, ny) U, V = self.flow_dict['um'].reshape( nx, ny), self.flow_dict['vm'].reshape(nx, ny) if "NACA" in self.case_name: pass else: plot.streams(ax, X, Y, U, V, start_points=seeding, color=plot.cgrey) pass # 2D Geometry outline if show_geometry: for boundary in boundaries: plot.lining(*boundary, linestyle='-', color=plot.cblack, append_to_fig_ax=(fig, ax)) plot.set_labels_title(ax, xlabel, ylabel, title) plot.set_limits(ax, xlim=xlim, ylim=ylim) else: fig, ax = plot.empty_plot(figwidth=plot.latex_textwidth) # Legend labels = [ r"\textsf{True-Positive}", r"\textsf{True-Negative}", r"\textsf{False-Positive}", r"\textsf{False-Negative}" ] # labels = ["Richtig-Positiv", "Richtig-Negativ", "Falsch-Positiv", "Falsch-Negativ"] label_values = [1, 0, 0.3, 0.7] cmap = plot.confusion_cmap clrs = cmap(label_values) legend_elements = list() for clr, label in zip(clrs[:2], labels[:2]): legend_elements.append( plot.line2d([0], [0], marker='o', linestyle='', color=clr, markersize=4, markerfacecolor=clr, label=label)) ax.legend(handles=legend_elements, loc=labelpos) # Zoom box if isinstance(zoom_box, list): for xi, yi in zip(zoom_box[0], zoom_box[1]): # Create a Rectangle patch rect = plot.patches.Rectangle((xi[0], yi[0]), abs(xi[1] - xi[0]), abs(yi[1] - yi[0]), linewidth=2.0, edgecolor=plot.cblack, facecolor='none', zorder=10) ax.add_patch(rect) return fig, ax
def show_flow(self, var_key, contour=True, contour_level=10, xlim=None, ylim=None, colorbar=False, show_geometry=True): """ Display the requested variable in the physical coordinates. :param show_geometry: Print outline of the boundary. :param contour_level: Set amount of or specific levels. :param contour: Option for contour plot instead of scatter. :param ylim: List with shape [min_y, max_y] :param xlim: List with shape [min_x, max_x] :param var_key: Key in flow_dict for flow quantity. :return: void. """ assert (var_key in self.flow_dict ), "var_key is not a valid key for flow data: %r" % var_key title = var_key + ' in ' + self.case_name if self.flow_dict[var_key].shape[0] == 3: var = self.flow_dict[var_key][0] # x-component of vector else: var = self.flow_dict[var_key] # 2D Geometry outline if show_geometry: fig, ax = self.show_geometry() else: fig, ax = plot.empty_plot() # Contour plot if contour: plot.contouring(self.flow_dict['x'].reshape(self.nx, self.ny), self.flow_dict['y'].reshape(self.nx, self.ny), var.reshape(self.nx, self.ny), xlabel='x', ylabel='y', title=title, levels=contour_level, colorbar=colorbar, xlim=xlim, ylim=ylim, append_to_fig_ax=(fig, ax)) # Scatter plot else: plot.scattering(self.flow_dict['x'], self.flow_dict['y'], var, scale=20, alpha=0.3, colorbar=colorbar, xlim=xlim, ylim=ylim, xlabel='x', ylabel='y', title=title, append_to_fig_ax=(fig, ax))
compare_integral_quantity('Cf', 'Reth', *hifi_data, xlim=[0, 4300], ylim=[0, 0.008]) # Find laminar flow threshold with y+ < 5 case = hifi_data[0] x, y = case.flow_dict['x'], case.flow_dict['y'] nx, ny = case.nx, case.ny yp = case.flow_dict['y+'] idx_lam = yp < 5 idx_lam_crit = case.flow_dict['k'] < 0.002 fig, ax = plot.contouring(x.reshape(nx, ny), y.reshape(nx, ny), case.flow_dict['k'].reshape(nx, ny)) plot.scattering(x[idx_lam_crit], y[idx_lam_crit], np.ones_like(x[idx_lam_crit]), append_to_fig_ax=(fig, ax), cmap='spring') plot.scattering(x[idx_lam], y[idx_lam], np.ones_like(x[idx_lam]), append_to_fig_ax=(fig, ax), cmap='autumn') plot.show()
# Upper limit xi_range = np.linspace(-1 / 6, 1 / 3, 20) eta_lim = (1 / 27 + 2 * xi_range**3)**0.5 lining(xi_range, eta_lim, append_to_fig_ax=(fig, ax), linestyle=limit_linestyle) # Anisotropy metric limit xi = np.linspace(-1 / 6, 1 / 6, 1000) eta = np.ones_like(xi) * 1 / 6 scattering( xi, eta, np.ones_like(xi), append_to_fig_ax=(fig, ax), alpha=0.4, scale=5, xlabel=r'$\xi$', ylabel=r'$\eta$', ) # Show area of true values xixi, etaeta = np.meshgrid(np.linspace(-1, 1, 1000), np.linspace(-1, 1, 1000)) bools = np.logical_and(np.logical_and(etaeta > 1 / 6, xixi > -1 / 3), xixi < 1 / 3) scattering( xixi[bools], etaeta[bools], np.ones_like(xixi[bools]), append_to_fig_ax=(fig, ax), alpha=0.4,
case_name = 'Tanarro_NACA0012_LES_top4n12' case = flowCase(case_name) x = case.flow_dict['x'] y = case.flow_dict['y'] xa = case.flow_dict['xa'] ya = case.flow_dict['ya'] x_min = np.min(x) x_max = np.max(x) y_min = np.min(y) y_max = np.max(y) # Plot reference scattering(x, y, np.arange(2600), append_to_fig_ax=(fig, ax)) ref = (xa, ya) lining(*ref, append_to_fig_ax=(fig, ax), linestyle='rx') # Compute naca profile x = np.linspace(0, 1, 1000) # upper = geometry_naca_profile(x, 4, 4, 12, 'upper') # lower = geometry_naca_profile(x, 4, 4, 12, 'lower') upper = geometry_naca_profile(x, 0, 0, 12, 'upper') lower = geometry_naca_profile(x, 0, 0, 12, 'lower') boundary = tuple([upper, lower])