pynkowski.theory.bak_theory
1import numpy as np 2import scipy.stats 3 4norm = scipy.stats.norm() 5 6 7def get_μ(cls): 8 """Compute the first derivative of the covariance function at the origin for a Gaussian field 9 defined on the sphere with angular power spectrum 'cls'. 10 11 Parameters 12 ---------- 13 cls : np.array 14 The angular power spectrum of the Gaussian field. 15 16 Returns 17 ------- 18 μ : float 19 The first derivative of the covariance function of a field at the origin. 20 21 """ 22 cls = np.array(cls, dtype=float) 23 ℓ = np.arange(cls.shape[0]) 24 cls /= np.sum(cls * (2.*ℓ+1.) / (4.*np.pi)) 25 μ = np.sum(cls * (2.*ℓ+1.) * ℓ*(ℓ+1.) / (8.*np.pi)) 26 return μ 27 28def V0_th_s0(u): 29 """Compute the expected value of the normalised first MF v0 at threshold u for a Gaussian isotropic scalar field normalised for its standard deviation. 30 31 Parameters 32 ---------- 33 u : np.array 34 Thresholds at which the first MF is computed. 35 36 Returns 37 ------- 38 v0 : np.array 39 The expected value of the normalised first MF at thresholds u. 40 41 """ 42 return (1-norm.cdf(u)) 43 44def V0_th_P2(u): 45 """Compute the expected value of the normalised first MF v0 at threshold u for the sum of two squared Gaussian isotropic fields normalised for their standard deviations. 46 47 Parameters 48 ---------- 49 u : np.array 50 Thresholds at which the first MF is computed. 51 52 Returns 53 ------- 54 v0 : np.array 55 The expected value of the normalised first MF at thresholds u. 56 57 """ 58 return 1-((1-np.exp(-u/2.)) * (u>=0.)) 59 60def V0_th_s2(u): 61 """Compute the expected value of the normalised first MF v0 at threshold u for a Gaussian field defined in SO(3) normalised for its standard deviation. 62 63 Parameters 64 ---------- 65 u : np.array 66 Thresholds at which the first MF is computed. 67 68 Returns 69 ------- 70 v0 : np.array 71 The expected value of the normalised first MF at thresholds u. 72 73 """ 74 return (1-norm.cdf(u)) 75 76def V1_th_s0(u, μ): 77 """Compute the expected value of the normalised second MF v1 at threshold u for a Gaussian isotropic scalar field normalised for its standard deviation. 78 79 Parameters 80 ---------- 81 u : np.array 82 Thresholds at which the second MF is computed. 83 84 μ : float 85 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 86 87 Returns 88 ------- 89 v1 : np.array 90 The expected value of the normalised second MF at thresholds u. 91 92 """ 93 return np.sqrt(μ) * np.exp(-u**2./2.) / 8. 94 95def V1_th_P2(u, μ): 96 """Compute the expected value of the normalised second MF v1 at threshold u for the sum of two squared Gaussian isotropic fields normalised for their standard deviations. 97 98 Parameters 99 ---------- 100 u : np.array 101 Thresholds at which the second MF is computed. 102 103 μ : float 104 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 105 106 Returns 107 ------- 108 v1 : np.array 109 The expected value of the normalised second MF at thresholds u. 110 111 """ 112 return np.sqrt(μ * (u) / 4.) * np.exp(-u/2.) * (u>=0.) * (np.sqrt(np.pi/8.)) 113 114def V1_th_s2(u, μ): 115 """Compute the expected value of the normalised second MF v1 at thresholds u for a Gaussian field defined in SO(3) normalised for its standard deviation. 116 117 Parameters 118 ---------- 119 u : np.array 120 Thresholds at which the second MF is computed. 121 122 μ : float 123 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 124 125 Returns 126 ------- 127 v1 : np.array 128 The expected value of the normalised second MF at thresholds u. 129 130 """ 131 return 2.*np.sqrt(2*np.pi**3 *μ) * norm.pdf(u) / (4*np.pi**2) 132 133def V2_th_s0(u, μ): 134 """Compute the expected value of the normalised third MF v2 at threshold u for a Gaussian isotropic scalar field normalised for its standard deviation. 135 136 Parameters 137 ---------- 138 u : np.array 139 Thresholds at which the third MF is computed. 140 141 μ : float 142 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 143 144 Returns 145 ------- 146 v2 : np.array 147 The expected value of the normalised third MF at thresholds u. 148 149 """ 150 return μ * u * np.exp(-u**2. /2.) / np.sqrt(2.*np.pi)**3. 151 152def V2_th_P2(u, μ): 153 """Compute the expected value of the normalised third MF v2 at threshold u for the sum of two squared Gaussian isotropic fields normalised for their standard deviations. 154 155 Parameters 156 ---------- 157 u : np.array 158 Thresholds at which the third MF is computed. 159 160 μ : float 161 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 162 163 Returns 164 ------- 165 v2 : np.array 166 The expected value of the normalised third MF at thresholds u. 167 168 """ 169 return (((μ * (u-1.) * np.exp(-u/2.)) / (2.*np.pi) ) * (u>=0.)) 170 171def V2_th_s2(u, μ): 172 """Compute the expected value of the normalised third MF v2 at threshold u for a Gaussian field defined in SO(3) normalised for its standard deviation. 173 174 Parameters 175 ---------- 176 u : np.array 177 Thresholds at which the third MF is computed. 178 179 μ : float 180 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 181 182 Returns 183 ------- 184 v2 : np.array 185 The expected value of the normalised third MF at thresholds u. 186 187 """ 188 return (((1-norm.cdf(u)) * 3.*np.pi + u*norm.pdf(u) * μ * 4.*np.pi) / (4*np.pi**2)) / (6.*np.pi) #This has a ratio of ~0.13 189 190def V3_th_s2(u, μ): 191 """Compute the expected value of the normalised fourth MF v3 at threshold u for a Gaussian field defined in SO(3) normalised for its standard deviation. 192 193 Parameters 194 ---------- 195 u : np.array 196 Threshold at which the fourth MF is computed. 197 198 μ : float 199 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 200 201 Returns 202 ------- 203 v3 : np.array 204 The expected value of the normalised fourth MF at threshold u. 205 206 """ 207 return μ*np.exp(-u**2. /2.) * (u**2. -1.) / 8 208 209def define_mu(cls,μ): 210 """Return the first derivative of the covariance function at the origin for a field 211 computed accordingly to which input variable is given. 212 213 Parameters 214 ---------- 215 cls : np.array, optional 216 The angular power spectrum of the field. 217 Default : None 218 219 μ : scalar, optional 220 The first derivative of the covariance function at the origin for the field. If None, μ=1 is assumed. 221 Default : None 222 223 Returns 224 ------- 225 μ : scalar 226 The first derivative of the covariance function of the field at the origin. 227 228 Notes 229 ----- 230 The derivatives are always computed full-sky regardless of input mask. 231 232 """ 233 if (cls is not None) and (μ is not None): 234 raise ValueError(r"Both cls and $\mu$ cannot be given") 235 if (cls is not None) and (μ is None): 236 return get_μ(cls) 237 if (cls is None) and (μ is not None): 238 return μ 239 if (cls is None) and (μ is None): 240 return 1. 241 242def define_us_for_V(us,dus,iters=1000): 243 """Return the thresholds where MFs (except for v0) are computed before averaging within the bins 'dus'. 244 245 Parameters 246 ---------- 247 us : np.array 248 The thresholds at which MFs have to be computed. 249 250 dus : np.array 251 The width of the bins associated to the thresholds 'us'. 252 253 iters : int, optional 254 the number of thresholds to consider within each bin. 255 256 Returns 257 ------- 258 us_ : np.array 259 The sequence of thresholds where MFs are computed before averaging within each bin, with shape (us.shape, iters) 260 261 iters : int, optional 262 the number of thresholds considered within each bin. 263 264 """ 265 return np.vstack([np.linspace(u-du/2, u+du/2, iters) for u, du in zip(us, dus)]) 266 267 268 269 270 271 272 273 274class TheoryTemperature(): 275 """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field normalised for its standard deviation defined on the sphere 276 like the temperature anisotropies of the CMB. 277 278 Parameters 279 ---------- 280 us : np.array, optional 281 The thresholds at which the theoretical MFs will be computed. 282 If not given, a range between -5σ and 5σ with steps of 0.1σ is considered, 283 with σ=1 the expected standard deviation of the field. 284 285 cls : np.array, optional 286 The angular power spectrum of the Gaussian isotropic scalar field. 287 Default : None 288 289 μ : float, optional 290 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 291 If both μ and cls are given, an error will be raised. 292 If only cls is given, μ will be computed from input cls. 293 If neither μ nor cls are given, μ is assumed to be 1. 294 Default : None 295 296 average_bin : bool, optional 297 If True, the results of V1 and V2 are the average on each bin, to be compared with binned computations on maps. 298 If False, the results are the evaluation on the center of each bin. 299 The value is always exactly computed for V0, as the computation on maps does not imply binning. 300 Defaul : True 301 302 edges : bool, optional 303 If False, the given 'us' is considered as an array of uniformly distributed thresholds. 304 If True, input 'us' is considered as a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform distributions of thresholds. 305 In this last case, the thresholds are the central value of the given bins. 306 Neglected if 'us' is not given. 307 Default : False. 308 309 Attributes 310 ---------- 311 us : np.array 312 The thresholds at which the theoretical MFs are computed. 313 314 μ : float 315 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 316 317 """ 318 def __init__(self, us=None, cls=None, μ=None, average_bin=True, edges=False): 319 """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere. 320 321 """ 322 if (us is None): 323 Δu = 0.1 324 self.us = np.arange(-5+Δu/2., 5.+Δu/2., Δu) 325 self.dus = Δu*np.ones(self.us.shape[0]) 326 else: 327 us = np.array(us) 328 if us.shape == (1,): 329 self.us = us 330 self.dus = 0. 331 else: 332 if edges: 333 self.dus = (us[1:]-us[:-1]) 334 self.us = (us[1:]+us[:-1])/2. 335 else: 336 self.us = us 337 self.dus = (us[1]-us[0])*np.ones(us.shape[0]) 338 339 340 self.μ = define_mu(cls,μ) 341 if not average_bin: 342 self.dus = 0.*self.dus 343 344 345 def V0(self): 346 """Compute the expected values of the normalised first MF v0 at the different thresholds us. 347 $$\mathbb{E}[ v_{0} ] =1 -\Phi (u)$$ 348 where $\Phi$ is the cumulative normal distribution. 349 """ 350 return (V0_th_s0(self.us)) 351 352 def V1(self): 353 """Compute the expected values of the normalised second MF v1 at the different thresholds us. 354 355 $$\mathbb{E}[ v_{1}(u) ] = {1 \over 8} \exp{(- {u^2 \over 2})} \mu^{1/2}$$ 356 """ 357 us_ = define_us_for_V(self.us,self.dus) 358 v1_ = V1_th_s0(us_, self.μ) 359 360 return np.mean(v1_, axis=1) 361 362 def V2(self): 363 """Compute the expected values of the normalised third MF v2 at the different thresholds us. 364 365 $$\mathbb{E}[v_{2}(u)] = {2 \over \sqrt{(2\pi)^{3}}} \exp(-{u^{2} \over 2}) u$$ 366 """ 367 us_ = define_us_for_V(self.us,self.dus) 368 v2_ = V2_th_s0(us_, self.μ) 369 370 return np.mean(v2_, axis=1) 371 372 373 374class TheoryP2(): 375 """Class to compute the expected values of Minkowski functionals (MFs) for the sum of two squared Gaussian isotropic fields normalised for their standard deviations defined on the sphere 376 like the polarised intensity of the CMB ($P^2 = Q^2 + U^2$). 377 378 Parameters 379 ---------- 380 us : np.array, optional 381 The thresholds at which the theoretical MFs will be computed. 382 If not given, a range between 0 and 5σ with steps of 0.1σ is considered, 383 with σ=1 the expected standard deviation of the fields U and Q. 384 385 cls : np.array, optional 386 The angular power spectrum associated to the Gaussian isotropic fields. 387 Shape '(..., lmax+1)'. '...' can be 2 (EE, BB) or absent (assumed to be EE+BB). 388 Default : None 389 390 μ : float, optional 391 The derivative of the covariance function at the origin for each of the two independent Gaussian isotropic fields (i.e., U and Q in the cosmological case). 392 If both μ and cls are given, an error will be raised. 393 If only cls is given, μ will be computed from input cls. 394 If neither μ nor cls are given, μ is assumed to be 1. 395 Default : None 396 397 average_bin : bool, optional 398 If True, the results of V1 and V2 are the average on each bin, to be compared with binned computations on maps. 399 If False, the results are the evaluation on the center of each bin. 400 The value is always exactly computed for V0, as the computation on maps does not imply binning. 401 Defaul : True 402 403 edges : bool, optional 404 If False, the given 'us' is considered as an array of uniformly distributed thresholds. 405 If True, input 'us' is considered as a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform distributions of thresholds. 406 In this last case, the thresholds are the central value of the given bins. 407 Neglected if 'us' is not given. 408 Default : False. 409 410 Attributes 411 ---------- 412 us : np.array 413 The thresholds at which the theoretical MFs are computed. 414 415 μ : float 416 The derivative of the covariance function at the origin for the sum of two squared Gaussian isotropic fields. 417 418 """ 419 def __init__(self, us=None, Cls=None, μ=None, average_bin=True, edges=False): 420 """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere. 421 422 """ 423 if (us is None): 424 Δu = 0.05 425 self.us = np.arange(Δu/2., 5.+Δu/2., Δu) 426 self.dus = Δu*np.ones(self.us.shape[0]) 427 else: 428 us = np.array(us) 429 if us.shape == (1,): 430 self.us = us 431 self.dus = 0. 432 else: 433 if edges: 434 self.dus = (us[1:]-us[:-1]) 435 self.us = (us[1:]+us[:-1])/2. 436 else: 437 self.us = us 438 self.dus = (us[1]-us[0])*np.ones(us.shape[0]) 439 440 if (Cls is not None) and (μ is None): 441 if (Cls.ndim == 2) and (Cls.shape[0]==2): 442 cls = (cls[0]+cls[1])/2. 443 elif (Cls.ndim == 1): 444 cls = cls/2. 445 else: 446 raise ValueError(r"Cls dimension has to be either (2,lmax+1) or (lmax+1)") 447 448 self.μ = define_mu(Cls,μ) 449 if not average_bin: 450 self.dus = 0.*self.dus 451 452 453 def V0(self): 454 """Compute the expected values of the normalised first MF v0 at the different thresholds us. 455 456 $$\mathbb{E}[{v_{0}(u)}] = \exp (-u/2)$$ 457 """ 458 return (V0_th_P2(self.us)) 459 460 def V1(self): 461 """Compute the expected values of the normalised second MF v1 at the different thresholds us. 462 463 $$\mathbb{E}[{v_{1}(u)}] = {\sqrt{2\pi } \over 8} \sqrt{\mu u}\exp (-{u \over 2})$$ 464 """ 465 us_ = define_us_for_V(self.us,self.dus) 466 v1_ = V1_th_P2(us_, self.μ) 467 468 return np.mean(v1_, axis=1) 469 470 def V2(self): 471 """Compute the expected values of the normalised third MF v2 at the different thresholds us. 472 473 $$\mathbb{E}[{v_{2}(u)}] = \mu {(u-1)\exp (-u/2) \over 2\pi }$$ 474 """ 475 us_ = define_us_for_V(self.us,self.dus) 476 v2_ = V2_th_P2(us_, self.μ) 477 478 return np.mean(v2_, axis=1) 479 480 481 482 483__all__ = ["get_μ", 484 "TheoryTemperature", 485 "TheoryP2"] 486 487__docformat__ = "numpy"
8def get_μ(cls): 9 """Compute the first derivative of the covariance function at the origin for a Gaussian field 10 defined on the sphere with angular power spectrum 'cls'. 11 12 Parameters 13 ---------- 14 cls : np.array 15 The angular power spectrum of the Gaussian field. 16 17 Returns 18 ------- 19 μ : float 20 The first derivative of the covariance function of a field at the origin. 21 22 """ 23 cls = np.array(cls, dtype=float) 24 ℓ = np.arange(cls.shape[0]) 25 cls /= np.sum(cls * (2.*ℓ+1.) / (4.*np.pi)) 26 μ = np.sum(cls * (2.*ℓ+1.) * ℓ*(ℓ+1.) / (8.*np.pi)) 27 return μ
Compute the first derivative of the covariance function at the origin for a Gaussian field defined on the sphere with angular power spectrum 'cls'.
Parameters
- cls (np.array): The angular power spectrum of the Gaussian field.
Returns
- μ (float): The first derivative of the covariance function of a field at the origin.
275class TheoryTemperature(): 276 """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field normalised for its standard deviation defined on the sphere 277 like the temperature anisotropies of the CMB. 278 279 Parameters 280 ---------- 281 us : np.array, optional 282 The thresholds at which the theoretical MFs will be computed. 283 If not given, a range between -5σ and 5σ with steps of 0.1σ is considered, 284 with σ=1 the expected standard deviation of the field. 285 286 cls : np.array, optional 287 The angular power spectrum of the Gaussian isotropic scalar field. 288 Default : None 289 290 μ : float, optional 291 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 292 If both μ and cls are given, an error will be raised. 293 If only cls is given, μ will be computed from input cls. 294 If neither μ nor cls are given, μ is assumed to be 1. 295 Default : None 296 297 average_bin : bool, optional 298 If True, the results of V1 and V2 are the average on each bin, to be compared with binned computations on maps. 299 If False, the results are the evaluation on the center of each bin. 300 The value is always exactly computed for V0, as the computation on maps does not imply binning. 301 Defaul : True 302 303 edges : bool, optional 304 If False, the given 'us' is considered as an array of uniformly distributed thresholds. 305 If True, input 'us' is considered as a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform distributions of thresholds. 306 In this last case, the thresholds are the central value of the given bins. 307 Neglected if 'us' is not given. 308 Default : False. 309 310 Attributes 311 ---------- 312 us : np.array 313 The thresholds at which the theoretical MFs are computed. 314 315 μ : float 316 The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. 317 318 """ 319 def __init__(self, us=None, cls=None, μ=None, average_bin=True, edges=False): 320 """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere. 321 322 """ 323 if (us is None): 324 Δu = 0.1 325 self.us = np.arange(-5+Δu/2., 5.+Δu/2., Δu) 326 self.dus = Δu*np.ones(self.us.shape[0]) 327 else: 328 us = np.array(us) 329 if us.shape == (1,): 330 self.us = us 331 self.dus = 0. 332 else: 333 if edges: 334 self.dus = (us[1:]-us[:-1]) 335 self.us = (us[1:]+us[:-1])/2. 336 else: 337 self.us = us 338 self.dus = (us[1]-us[0])*np.ones(us.shape[0]) 339 340 341 self.μ = define_mu(cls,μ) 342 if not average_bin: 343 self.dus = 0.*self.dus 344 345 346 def V0(self): 347 """Compute the expected values of the normalised first MF v0 at the different thresholds us. 348 $$\mathbb{E}[ v_{0} ] =1 -\Phi (u)$$ 349 where $\Phi$ is the cumulative normal distribution. 350 """ 351 return (V0_th_s0(self.us)) 352 353 def V1(self): 354 """Compute the expected values of the normalised second MF v1 at the different thresholds us. 355 356 $$\mathbb{E}[ v_{1}(u) ] = {1 \over 8} \exp{(- {u^2 \over 2})} \mu^{1/2}$$ 357 """ 358 us_ = define_us_for_V(self.us,self.dus) 359 v1_ = V1_th_s0(us_, self.μ) 360 361 return np.mean(v1_, axis=1) 362 363 def V2(self): 364 """Compute the expected values of the normalised third MF v2 at the different thresholds us. 365 366 $$\mathbb{E}[v_{2}(u)] = {2 \over \sqrt{(2\pi)^{3}}} \exp(-{u^{2} \over 2}) u$$ 367 """ 368 us_ = define_us_for_V(self.us,self.dus) 369 v2_ = V2_th_s0(us_, self.μ) 370 371 return np.mean(v2_, axis=1)
Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field normalised for its standard deviation defined on the sphere like the temperature anisotropies of the CMB.
Parameters
- us (np.array, optional): The thresholds at which the theoretical MFs will be computed. If not given, a range between -5σ and 5σ with steps of 0.1σ is considered, with σ=1 the expected standard deviation of the field.
- cls (np.array, optional): The angular power spectrum of the Gaussian isotropic scalar field. Default : None
- μ (float, optional): The derivative of the covariance function at the origin for the Gaussian isotropic scalar field. If both μ and cls are given, an error will be raised. If only cls is given, μ will be computed from input cls. If neither μ nor cls are given, μ is assumed to be 1. Default : None
- average_bin (bool, optional): If True, the results of V1 and V2 are the average on each bin, to be compared with binned computations on maps. If False, the results are the evaluation on the center of each bin. The value is always exactly computed for V0, as the computation on maps does not imply binning. Defaul : True
- edges (bool, optional): If False, the given 'us' is considered as an array of uniformly distributed thresholds. If True, input 'us' is considered as a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform distributions of thresholds. In this last case, the thresholds are the central value of the given bins. Neglected if 'us' is not given. Default : False.
Attributes
- us (np.array): The thresholds at which the theoretical MFs are computed.
- μ (float): The derivative of the covariance function at the origin for the Gaussian isotropic scalar field.
319 def __init__(self, us=None, cls=None, μ=None, average_bin=True, edges=False): 320 """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere. 321 322 """ 323 if (us is None): 324 Δu = 0.1 325 self.us = np.arange(-5+Δu/2., 5.+Δu/2., Δu) 326 self.dus = Δu*np.ones(self.us.shape[0]) 327 else: 328 us = np.array(us) 329 if us.shape == (1,): 330 self.us = us 331 self.dus = 0. 332 else: 333 if edges: 334 self.dus = (us[1:]-us[:-1]) 335 self.us = (us[1:]+us[:-1])/2. 336 else: 337 self.us = us 338 self.dus = (us[1]-us[0])*np.ones(us.shape[0]) 339 340 341 self.μ = define_mu(cls,μ) 342 if not average_bin: 343 self.dus = 0.*self.dus
Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere.
346 def V0(self): 347 """Compute the expected values of the normalised first MF v0 at the different thresholds us. 348 $$\mathbb{E}[ v_{0} ] =1 -\Phi (u)$$ 349 where $\Phi$ is the cumulative normal distribution. 350 """ 351 return (V0_th_s0(self.us))
Compute the expected values of the normalised first MF v0 at the different thresholds us. $$\mathbb{E}[ v_{0} ] =1 -\Phi (u)$$ where $\Phi$ is the cumulative normal distribution.
353 def V1(self): 354 """Compute the expected values of the normalised second MF v1 at the different thresholds us. 355 356 $$\mathbb{E}[ v_{1}(u) ] = {1 \over 8} \exp{(- {u^2 \over 2})} \mu^{1/2}$$ 357 """ 358 us_ = define_us_for_V(self.us,self.dus) 359 v1_ = V1_th_s0(us_, self.μ) 360 361 return np.mean(v1_, axis=1)
Compute the expected values of the normalised second MF v1 at the different thresholds us.
$$\mathbb{E}[ v_{1}(u) ] = {1 \over 8} \exp{(- {u^2 \over 2})} \mu^{1/2}$$
363 def V2(self): 364 """Compute the expected values of the normalised third MF v2 at the different thresholds us. 365 366 $$\mathbb{E}[v_{2}(u)] = {2 \over \sqrt{(2\pi)^{3}}} \exp(-{u^{2} \over 2}) u$$ 367 """ 368 us_ = define_us_for_V(self.us,self.dus) 369 v2_ = V2_th_s0(us_, self.μ) 370 371 return np.mean(v2_, axis=1)
Compute the expected values of the normalised third MF v2 at the different thresholds us.
$$\mathbb{E}[v_{2}(u)] = {2 \over \sqrt{(2\pi)^{3}}} \exp(-{u^{2} \over 2}) u$$
375class TheoryP2(): 376 """Class to compute the expected values of Minkowski functionals (MFs) for the sum of two squared Gaussian isotropic fields normalised for their standard deviations defined on the sphere 377 like the polarised intensity of the CMB ($P^2 = Q^2 + U^2$). 378 379 Parameters 380 ---------- 381 us : np.array, optional 382 The thresholds at which the theoretical MFs will be computed. 383 If not given, a range between 0 and 5σ with steps of 0.1σ is considered, 384 with σ=1 the expected standard deviation of the fields U and Q. 385 386 cls : np.array, optional 387 The angular power spectrum associated to the Gaussian isotropic fields. 388 Shape '(..., lmax+1)'. '...' can be 2 (EE, BB) or absent (assumed to be EE+BB). 389 Default : None 390 391 μ : float, optional 392 The derivative of the covariance function at the origin for each of the two independent Gaussian isotropic fields (i.e., U and Q in the cosmological case). 393 If both μ and cls are given, an error will be raised. 394 If only cls is given, μ will be computed from input cls. 395 If neither μ nor cls are given, μ is assumed to be 1. 396 Default : None 397 398 average_bin : bool, optional 399 If True, the results of V1 and V2 are the average on each bin, to be compared with binned computations on maps. 400 If False, the results are the evaluation on the center of each bin. 401 The value is always exactly computed for V0, as the computation on maps does not imply binning. 402 Defaul : True 403 404 edges : bool, optional 405 If False, the given 'us' is considered as an array of uniformly distributed thresholds. 406 If True, input 'us' is considered as a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform distributions of thresholds. 407 In this last case, the thresholds are the central value of the given bins. 408 Neglected if 'us' is not given. 409 Default : False. 410 411 Attributes 412 ---------- 413 us : np.array 414 The thresholds at which the theoretical MFs are computed. 415 416 μ : float 417 The derivative of the covariance function at the origin for the sum of two squared Gaussian isotropic fields. 418 419 """ 420 def __init__(self, us=None, Cls=None, μ=None, average_bin=True, edges=False): 421 """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere. 422 423 """ 424 if (us is None): 425 Δu = 0.05 426 self.us = np.arange(Δu/2., 5.+Δu/2., Δu) 427 self.dus = Δu*np.ones(self.us.shape[0]) 428 else: 429 us = np.array(us) 430 if us.shape == (1,): 431 self.us = us 432 self.dus = 0. 433 else: 434 if edges: 435 self.dus = (us[1:]-us[:-1]) 436 self.us = (us[1:]+us[:-1])/2. 437 else: 438 self.us = us 439 self.dus = (us[1]-us[0])*np.ones(us.shape[0]) 440 441 if (Cls is not None) and (μ is None): 442 if (Cls.ndim == 2) and (Cls.shape[0]==2): 443 cls = (cls[0]+cls[1])/2. 444 elif (Cls.ndim == 1): 445 cls = cls/2. 446 else: 447 raise ValueError(r"Cls dimension has to be either (2,lmax+1) or (lmax+1)") 448 449 self.μ = define_mu(Cls,μ) 450 if not average_bin: 451 self.dus = 0.*self.dus 452 453 454 def V0(self): 455 """Compute the expected values of the normalised first MF v0 at the different thresholds us. 456 457 $$\mathbb{E}[{v_{0}(u)}] = \exp (-u/2)$$ 458 """ 459 return (V0_th_P2(self.us)) 460 461 def V1(self): 462 """Compute the expected values of the normalised second MF v1 at the different thresholds us. 463 464 $$\mathbb{E}[{v_{1}(u)}] = {\sqrt{2\pi } \over 8} \sqrt{\mu u}\exp (-{u \over 2})$$ 465 """ 466 us_ = define_us_for_V(self.us,self.dus) 467 v1_ = V1_th_P2(us_, self.μ) 468 469 return np.mean(v1_, axis=1) 470 471 def V2(self): 472 """Compute the expected values of the normalised third MF v2 at the different thresholds us. 473 474 $$\mathbb{E}[{v_{2}(u)}] = \mu {(u-1)\exp (-u/2) \over 2\pi }$$ 475 """ 476 us_ = define_us_for_V(self.us,self.dus) 477 v2_ = V2_th_P2(us_, self.μ) 478 479 return np.mean(v2_, axis=1)
Class to compute the expected values of Minkowski functionals (MFs) for the sum of two squared Gaussian isotropic fields normalised for their standard deviations defined on the sphere like the polarised intensity of the CMB ($P^2 = Q^2 + U^2$).
Parameters
- us (np.array, optional): The thresholds at which the theoretical MFs will be computed. If not given, a range between 0 and 5σ with steps of 0.1σ is considered, with σ=1 the expected standard deviation of the fields U and Q.
- cls (np.array, optional): The angular power spectrum associated to the Gaussian isotropic fields. Shape '(..., lmax+1)'. '...' can be 2 (EE, BB) or absent (assumed to be EE+BB). Default : None
- μ (float, optional): The derivative of the covariance function at the origin for each of the two independent Gaussian isotropic fields (i.e., U and Q in the cosmological case). If both μ and cls are given, an error will be raised. If only cls is given, μ will be computed from input cls. If neither μ nor cls are given, μ is assumed to be 1. Default : None
- average_bin (bool, optional): If True, the results of V1 and V2 are the average on each bin, to be compared with binned computations on maps. If False, the results are the evaluation on the center of each bin. The value is always exactly computed for V0, as the computation on maps does not imply binning. Defaul : True
- edges (bool, optional): If False, the given 'us' is considered as an array of uniformly distributed thresholds. If True, input 'us' is considered as a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform distributions of thresholds. In this last case, the thresholds are the central value of the given bins. Neglected if 'us' is not given. Default : False.
Attributes
- us (np.array): The thresholds at which the theoretical MFs are computed.
- μ (float): The derivative of the covariance function at the origin for the sum of two squared Gaussian isotropic fields.
420 def __init__(self, us=None, Cls=None, μ=None, average_bin=True, edges=False): 421 """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere. 422 423 """ 424 if (us is None): 425 Δu = 0.05 426 self.us = np.arange(Δu/2., 5.+Δu/2., Δu) 427 self.dus = Δu*np.ones(self.us.shape[0]) 428 else: 429 us = np.array(us) 430 if us.shape == (1,): 431 self.us = us 432 self.dus = 0. 433 else: 434 if edges: 435 self.dus = (us[1:]-us[:-1]) 436 self.us = (us[1:]+us[:-1])/2. 437 else: 438 self.us = us 439 self.dus = (us[1]-us[0])*np.ones(us.shape[0]) 440 441 if (Cls is not None) and (μ is None): 442 if (Cls.ndim == 2) and (Cls.shape[0]==2): 443 cls = (cls[0]+cls[1])/2. 444 elif (Cls.ndim == 1): 445 cls = cls/2. 446 else: 447 raise ValueError(r"Cls dimension has to be either (2,lmax+1) or (lmax+1)") 448 449 self.μ = define_mu(Cls,μ) 450 if not average_bin: 451 self.dus = 0.*self.dus
Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere.
454 def V0(self): 455 """Compute the expected values of the normalised first MF v0 at the different thresholds us. 456 457 $$\mathbb{E}[{v_{0}(u)}] = \exp (-u/2)$$ 458 """ 459 return (V0_th_P2(self.us))
Compute the expected values of the normalised first MF v0 at the different thresholds us.
$$\mathbb{E}[{v_{0}(u)}] = \exp (-u/2)$$
461 def V1(self): 462 """Compute the expected values of the normalised second MF v1 at the different thresholds us. 463 464 $$\mathbb{E}[{v_{1}(u)}] = {\sqrt{2\pi } \over 8} \sqrt{\mu u}\exp (-{u \over 2})$$ 465 """ 466 us_ = define_us_for_V(self.us,self.dus) 467 v1_ = V1_th_P2(us_, self.μ) 468 469 return np.mean(v1_, axis=1)
Compute the expected values of the normalised second MF v1 at the different thresholds us.
$$\mathbb{E}[{v_{1}(u)}] = {\sqrt{2\pi } \over 8} \sqrt{\mu u}\exp (-{u \over 2})$$
471 def V2(self): 472 """Compute the expected values of the normalised third MF v2 at the different thresholds us. 473 474 $$\mathbb{E}[{v_{2}(u)}] = \mu {(u-1)\exp (-u/2) \over 2\pi }$$ 475 """ 476 us_ = define_us_for_V(self.us,self.dus) 477 v2_ = V2_th_P2(us_, self.μ) 478 479 return np.mean(v2_, axis=1)
Compute the expected values of the normalised third MF v2 at the different thresholds us.
$$\mathbb{E}[{v_{2}(u)}] = \mu {(u-1)\exp (-u/2) \over 2\pi }$$