def realspace_benchmark_new_algorithm_comparison(model, ea=None, num_inplane_angles=360, rad=0.6, save_animation=False, animation_name=None): N = model.shape[0] ea, euler_angles = gen_EAs_randomly(ea, num_inplane_angles) sl = projector.project(model, ea, rad=rad, truncate=True) rot_slice = projector.project(M, euler_angles, rad=rad, truncate=True) full_slice = projector.trunc_to_full(sl, N, rad) full_rot_slices = projector.trunc_to_full(rot_slice, N, rad) proj = density.fspace_to_real(full_slice) full_rot_projs = np.zeros_like(full_rot_slices, dtype=density.real_t) for i, fs in enumerate(full_rot_slices): full_rot_projs[i] = density.fspace_to_real(fs) trunc_proj = projector.full_to_trunc(proj, rad) trunc_rot_projs = projector.full_to_trunc(full_rot_projs, rad) corr_trunc_proj = correlation.calc_angular_correlation(trunc_proj, N, rad) corr_trunc_rot_projs = correlation.calc_angular_correlation(trunc_rot_projs, N, rad) diff = calc_difference(trunc_proj, trunc_rot_projs, only_real=True) corr_diff = calc_difference(corr_trunc_proj, corr_trunc_rot_projs, only_real=True) vis_real_space_comparison( full_rot_projs, projector.trunc_to_full(corr_trunc_rot_projs, N, rad), diff, corr_diff, original_img=proj, original_corr_img=projector.trunc_to_full(corr_trunc_proj, N, rad), save_animation=save_animation, animation_name=animation_name)
def angular_correlation_visulize(model, ea=None, rad=0.8): N = model.shape[0] ea0 = [0, 0, 0] ea1 = [0, 0, 60] ea0_proj = projector.project(model, np.deg2rad(ea0)) ea1_proj = projector.project(model, np.deg2rad(ea1)) ea0_trunc = projector.full_to_trunc(ea0_proj, rad=rad) ac_trunc = correlation.calc_angular_correlation(ea0_trunc, N, rad) ac_proj = projector.trunc_to_full(ac_trunc, N, rad=rad) fig = plt.figure(figsize=(6,8)) gs = GridSpec(2,2, height_ratios=[1, 0.5]) axes = list() axes.append(fig.add_subplot(gs[0, 0])) axes[0].imshow(ea0_proj, origin='lower') axes[0].set_title(r'$(\phi, \theta, \psi)=({}^\circ, {}^\circ, {}^\circ)$'.format(*ea0), fontdict={'size': 14}) axes.append(fig.add_subplot(gs[0, 1])) axes[1].imshow(ea1_proj, origin='lower') axes[1].set_title(r'$(\phi, \theta, \psi)=({}^\circ, {}^\circ, {}^\circ)$'.format(*ea1), fontdict={'size': 14}) axes.append(fig.add_subplot(gs[1, :])) axes[2].imshow(ac_proj, origin='lower') axes[2].set_title('angular correlation image', fontdict={'size': 14}) for ax in axes: ax.set_xticks([0, int(N/4), int(N/2), int(N*3/4), N-1]) ax.set_yticks([0, int(N/4), int(N/2), int(N*3/4), N-1]) fig.tight_layout() fig.savefig('angular_correlation_vis.png', dpi=300) plt.show()
def realspace_benchmark(model, ea=None, num_inplane_angles=360, calc_corr_img=False): N = model.shape[0] ea, euler_angles = gen_EAs_randomly(ea, num_inplane_angles) proj = projector.project(model, ea) rot_projs = projector.project(M, euler_angles) if calc_corr_img: proj = correlation.get_corr_img(proj) rot_projs = correlation.get_corr_imgs(rot_projs) diff = calc_difference(proj, rot_projs) vis_real_space(rot_projs, diff, original_img=proj)
def fourierspace_benchmark_comparison(model, ea=None, num_inplane_angles=360, modulus=False, save_animation=False, animation_name=None): N = model.shape[0] ea, euler_angles = gen_EAs_randomly(ea, num_inplane_angles) proj = projector.project(model, ea) one_slice = density.real_to_fspace(proj) rot_projs = projector.project(M, euler_angles) rot_slices = np.zeros_like(rot_projs, dtype=density.complex_t) for i, pj in enumerate(rot_projs): rot_slices[i] = density.real_to_fspace(pj) if modulus: one_slice = np.abs(one_slice) rot_slices = np.abs(rot_slices) if modulus: corr_slice = correlation.get_corr_img(one_slice) corr_rot_slices = correlation.get_corr_imgs(rot_slices) diff = calc_difference(one_slice, rot_slices, only_real=True) corr_diff = calc_difference(corr_slice, corr_rot_slices, only_real=True) vis_real_space_comparison( np.log(rot_slices), np.log(corr_rot_slices), diff, corr_diff, original_img=np.log(one_slice), original_corr_img=np.log(corr_slice), save_animation=save_animation, animation_name=animation_name ) else: corr_slice = np.zeros((int(N/2.0), 360), dtype=density.complex_t) corr_slice.imag = correlation.get_corr_img(one_slice.imag) corr_slice.real = correlation.get_corr_img(one_slice.real) corr_rot_slices = np.zeros((num_inplane_angles, int(N/2.0), 360), dtype=density.complex_t) corr_rot_slices.real = correlation.get_corr_imgs(rot_slices.real) corr_rot_slices.imag = correlation.get_corr_imgs(rot_slices.imag) diff_real, diff_imag = calc_difference(one_slice, rot_slices) corr_diff_real, corr_diff_imag = calc_difference(corr_slice, corr_rot_slices) vis_fourier_space_comparison( rot_slices, corr_rot_slices, diff_real, diff_imag, corr_diff_real, corr_diff_imag, original_img=one_slice, original_corr_img=corr_slice, save_animation=save_animation, animation_name=animation_name )
def realspace_benchmark_comparison(model, ea=None, num_inplane_angles=360, save_animation=False, animation_name=None): N = model.shape[0] ea, euler_angles = gen_EAs_randomly(ea, num_inplane_angles) proj = projector.project(model, ea) rot_projs = projector.project(M, euler_angles) corr_proj = correlation.get_corr_img(proj) corr_rot_projs = correlation.get_corr_imgs(rot_projs) diff = calc_difference(proj, rot_projs, only_real=True) corr_diff = calc_difference(corr_proj, corr_rot_projs, only_real=True) vis_real_space_comparison(rot_projs, corr_rot_projs, diff, corr_diff, original_img=proj, original_corr_img=corr_proj, save_animation=save_animation, animation_name=animation_name)
def fourierspace_benchmark_new_algorithm_comparison(model, ea=None, num_inplane_angles=360, rad=0.6, modulus=False, save_animation=False, animation_name=None): N = model.shape[0] ea, euler_angles = gen_EAs_randomly(ea, num_inplane_angles) one_slice = projector.project(model, ea, rad=rad, truncate=True) rot_slices = projector.project(M, euler_angles, rad=rad, truncate=True) if modulus: one_slice = np.abs(one_slice) rot_slices = np.abs(rot_slices) corr_slice = correlation.calc_angular_correlation(one_slice, N, rad) corr_rot_slices = correlation.calc_angular_correlation(rot_slices, N, rad) if modulus: diff = calc_difference(one_slice, rot_slices, only_real=True) corr_diff = calc_difference(corr_slice, corr_rot_slices, only_real=True) vis_real_space_comparison( np.log(projector.trunc_to_full(rot_slices, N, rad)), np.log(projector.trunc_to_full(corr_rot_slices, N, rad)), diff, corr_diff, original_img=np.log(projector.trunc_to_full(one_slice, N, rad)), original_corr_img=np.log(projector.trunc_to_full(corr_slice, N, rad)), save_animation=save_animation, animation_name=animation_name ) else: diff_real, diff_imag = calc_difference(one_slice, rot_slices) corr_diff_real, corr_diff_imag = calc_difference(corr_slice, corr_rot_slices) vis_fourier_space_comparison( projector.trunc_to_full(rot_slices, N, rad), projector.trunc_to_full(corr_rot_slices, N, rad), diff_real, diff_imag, corr_diff_real, corr_diff_imag, original_img=projector.trunc_to_full(one_slice, N, rad), original_corr_img=projector.trunc_to_full(corr_slice, N, rad), save_animation=save_animation, animation_name=animation_name )
def speed_benchmark_comparison(model): if isinstance(model, np.ndarray): N = model.shape[0] rad_list = np.arange(0.1, 1+0.1, step=0.1) ea, EAs = gen_EAs_randomly(num_inplane_angles=1000) num_rads = rad_list.shape[0] num_test = 100 old_time = np.zeros((num_rads, num_test)) new_time = np.zeros((num_rads, num_test)) proj = projector.project(model, ea, rad=1) for i, rad in enumerate(rad_list): trunc_proj = projector.full_to_trunc(proj, rad) for j in range(num_test): tic = time.time() corr_trunc_proj = correlation.calc_angular_correlation(trunc_proj, N, rad) new_time[i, j] = time.time() - tic for j in range(num_test): tic = time.time() corr_proj = correlation.get_corr_img(proj, rad=rad) old_time[i, j] = time.time() - tic average_new_time = new_time.mean(axis=1) average_old_time = old_time.mean(axis=1) fig, ax = plt.subplots() ax.plot(rad_list, average_old_time, label='generate corr image in traditional way') ax.plot(rad_list, average_new_time, label='new algorithm for corr image') ax.legend(frameon=False) ax.set_ylabel('time (s)') ax.set_xlabel('radius (ratio)') ax.set_title('New vs Old') fig.savefig('speedup.png', dpi=300) plt.show()