classy-szfast 0.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,150 @@
1
+ from .utils import *
2
+ from .config import *
3
+ from scipy.interpolate import RectBivariateSpline
4
+
5
+
6
+ # this code is adapted from cobaya
7
+ class PowerSpectrumInterpolator(RectBivariateSpline):
8
+ r"""
9
+ 2D spline interpolation object (scipy.interpolate.RectBivariateSpline)
10
+ to evaluate matter power spectrum as function of z and k.
11
+
12
+ *This class is adapted from CAMB's own P(k) interpolator, by Antony Lewis;
13
+ it's mostly interface-compatible with the original.*
14
+
15
+ :param z: values of z for which the power spectrum was evaluated.
16
+ :param k: values of k for which the power spectrum was evaluated.
17
+ :param P_or_logP: Values of the power spectrum (or log-values, if logP=True).
18
+ :param logP: if True (default: False), log of power spectrum are given and used
19
+ for the underlying interpolator.
20
+ :param logsign: if logP is True, P_or_logP is log(logsign*Pk)
21
+ :param extrap_kmax: if set, use power law extrapolation beyond kmax up to
22
+ extrap_kmax; useful for tails of integrals.
23
+ """
24
+
25
+ def __init__(self, z, k, P_or_logP, extrap_kmin=1e-5, extrap_kmax=1e2, logP=False,
26
+ logsign=1):
27
+ self.islog = logP
28
+ # Check order
29
+ z, k = (np.atleast_1d(x) for x in [z, k])
30
+ if len(z) < 4:
31
+ raise ValueError('Require at least four redshifts for Pk interpolation.'
32
+ 'Consider using Pk_grid if you just need a small number'
33
+ 'of specific redshifts (doing 1D splines in k yourself).')
34
+ z, k, P_or_logP = np.array(z), np.array(k), np.array(P_or_logP)
35
+ i_z = np.argsort(z)
36
+ i_k = np.argsort(k)
37
+ self.logsign = logsign
38
+ self.z, self.k, P_or_logP = z[i_z], k[i_k], P_or_logP[i_z, :][:, i_k]
39
+ self.zmin, self.zmax = self.z[0], self.z[-1]
40
+ self.extrap_kmin, self.extrap_kmax = extrap_kmin, extrap_kmax
41
+ logk = np.log(self.k)
42
+ # Start from extrap_kmin using a (log,log)-linear extrapolation
43
+ if extrap_kmin and extrap_kmin < self.input_kmin:
44
+ if not logP:
45
+ raise ValueError('extrap_kmin must use logP')
46
+ logk = np.hstack(
47
+ [np.log(extrap_kmin),
48
+ np.log(self.input_kmin) * 0.1 + np.log(extrap_kmin) * 0.9, logk])
49
+ logPnew = np.empty((P_or_logP.shape[0], P_or_logP.shape[1] + 2))
50
+ logPnew[:, 2:] = P_or_logP
51
+ diff = (logPnew[:, 3] - logPnew[:, 2]) / (logk[3] - logk[2])
52
+ delta = diff * (logk[2] - logk[0])
53
+ logPnew[:, 0] = logPnew[:, 2] - delta
54
+ logPnew[:, 1] = logPnew[:, 2] - delta * 0.9
55
+ P_or_logP = logPnew
56
+ # Continue until extrap_kmax using a (log,log)-linear extrapolation
57
+ if extrap_kmax and extrap_kmax > self.input_kmax:
58
+ if not logP:
59
+ raise ValueError('extrap_kmax must use logP')
60
+ logk = np.hstack(
61
+ [logk, np.log(self.input_kmax) * 0.1 + np.log(extrap_kmax) * 0.9,
62
+ np.log(extrap_kmax)])
63
+ logPnew = np.empty((P_or_logP.shape[0], P_or_logP.shape[1] + 2))
64
+ logPnew[:, :-2] = P_or_logP
65
+ diff = (logPnew[:, -3] - logPnew[:, -4]) / (logk[-3] - logk[-4])
66
+ delta = diff * (logk[-1] - logk[-3])
67
+ logPnew[:, -1] = logPnew[:, -3] + delta
68
+ logPnew[:, -2] = logPnew[:, -3] + delta * 0.9
69
+ P_or_logP = logPnew
70
+ super().__init__(self.z, logk, P_or_logP)
71
+
72
+ @property
73
+ def input_kmin(self):
74
+ """Minimum k for the interpolation (not incl. extrapolation range)."""
75
+ return self.k[0]
76
+
77
+ @property
78
+ def input_kmax(self):
79
+ """Maximum k for the interpolation (not incl. extrapolation range)."""
80
+ return self.k[-1]
81
+
82
+ @property
83
+ def kmin(self):
84
+ """Minimum k of the interpolator (incl. extrapolation range)."""
85
+ if self.extrap_kmin is None:
86
+ return self.input_kmin
87
+ return self.extrap_kmin
88
+
89
+ @property
90
+ def kmax(self):
91
+ """Maximum k of the interpolator (incl. extrapolation range)."""
92
+ if self.extrap_kmax is None:
93
+ return self.input_kmax
94
+ return self.extrap_kmax
95
+
96
+ def check_ranges(self, z, k):
97
+ """Checks that we are not trying to extrapolate beyond the interpolator limits."""
98
+ z = np.atleast_1d(z).flatten()
99
+ min_z, max_z = min(z), max(z)
100
+ if min_z < self.zmin and not np.allclose(min_z, self.zmin):
101
+ print(
102
+ f"Not possible to extrapolate to z={min(z)} "
103
+ f"(minimum z computed is {self.zmin}).")
104
+ if max_z > self.zmax and not np.allclose(max_z, self.zmax):
105
+ print(
106
+ f"Not possible to extrapolate to z={max(z)} "
107
+ f"(maximum z computed is {self.zmax}).")
108
+ k = np.atleast_1d(k).flatten()
109
+ min_k, max_k = min(k), max(k)
110
+ if min_k < self.kmin and not np.allclose(min_k, self.kmin):
111
+ raise print(
112
+ f"Not possible to extrapolate to k={min(k)} 1/Mpc "
113
+ f"(minimum k possible is {self.kmin} 1/Mpc).")
114
+ if max_k > self.kmax and not np.allclose(max_k, self.kmax):
115
+ print(
116
+ f"Not possible to extrapolate to k={max(k)} 1/Mpc "
117
+ f"(maximum k possible is {self.kmax} 1/Mpc).")
118
+
119
+ def P(self, z, k, grid=None):
120
+ """
121
+ Get the power spectrum at (z,k).
122
+ """
123
+ self.check_ranges(z, k)
124
+ if grid is None:
125
+ grid = not np.isscalar(z) and not np.isscalar(k)
126
+ if self.islog:
127
+ return self.logsign * np.exp(self(z, np.log(k), grid=grid, warn=False))
128
+ else:
129
+ return self(z, np.log(k), grid=grid, warn=False)
130
+
131
+ def logP(self, z, k, grid=None):
132
+ """
133
+ Get the log power spectrum at (z,k). (or minus log power spectrum if
134
+ islog and logsign=-1)
135
+ """
136
+ self.check_ranges(z, k)
137
+ if grid is None:
138
+ grid = not np.isscalar(z) and not np.isscalar(k)
139
+ if self.islog:
140
+ return self(z, np.log(k), grid=grid, warn=False)
141
+ else:
142
+ return np.log(self(z, np.log(k), grid=grid, warn=False))
143
+
144
+ def __call__(self, *args, warn=True, **kwargs):
145
+ if warn:
146
+ print(
147
+ "Do not call the instance directly. Use instead methods P(z, k) or "
148
+ "logP(z, k) to get the (log)power spectrum. (If you know what you are "
149
+ "doing, pass warn=False)")
150
+ return super().__call__(*args, **kwargs)
@@ -0,0 +1,10 @@
1
+ import warnings
2
+ from contextlib import contextmanager
3
+
4
+ @contextmanager
5
+ def suppress_warnings():
6
+ warnings.filterwarnings("ignore")
7
+ try:
8
+ yield
9
+ finally:
10
+ warnings.resetwarnings()
classy_szfast/utils.py ADDED
@@ -0,0 +1,62 @@
1
+ import numpy as np
2
+ from datetime import datetime
3
+ import multiprocessing
4
+ import time
5
+ import functools
6
+ import re
7
+ from pkg_resources import resource_filename
8
+ import os
9
+ from scipy import optimize
10
+ from scipy.integrate import quad
11
+ from scipy.interpolate import interp1d
12
+ import math
13
+ from numpy import linalg as LA
14
+ import mcfit
15
+ from mcfit import P2xi
16
+ import cosmopower
17
+ # import classy_sz as csz
18
+
19
+
20
+
21
+ from scipy.interpolate import LinearNDInterpolator
22
+ from scipy.interpolate import CloughTocher2DInterpolator
23
+
24
+ kb = 1.38064852e-23 #m2 kg s-2 K-1
25
+ clight = 299792458. #m/s
26
+ hplanck=6.62607004e-34 #m2 kg / s
27
+ firas_T0 = 2.728 #pivot temperature used in the Max Lkl Analysis
28
+ firas_T0_bf = 2.725 #best-fitting temperature
29
+
30
+ Tcmb_uk = 2.7255e6
31
+
32
+ G_newton = 6.674e-11
33
+ rho_crit_over_h2_in_GeV_per_cm3 = 1.0537e-5
34
+
35
+
36
+ nu_21_cm_in_GHz = 1./21.1*clight*1.e2/1.e9
37
+ x_21_cm = hplanck*nu_21_cm_in_GHz/kb/firas_T0_bf*1.e9
38
+
39
+ kappa_c = 2.1419 # 4M_2-3M_c see below eq. 9b of https://arxiv.org/pdf/1506.06582.pdf
40
+
41
+ beta_mu = 2.1923
42
+
43
+ G1 = np.pi**2./6
44
+ G2 = 2.4041
45
+ G3 = np.pi**4/15.
46
+ a_rho = G2/G3
47
+ alpha_mu = 2.*G1/3./G2 # = 1/beta_mu = π^2/18ζ(3) see eq. 4.15 CUSO lectures.
48
+
49
+ z_mu_era = 3e5
50
+ z_y_era = 5e4
51
+ z_reio_min = 6
52
+ z_reio_max = 25
53
+ z_recombination_min = 800
54
+ z_recombination_max = 1500
55
+
56
+ # Physical constants
57
+ # ------------------
58
+ # Light speed
59
+ class Const:
60
+ c_km_s = 299792.458 # speed of light
61
+ h_J_s = 6.626070040e-34 # Planck's constant
62
+ kB_J_K = 1.38064852e-23 # Boltzmann constant
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.1
2
+ Name: classy_szfast
3
+ Version: 0.0.3
4
+ Summary: The accelerator of the class_sz code from https://github.com/CLASS-SZ
5
+ Home-page: https://github.com/CLASS-SZ/classy_szfast
6
+ Download-URL: https://github.com/CLASS-SZ/classy_szfast
7
+ Author: Boris Bolliet, Ola Kusiak
8
+ Author-email: bb667@cam.ac.uk, akk2175@columbia.edu
9
+ Maintainer-email: Boris Bolliet <bb667@cam.ac.uk>
10
+ Project-URL: Homepage, https://github.com/CLASS-SZ
11
+ Project-URL: GitHub, https://github.com/CLASS-SZ
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: tensorflow ==2.13.0
14
+ Requires-Dist: tensorflow-probability ==0.21.0
15
+ Requires-Dist: cosmopower
16
+ Requires-Dist: mcfit
17
+
@@ -0,0 +1,17 @@
1
+ classy_szfast/__init__.py,sha256=Mp1HvqeZ9_XmjVkqljBe8qG8vxpDzQt-CzQDlZFmOIU,247
2
+ classy_szfast/classy_sz.py,sha256=AUCJsWFOTUH1zadbfBcCS8coHLKNEvSlvAUV5DQ3xQ0,25834
3
+ classy_szfast/classy_szfast.py,sha256=gpiGm3WLStyhiT-b-s8wUvlxCcdqjMZkVqpVhszkJ0M,32433
4
+ classy_szfast/config.py,sha256=JwRAmdVL44ftwuJyrtuP6tZKmQC_yMJ-WdPustaFIWY,102
5
+ classy_szfast/cosmopower.py,sha256=O9Jorm7st-z7CKLXgAIrIZmVZx5rS2xjiUtkEIDrkpo,7010
6
+ classy_szfast/cosmosis_classy_szfast_interface.py,sha256=zAnxvFtn73a5yS7jgs59zpWFEYKCIQyraYPs5hQ4Le8,11483
7
+ classy_szfast/pks_and_sigmas.py,sha256=drtuujE1HhlrYY1hY92DyY5lXlYS1uE15MSuVI4uo6k,6625
8
+ classy_szfast/suppress_warnings.py,sha256=6wIBml2Sj9DyRGZlZWhuA9hqvpxqrNyYjuz6BPK_a6E,202
9
+ classy_szfast/utils.py,sha256=ZZxujm1yBM0KIeVVLOuoNqUVkXIZt817QDi7U_Fz_IM,1462
10
+ classy_szfast/custom_bias/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ classy_szfast/custom_bias/custom_bias.py,sha256=53RbMAawCurKuI44nqk6fTTkQbbuJDcZpK0YhNQS3j8,486
12
+ classy_szfast/custom_profiles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ classy_szfast/custom_profiles/custom_profiles.py,sha256=4LZwb2XoqwCyWNmW2s24Z7AJdmgVdaRG7yYaBYe-d9Q,1188
14
+ classy_szfast-0.0.3.dist-info/METADATA,sha256=lW_89kHfdNOBwjA4r0Y2iPa8YO-VdEYTrdp1Y-viyog,651
15
+ classy_szfast-0.0.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
16
+ classy_szfast-0.0.3.dist-info/top_level.txt,sha256=hRgqpilUck4lx2KkaWI2y9aCDKqF6pFfGHfNaoPFxv0,14
17
+ classy_szfast-0.0.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ classy_szfast