def gal_power_discrete(model): # set up fake 1D k, mu bins k_1d = numpy.arange(0.01, 0.4, 0.005) mu_1d = numpy.linspace(0, 1.0, 100) # convert to a 2D grid # shape is (78, 100) k, mu = numpy.meshgrid(k_1d, mu_1d, indexing='ij') # assign random weights for each bin for illustration purposes modes = numpy.random.random(size=k.shape) # simulate missing data missing = numpy.random.randint(0, numpy.prod(modes.shape), size=10) modes.flat[missing] = numpy.nan # initialize the grid grid = PkmuGrid([k_1d, mu_1d], k, mu, modes) # edges of the mu bins mu_bounds = [(0., 0.2), (0.2, 0.4), (0.4, 0.6), (0.6, 0.8), (0.8, 1.0)] # the transfer function, with specified valid k range transfer = PkmuTransfer(grid, mu_bounds, kmin=0.01, kmax=0.4) # evaluate the model with this transfer function Pkmu_binned = model.from_transfer(transfer) # get the coordinate arrays from the grid k, mu = transfer.coords # this has shape of (Nk, Nmu) for i in range(mu.shape[1]): plt.loglog(k[:, i], Pkmu_binned[:, i], label=r"$\mu = %.1f$" % mu[:, i].mean()) plt.legend(loc=0) plt.xlabel(r"$k$ $[h \mathrm{Mpc}^{-1}]$", fontsize=10) plt.ylabel(r"$P$ $[h^{-3} \mathrm{Mpc}^3]$", fontsize=10) savefig("pkmu_binned_plot.png") # the multipoles to compute ells = [0, 2, 4] # the transfer function, with specified valid k range transfer = PolesTransfer(grid, ells, kmin=0.01, kmax=0.4) # evaluate the model with this transfer function poles_binned = model.from_transfer(transfer) # shape is (78, 3) # get the coordinate arrays from the grid k, mu = transfer.coords # this has shape of (Nk, Nmu) for i, iell in enumerate(ells): plt.loglog(k[:, i], poles_binned[:, i], label=r"$\ell = %d$" % iell) plt.legend(loc=0) plt.xlabel(r"$k$ $[h \mathrm{Mpc}^{-1}]$", fontsize=10) plt.ylabel(r"$P_\ell$ $[h^{-3} \mathrm{Mpc}^3]$", fontsize=10) savefig("poles_binned_plot.png")