def miscentering(density_model): return maszcal.lensing.Miscentering( rho_func=density_model.rho_tot, misc_distrib=maszcal.stats.MiscenteringDistributions. rayleigh_dist, miscentering_func=meso.Rho().miscenter, )
def miscentering(density_model): return maszcal.lensing.Miscentering( rho_func=density_model.rho_tot, misc_distrib=maszcal.stats.MiscenteringDistributions. rayleigh_dist, miscentering_func=meso.Rho( num_offset_radii=40, num_phis=10, ).miscenter, )
def it_takes_a_density_function_and_creates_a_miscentered_version(miscentering): rs = np.logspace(-2, 2, 30) param_1 = np.ones(3) param_2 = np.ones(2) rho_params = (param_1, param_2) miscenter_model = meso.Rho() ul = miscenter_model.max_radius ll = miscenter_model.min_radius interval = ul - ll misc_params = (np.array([1/interval, 1/interval]), np.array([0.5, 0.5])) rho_cents = rho_with_analytic_result(rs, param_1, param_2) rho_miscs = miscentering.rho(rs, misc_params, rho_params).squeeze() analytical_answer = 1/3 * (ll**2 + ul**2 + ul*ll + 3*rs**2) analytical_answer = analytical_answer[:, None, None] * param_1[None, :, None] * param_2[None, None, :] analytical_answer = rho_cents/2 + analytical_answer/2 assert np.allclose(rho_miscs, analytical_answer, rtol=1e-3)
def it_matches_a_monte_carlo_miscentered_profile(radial_grid, density, rng): rho_func = scipy.interpolate.interp1d(radial_grid, density, kind='cubic') rs = np.geomspace(0.01, 100, 100) offsets = rng.rayleigh(scale=SCALE, size=NUM_MC) phis = 2 * np.pi * rng.random(size=NUM_MC) rho_arg = get_arg(rs, offsets, phis) idx = np.argwhere(rho_arg < radial_grid.min()) rho_arg = np.delete(rho_arg, idx[:, 1:], axis=1) plt.hist( np.log(np.repeat(rs, NUM_MC)), bins=48, histtype='stepfilled', color='black', alpha=0.8, label='radius', ) plt.hist( np.log(rho_arg).flatten(), bins=48, color=COLORS[0], histtype='stepfilled', alpha=0.8, label='miscentered radius', ) plt.xlabel(r'$\ln(r)$') plt.ylabel('number') plt.legend(loc='best') plt.gcf().set_size_inches(6, 4) plt.savefig(PLOT_DIR + 'radius_hist.svg', bbox_inches='tight') plt.gcf().clear() rhos = rho_func(rs) rhos_mc = rho_func(rho_arg).mean(axis=(1)) meso_rhos_coarse = meso.Rho( num_offset_radii=50, num_phis=4, ).miscenter(rs, rho_func, prob_dist_func=rayleigh_dist) meso_rhos_medium = meso.Rho( num_offset_radii=100, num_phis=12, ).miscenter(rs, rho_func, prob_dist_func=rayleigh_dist) meso_rhos_fine = meso.Rho( num_offset_radii=200, num_phis=36, ).miscenter(rs, rho_func, prob_dist_func=rayleigh_dist) plt.plot(rs, rhos, color='black', label='centered') plt.plot(rs, meso_rhos_coarse, color=COLORS[1], alpha=0.8, linestyle=':', label='coarse') plt.plot(rs, meso_rhos_medium, color=COLORS[1], alpha=0.8, linestyle='--', label='medium') plt.plot(rs, meso_rhos_fine, color=COLORS[1], alpha=0.8, linestyle='-', label='fine') plt.plot(rs, rhos_mc, color=COLORS[0], alpha=0.8, label='Monte Carlo') plt.xscale('log') plt.yscale('log') plt.xlabel(r'$r$ (Mpc)') plt.ylabel(r'$\rho(r)$') plt.legend(loc='best') plt.gcf().set_size_inches(6, 4) plt.savefig(PLOT_DIR + 'rho_comparison.svg', bbox_inches='tight') plt.gcf().clear() plt.plot(rs, rs**2 * rhos, color='black', label='centered') plt.plot(rs, rs**2 * meso_rhos_coarse, color=COLORS[1], alpha=0.8, linestyle=':', label='coarse') plt.plot(rs, rs**2 * meso_rhos_medium, color=COLORS[1], alpha=0.8, linestyle='--', label='medium') plt.plot(rs, rs**2 * meso_rhos_fine, color=COLORS[1], alpha=0.8, linestyle='-', label='fine') plt.plot(rs, rs**2 * rhos_mc, color=COLORS[0], alpha=0.8, label='Monte Carlo') plt.xscale('log') plt.xlabel(r'$r$ (Mpc)') plt.ylabel(r'$r^2 \rho(r)$') plt.legend(loc='best') plt.gcf().set_size_inches(6, 4) plt.savefig(PLOT_DIR + 'rho_comparison_scaled.svg', bbox_inches='tight') plt.gcf().clear()
def miscentering(): return core.Miscentering( rho_func=rho_with_analytic_result, misc_distrib=prob_dist_func, miscentering_func=meso.Rho().miscenter, )
def miscenter_model(): return meso.Rho()
def miscenter_model(): return meso.Rho( num_offset_radii=50, num_phis=4, )