def scf_density_grid_fast(x, y, z, Smw, Tmw, Slmc, Tlmc, nbins, rs_mw, rs_lmc, lmc_com, quantity, G=1): q_all = np.zeros((nbins, nbins, nbins)) xyz_lmc = np.array([x - lmc_com[0], y - lmc_com[1], z - lmc_com[2]]).T xyz = np.array([x, y, z]).T print(len(xyz_lmc[:, 0])) print(xyz_lmc[:, 0]) if quantity == "density": q_all = biff.density(np.ascontiguousarray(xyz_lmc), Slmc, Tlmc, M=1, r_s=rs_lmc) \ + biff.density(np.ascontiguousarray(xyz), Smw, Tmw, M=1, r_s=rs_mw) if quantity == "potential": q_all = biff.potential(np.ascontiguousarray(xyz_lmc), Slmc, Tlmc, M=1, r_s=rs_lmc, G=G) \ + biff.potential(np.ascontiguousarray(xyz), Smw, Tmw, M=1, r_s=rs_mw, G=G) if quantity == "acceleration": almc = biff.gradient(xyz_lmc, Slmc, Tlmc, M=1, r_s=rs_lmc, G=G) amw = biff.gradient(xyz, Smw, Tmw, M=1, r_s=rs_mw, G=G) q_all = np.sqrt(np.sum(almc**2, axis=1)) + np.sqrt( np.sum(amw**2, axis=1)) return q_all
def combine_bfe_pot(S1, T1, S2, T2, y_grid, z_grid, lmc_com, nbins): pot_mwlmc = np.zeros((nbins, nbins)) for i in range(nbins): for j in range(nbins): pot_mwlmc[i][j] = biff.potential(np.array([[0-lmc_com[0]], [y_grid[0][i]-lmc_com[1]], [z_grid[j,0]-lmc_com[2]]]).T, S2, T2, M=1, r_s=10, G=1) + \ biff.potential(np.array([[0], [y_grid[0][i]], [z_grid[j,0]]]).T, S1, T1, M=1, r_s=40.85, G=1) return pot_mwlmc
def lmc_mw_ratio_potetial(): coeff_c = np.loadtxt('../../SCF_tools/PCA/MWLMC5_coeff_20_20_100M_b1.txt') S = coeff_c[:, 0] T = coeff_c[:, 1] S_matrix = np.zeros((21, 21, 21)) T_matrix = np.zeros((21, 21, 21)) counter = 0 for n in range(21): for l in range(21): for m in range(0, l + 1): S_matrix[n][l][m] = S[counter] T_matrix[n][l][m] = T[counter] counter += 1 ## Reading coefficients coeff_lmc = np.loadtxt('./LMC/coeff_rand_40lmc5_b1_1E6_1.txt') S_lmc = coeff_lmc[:, 0] T_lmc = coeff_lmc[:, 1] S_lmc_1e6 = np.zeros((41, 21, 21)) T_lmc_1e6 = np.zeros((41, 21, 21)) counter = 0 for n in range(41): for l in range(21): for m in range(0, l + 1): S_lmc_1e6[n][l][m] = S_lmc[counter] T_lmc_1e6[n][l][m] = T_lmc[counter] counter += 1 xlmc_com = 1 ylmc_com = -41 zlmc_com = -28 x_grid = np.arange(-300, 300, 5.5) y_grid = np.arange(-300, 300, 5.5) z_grid = np.arange(-300, 300, 5.5) X_grid, Y_grid, Z_grid = np.meshgrid(x_grid, y_grid, z_grid) pot_ratio_all = np.zeros((110, 110, 110)) for i in range(110): for j in range(110): for k in range(110): pot_ratio_all[i][j][k] = biff.potential(np.array([[X_grid[0][i][0]-xlmc_com], [Y_grid[j][0][0]-ylmc_com], [Z_grid[0][0][k]-zlmc_com]]).T, S_lmc_1e6, T_lmc_1e6, M=11.41*1E6,r_s=10, G=1) / \ biff.potential(np.array([[X_grid[0][i][0]], [Y_grid[j][0][0]], [Z_grid[0][0][k]]]).T, S_matrix, T_matrix, M=1, r_s=40.85, G=1) return pot_ratio_all
def relative_pot(S, T, SS, TT, ST, figname, cbar_name): sn = [0, 1, 2, 3, 4, 5] fig = plt.figure(figsize=(10, 14)) for i in range(len(sn)): S_smooth, T_smooth, N_smooth = coefficients_smoothing.smooth_coeff_matrix( S, T, SS, TT, ST, mass, 20, 20, 20, sn[i]) pot_biff = biff.potential(np.ascontiguousarray(xyz), S_smooth, T_smooth, M=1, r_s=40.85, G=1) pot_biff_0 = biff.potential(np.ascontiguousarray(xyz), np.array([[[S_smooth[0, 0, 0]], [0], [0]]]).T, np.array([[[T_smooth[0, 0, 0]], [0], [0]]]).T, M=1, r_s=40.85, G=1) plt.subplot(3, 2, i + 1) #levels = np.arange(-4, -1, 0.1) im = plt.contourf(y_grid, z_grid, ((pot_biff / pot_biff_0) - 1).reshape(bins, bins), 40, origin='lower', cmap='inferno') plt.text(-180, 160, 'Ncoeff={}'.format(N_smooth), color='w') plt.text(-180, 130, 'S/N={}'.format(sn[i]), color='w') plt.xlim(-200, 200) plt.ylim(-200, 200) if ((i == 4) | (i == 5)): plt.xlabel('y[kpc]') if (i + 1) % 2 == 1: plt.ylabel('z[kpc]') cb_ax = fig.add_axes([0.93, 0.1, 0.02, 0.8]) cbar = plt.colorbar(im, cax=cb_ax) fig.suptitle('Relative potential of MW + LMC unbound particles {}'.format( cbar_name), y=0.93) cbar.set_label('$\Delta \Phi$') plt.savefig(figname + '.pdf', bbox_inches='tight') plt.savefig(figname + '.png', bbox_inches='tight') return 0
def scf_density_grid(x, y, z, Smw, Tmw, Slmc, Tlmc, nbins, rs_mw, rs_lmc, lmc_com, quantity, G=1): q_all = np.zeros((nbins, nbins, nbins)) for i in range(nbins): for j in range(nbins): for k in range(nbins): # These line is flipping x with y! xyz_lmc = np.array([[x[0, i, 0] - lmc_com[0]], [y[j, 0, 0] - lmc_com[1]], [z[0, 0, k] - lmc_com[2]]]).T xyz = np.array([[x[0, i, 0]], [y[j, 0, 0]], [z[0, 0, k]]]).T if quantity == "density": q_all[i][j][k] = \ biff.density(xyz_lmc, Slmc, Tlmc, M=1, r_s=rs_lmc) \ + biff.density(xyz, Smw, Tmw, M=1, r_s=rs_mw) if quantity == "potential": q_all[i][j][k] = \ biff.potential(np.ascontiguousarray(xyz_lmc), Slmc, Tlmc, M=1, r_s=rs_lmc, G=G) \ + biff.potential(np.ascontiguousarray(xyz), Smw, Tmw, M=1, r_s=rs_mw, G=G) if quantity == "acceleration": almc = biff.gradient(xyz_lmc, Slmc, Tlmc, M=1, r_s=rs_lmc, G=G) amw = biff.gradient(xyz, Smw, Tmw, M=1, r_s=rs_mw, G=G) q_all[i][j][k] = np.sqrt(np.sum(almc**2)) \ + np.sqrt(np.sum(amw**2)) return q_all.flatten()
def BFE_potential(pos, Snlm, Tnlm, true_M, true_r_s, G): """ Computes the density profile of the BFE """ pot_bfe = biff.potential(np.ascontiguousarray(pos.astype(np.double)), Snlm, Tnlm, G, true_M, true_r_s) return pot_bfe
def scf_potential(x_grid, y_grid, z_grid, S, T, r_s_mw): xyz = np.ascontiguousarray( np.double( np.array([x_grid.flatten(), y_grid.flatten(), z_grid.flatten()]).T)) pot_ratio_all = biff.potential(xyz, S, T, M=1, r_s=r_s_mw, G=1) return dens_ratio_all
def compute_scf_pot(pos, rs, nmax, lmax, mass): """ TODO: Parallelize this function here! """ G_gadget = 43007.1 S, T = biff.compute_coeffs_discrete( np.ascontiguousarray(pos).astype(float), mass, nmax, lmax, rs) LMC_potential = biff.potential(np.ascontiguousarray(pos).astype(float), S, T, M=1, r_s=rs, G=G_gadget) return LMC_potential
def BFE_potential_profile(pos, Snlm, Tnlm, true_M, true_r_s, G, rmax, nbins=20): """ Computes the density profile of the BFE """ pot_bfe = biff.potential(np.ascontiguousarray(pos.astype(np.double)), Snlm, Tnlm, G, true_M, true_r_s) r = (pos[:, 0]**2 + pos[:, 1]**2 + pos[:, 2]**2)**0.5 r_bins = np.linspace(0.01, rmax, nbins) pot_bins = np.zeros(len(r_bins)) for i in range(len(pot_bins) - 1): index_c = np.where((r < r_bins[i + 1]) & (r >= r_bins[i]))[0] pot_bins[i] = np.mean(pot_bfe[index_c]) dr = (r_bins[1] - r_bins[0]) / 2. return r_bins + dr, pot_bins