def plot_energy_error_heatmap(ax, data_set, struct_types=struct_types, dyn_types=dyn_types, bad_data_traj_list=[], xbin_size=None, ybin_size=None, use_meV_y=False, use_meV_x=False, cmap=cm.get_cmap('plasma')): scalex = 1 scaley = 1 if use_meV_x: scalex = 1000 if use_meV_y: scaley = 1000 def pick_bins(abin_size, A): if abin_size is None: abins = np.linspace(A.min(), A.max(), 100) else: abins = np.arange(A.min(), A.max(), abin_size) return abins #from matplotlib.ticker import MultipleLocator #ax.yaxis.set_major_locator(MultipleLocator(base=30)) #ax.yaxis.set_minor_locator(MultipleLocator(base=5)) import copy cmap_tweaked = copy.copy(cmap) from matplotlib.colors import Colormap Colormap.set_under(cmap_tweaked, color=(1, 1, 1, 0)) Colormap.set_over(cmap_tweaked, color=(1, 1, 1, 0)) fname = data_set[0] data_name = data_set[1] image_pairs = read_evaluation_data(filename=fname, struct_types=struct_types, dyn_types=dyn_types, bad_data_traj_list=bad_data_traj_list) cache_energy, data_energy = get_energy_lists(image_pairs) energy_error = cache_energy - data_energy error_rmse = np.sqrt(np.mean(energy_error**2)) * scaley error_mae = np.mean(np.absolute(energy_error)) * scaley X = data_energy * scalex Y = energy_error * scaley xbins = pick_bins(xbin_size, X) ybins = pick_bins(ybin_size, Y) ax.hist2d(X, Y, bins=(xbins, ybins), vmin=1, cmap=cmap_tweaked) ax.set_title(data_name, fontsize=8) ax.minorticks_on() return error_rmse, error_mae
def plot_force_angle_heatmaps(axes, data_sets, struct_types=struct_types, dyn_types=dyn_types, struct_colors=struct_colors, dyn_markers=dyn_markers, bad_data_traj_list=[], cmap=cm.get_cmap('plasma')): deg = 180 / np.pi bin_size = 2 my_bins = np.arange(0, 180 + bin_size / 2, bin_size) ylims = (0, 180) from matplotlib.ticker import MultipleLocator import copy cmap_tweaked = copy.copy(cmap) from matplotlib.colors import Colormap Colormap.set_under(cmap_tweaked, color=(1, 1, 1, 0)) Colormap.set_over(cmap_tweaked, color=(1, 1, 1, 0)) for di, data_set in enumerate(data_sets): fname = data_set[0] data_name = data_set[1] #color = np.array(get_color(data_set[2])) #lightness = data_set[3] #zorder = zorders[di] image_pairs = read_evaluation_data(filename=fname, struct_types=struct_types, dyn_types=dyn_types) cache_forces, data_forces = get_force_list(image_pairs) force_cosines_by_atom = compute_force_cosines_by_atom( cache_forces, data_forces) data_force_norms_by_atom = compute_force_norms_by_atom(data_forces) X = collapse_sub_lists(data_force_norms_by_atom) Y = deg * np.arccos(collapse_sub_lists(force_cosines_by_atom)) xbins = np.linspace(0, X.max(), 100) axes[di].hist2d(X, Y, bins=(xbins, my_bins), vmin=1, cmap=cmap_tweaked) #label = data_name + '\nMean: %.2f°\nRMS: %.2f°'%(mean_force_angles, rms_force_angles) axes[di].set_title(data_name, fontsize=8) axes[di].set_ylim(ylims) #ax2.legend(fontsize = 8, handletextpad = 0.3, borderpad = 0.1) axes[di].minorticks_on() axes[di].yaxis.set_major_locator(MultipleLocator(base=30)) axes[di].yaxis.set_minor_locator(MultipleLocator(base=5)) if di == 0: axes[di].set_ylabel('Force Angle, ' + formula_angle + ' (°)') axes[di].set_xlabel('DFT Force (eV/Å)')
landNAN[:] = np.nan land = np.hstack((landXY,landNAN)) # Data we want to read and interpolate data = glob.glob(path+'*.npy') data.sort() print data # Colormap Chl de ref # COULEUR norm_chl=mpl.colors.LogNorm(vmin=0.01, vmax=20) colors = [(0.33,0.33,0.33)] + [(plt.cm.jet(i)) for i in xrange(1,256)] new_map_chl = mpl.colors.LinearSegmentedColormap.from_list('new_map_chl', colors, N=256) new_map_chl._init(); new_map_chl._lut[0,:] = new_map_chl._lut[1,:] # Replace lowest value of colormap (which is gray) with the one before (dark blue) Colormap.set_under(new_map_chl,color=new_map_chl._lut[0,:]) # Set color for values outside colormap to be the lowest of the colormap (dark blue) ##Colormap.set_over(new_map_chl,color=(0.0, 0.0, 0.517825311942959, 1.0)) ## to get rgba from colormap for a specific value : new_map_chl(specificvalue for example ex : 0.2) # BLACK AND WHITE grays = [(0.33,0.33,0.33)] + [(plt.cm.gray(i)) for i in xrange(1,256)] new_map_gray_chl = mpl.colors.LinearSegmentedColormap.from_list('new_map_gray_chl', grays, N=256) # Colormap (avec borne grise) #norm_chl=mpl.colors.LogNorm(vmin=0.01, vmax=20) #colors = [(0.33,0.33,0.33)] + [(plt.cm.jet(i)) for i in xrange(1,256)] #new_map_chl = mpl.colors.LinearSegmentedColormap.from_list('new_map_chl', colors, N=256) #colors = [(0.33,0.33,0.33)] + [(plt.cm.gray(i)) for i in xrange(1,256)] #new_map_gray_chl = mpl.colors.LinearSegmentedColormap.from_list('new_map_gray_chl', colors, N=256) #==============================================================================
def plot_force_error_heatmap(ax, data_set, struct_types=struct_types, dyn_types=dyn_types, bad_data_traj_list=[], xbin_size=None, ybin_size=None, use_meV_y=False, use_meV_x=False, by_atom=False, cmap=cm.get_cmap('viridis')): scalex = 1 scaley = 1 if use_meV_x: scalex = 1000 if use_meV_y: scaley = 1000 def pick_bins(abin_size, A): if abin_size is None: abins = np.linspace(A.min(), A.max(), 100) else: abins = np.arange(A.min(), A.max(), abin_size) return abins #from matplotlib.ticker import MultipleLocator #ax.yaxis.set_major_locator(MultipleLocator(base=30)) #ax.yaxis.set_minor_locator(MultipleLocator(base=5)) import copy cmap_tweaked = copy.copy(cmap) from matplotlib.colors import Colormap Colormap.set_under(cmap_tweaked, color=(1, 1, 1, 0)) Colormap.set_over(cmap_tweaked, color=(1, 1, 1, 0)) fname = data_set[0] data_name = data_set[1] image_pairs = read_evaluation_data(filename=fname, struct_types=struct_types, dyn_types=dyn_types) cache_forces, data_forces = get_force_list(image_pairs) force_error_list = compute_force_error_list(cache_forces, data_forces) if by_atom: atom_force_norms = compute_atom_force_norms(data_forces) rms_force_error_by_atom = compute_rms_force_error_by_atom( cache_forces, data_forces) net_rms_force_error_by_atom = np.sqrt( np.mean(collapse_sub_lists(rms_force_error_by_atom)**2)) X = scalex * atom_force_norms Y = scaley * rms_force_error_by_atom error_rmse = scaley * net_rms_force_error_by_atom else: image_force_norms = compute_force_norms_by_image( data_forces) / np.sqrt(3) rms_force_error_by_image = compute_rms_force_error_by_image( cache_forces, data_forces) / np.sqrt(3) net_rms_force_error_by_image = np.sqrt( np.mean((rms_force_error_by_image)**2)) X = scalex * image_force_norms Y = scaley * rms_force_error_by_image error_rmse = scaley * net_rms_force_error_by_image xbins = pick_bins(xbin_size, X) ybins = pick_bins(ybin_size, Y) ax.hist2d(X, Y, bins=(xbins, ybins), vmin=1, cmap=cmap_tweaked) ax.set_title(data_name, fontsize=8) ax.minorticks_on() return error_rmse
def plot_force_angle_polar_heatmap( ax, data_set, struct_types=struct_types, dyn_types=dyn_types, bad_data_traj_list=[], theta_zero_location="S", xbin_size=None, ybin_size=None, use_meV_y=False, #use_meV_x = False, by_atom=True, cmap=cm.get_cmap('plasma')): scalex = 1 scaley = 1 #if use_meV_x: scalex = 1000 if use_meV_y: scaley = 1000 deg = 180 / np.pi def pick_bins(abin_size, A): if abin_size is None: abins = np.linspace(np.min(A), np.max(A), 100) else: abins = np.arange(np.min(A), np.max(A), abin_size) return abins if xbin_size is None: xbin_size = 2 xbins = np.arange(0, 180, xbin_size) from matplotlib.ticker import MultipleLocator #ax.yaxis.set_major_locator(MultipleLocator(base=30)) #ax.yaxis.set_minor_locator(MultipleLocator(base=5)) import copy cmap_tweaked = copy.copy(cmap) from matplotlib.colors import Colormap Colormap.set_under(cmap_tweaked, color=(1, 1, 1, 0)) Colormap.set_over(cmap_tweaked, color=(1, 1, 1, 0)) fname = data_set[0] data_name = data_set[1] image_pairs = read_evaluation_data(filename=fname, struct_types=struct_types, dyn_types=dyn_types) cache_forces, data_forces = get_force_list(image_pairs) force_error_list = compute_force_error_list(cache_forces, data_forces) if by_atom: force_norms_by_atom = compute_force_norms_by_atom(data_forces) rms_force_error_by_atom = compute_rms_force_error_by_atom( cache_forces, data_forces) #net_rms_force_error_by_atom = np.sqrt(np.mean( collapse_sub_lists(rms_force_error_by_atom)**2)) force_cosines_by_atom = compute_force_cosines_by_atom( cache_forces, data_forces) force_angles_by_atom = deg * np.arccos( collapse_sub_lists(force_cosines_by_atom)) mean_force_angles = np.mean(force_angles_by_atom) rms_force_angles = np.sqrt(np.mean((force_angles_by_atom)**2)) X = scalex * force_angles_by_atom Y = scaley * collapse_sub_lists(rms_force_error_by_atom) error_rmse = scaley * rms_force_angles error_mae = scaley * mean_force_angles else: image_force_norms = compute_force_norms_by_image( data_forces) / np.sqrt(3) rms_force_error_by_image = compute_rms_force_error_by_image( cache_forces, data_forces) / np.sqrt(3) net_rms_force_error_by_image = np.sqrt( np.mean((rms_force_error_by_image)**2)) X = scalex * image_force_norms Y = scaley * rms_force_error_by_image error_rmse = scaley * net_rms_force_error_by_image #xbins = pick_bins(xbin_size, X) ybins = pick_bins(ybin_size, Y) ax.hist2d(X / deg, Y, bins=(xbins / deg, ybins), vmin=1, cmap=cmap_tweaked) ax.set_title(data_name, fontsize=8) #ax_force_polar.legend(fontsize = 8) ax.set_thetamin(0) ax.set_thetamax(180) ax.set_theta_zero_location(theta_zero_location) ax.xaxis.set_major_locator(MultipleLocator(base=45 / deg)) #ax.xaxis.set_minor_locator(MultipleLocator(base=15/deg)) dtheta = 15 theta_grid = np.arange(0, 180 + dtheta / 2, dtheta) for theta in theta_grid: ax.axvline(theta / deg, color='grey', lw=0.8, zorder=-1) #ax.set_thetagrids() #ax.minorticks_on() return error_rmse, error_mae