|
14 | 14 | `projected_y_BBPS`.
|
15 | 15 | '''
|
16 | 16 |
|
| 17 | +from astropy.convolution import Gaussian2DKernel, convolve_fft |
17 | 18 | from cluster_toolkit import _dcast, _lib
|
18 | 19 | import numpy as np
|
19 | 20 | from scipy.integrate import quad
|
@@ -268,6 +269,85 @@ def projected_y_BBPS(r, M, z, omega_b, omega_m,
|
268 | 269 | epsrel=epsrel)
|
269 | 270 |
|
270 | 271 |
|
| 272 | +def create_image(fn, theta=15, n=200): |
| 273 | + xs, ys = np.meshgrid(range(n), range(n)) |
| 274 | + midpt = (n - 1) / 2 |
| 275 | + rs = (theta / midpt) * np.sqrt((xs - midpt)**2 + (ys - midpt)**2) |
| 276 | + y = fn(rs.flatten()).reshape(rs.shape) |
| 277 | + return rs, y |
| 278 | + |
| 279 | + |
| 280 | +def create_convolved_profile(fn, theta=15, n=200, |
| 281 | + sigma=5 / np.sqrt(2 * np.log(2))): |
| 282 | + ''' |
| 283 | + Convolves the profile `fn` with a gaussian with std == `sigma`, and returns |
| 284 | + the new 1D profile. |
| 285 | +
|
| 286 | + Args: |
| 287 | + fn (function): The function to be convolved. Should accept an array. \ |
| 288 | + Should take a single variable with units of `theta`. |
| 289 | + theta (float): Half-width of the image. i.e., for a 30 x 30 arcmin \ |
| 290 | + image centered on radius = 0, use theta = 15. \ |
| 291 | + (The units are not necessarily arcmin, but whatever the \ |
| 292 | + argument to `fn` uses.) |
| 293 | + n (int): The side length of the image, in pixels. The convolution is \ |
| 294 | + performed on an n x n image. |
| 295 | + sigma (float): The standard deviation of the Gaussian beam, in the \ |
| 296 | + same units as `theta`. The default is the Planck beam, \ |
| 297 | + in arcmin. |
| 298 | +
|
| 299 | + Returns: |
| 300 | + (array, array): Radii and convolved profile. Each array is size n // 2. |
| 301 | + ''' |
| 302 | + rs, img = create_image(fn, theta, n) |
| 303 | + kernel = Gaussian2DKernel(sigma * (n / 2) / theta) |
| 304 | + convolved = convolve_fft(img, kernel) |
| 305 | + return np.diag(rs)[n//2:], np.diag(convolved)[n//2:] |
| 306 | + |
| 307 | + |
| 308 | +def convolved_y_BBPS(M, z, omega_b, omega_m, da, |
| 309 | + theta=15, n=200, |
| 310 | + sigma=5 / np.sqrt(2 * np.log(2)), |
| 311 | + params_P_0=__BBPS_params_P_0, |
| 312 | + params_x_c=__BBPS_params_x_c, |
| 313 | + params_beta=__BBPS_params_beta, |
| 314 | + alpha=1, gamma=-0.3, |
| 315 | + delta=200, |
| 316 | + Xh=0.76, epsrel=1e-3): |
| 317 | + ''' |
| 318 | + Create an observed Compton-y profile of a halo by convolving it with |
| 319 | + a Gaussian beam function. |
| 320 | +
|
| 321 | + Args: |
| 322 | + r (float or array): Radius from the cluster center, in Mpc. |
| 323 | + M (float): Cluster :math:`M_{\\Delta}`, in Msun. |
| 324 | + z (float): Cluster redshift. |
| 325 | + omega_b (float): Baryon fraction. |
| 326 | + omega_m (float): Matter fraction. |
| 327 | + theta (float): Half-width of the convolved image, in arcmin. |
| 328 | + n (int): The side length of the image, in pixels. The convolution is \ |
| 329 | + performed on an n x n image. |
| 330 | + sigma (float): The standard deviation of the Gaussian beam, in the \ |
| 331 | + same units as `theta`. The default is the Planck beam, \ |
| 332 | + in arcmin. |
| 333 | + Xh (float): Primordial hydrogen mass fraction. |
| 334 | +
|
| 335 | + Returns: |
| 336 | + (2-tuple of array): Pair of (rs, smoothed ys). |
| 337 | + ''' |
| 338 | + def image_func(thetas): |
| 339 | + return projected_y_BBPS(thetas * da / 60 * np.pi / 180, |
| 340 | + M, z, |
| 341 | + omega_b, omega_m, |
| 342 | + params_P_0=params_P_0, |
| 343 | + params_x_c=params_x_c, |
| 344 | + params_beta=params_beta, |
| 345 | + alpha=alpha, gamma=gamma, |
| 346 | + delta=delta, |
| 347 | + Xh=Xh, epsrel=epsrel) |
| 348 | + return create_convolved_profile(image_func, theta=theta, n=n, sigma=sigma) |
| 349 | + |
| 350 | + |
271 | 351 | ##################################################
|
272 | 352 | # The following functions are for testing only!! #
|
273 | 353 | ##################################################
|
|
0 commit comments