pynkowski.theory.p2

  1import numpy as np
  2import scipy.stats
  3
  4from .utils import get_μ, define_mu, define_us_for_V
  5
  6norm = scipy.stats.norm()
  7
  8
  9
 10def V0_th_P2(u):
 11    """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.
 12
 13    Parameters
 14    ----------
 15    u : np.array
 16        Thresholds at which the first MF is computed.
 17    
 18    Returns
 19    -------
 20    v0 : np.array
 21        The expected value of the normalised first MF at thresholds u.
 22    
 23    """    
 24    return 1-((1-np.exp(-u/2.)) * (u>=0.))
 25
 26def V1_th_P2(u, μ):
 27    """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.
 28
 29    Parameters
 30    ----------
 31    u : np.array
 32        Thresholds at which the second MF is computed.
 33    
 34    μ : float
 35        The derivative of the covariance function at the origin for the Gaussian isotropic scalar field.
 36    
 37    Returns
 38    -------
 39    v1 : np.array
 40        The expected value of the normalised second MF at thresholds u.
 41    
 42    """    
 43    return np.sqrt(μ * (u) / 4.) * np.exp(-u/2.) * (u>=0.) * (np.sqrt(np.pi/8.))
 44
 45def V2_th_P2(u, μ):
 46    """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.
 47
 48    Parameters
 49    ----------
 50    u : np.array
 51        Thresholds at which the third MF is computed.
 52    
 53    μ : float
 54        The derivative of the covariance function at the origin for the Gaussian isotropic scalar field.
 55    
 56    Returns
 57    -------
 58    v2 : np.array
 59        The expected value of the normalised third MF at thresholds u.
 60    
 61    """    
 62    return (((μ * (u-1.) * np.exp(-u/2.)) / (2.*np.pi) ) * (u>=0.)) 
 63
 64
 65
 66
 67
 68class TheoryP2():
 69    """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 
 70    like the polarised intensity of the CMB ($P^2 = Q^2 + U^2$).
 71
 72    Parameters
 73    ----------
 74    us : np.array, optional
 75        The thresholds at which the theoretical MFs will be computed. 
 76        If not given, a range between 0 and 5σ with steps of 0.1σ is considered, 
 77        with σ=1 the expected standard deviation of the fields U and Q.
 78    
 79    cls : np.array, optional
 80        The angular power spectrum associated to the Gaussian isotropic fields. 
 81        Shape '(..., lmax+1)'. '...' can be 2 (EE, BB) or absent (assumed to be EE+BB).
 82        Default : None 
 83    
 84    μ : float, optional
 85        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).
 86        If both μ and cls are given, an error will be raised.
 87        If only cls is given, μ will be computed from input cls.
 88        If neither μ nor cls are given, μ is assumed to be 1.
 89        Default : None
 90        
 91    average_bin : bool, optional
 92        If True, the results of V1 and V2 are the average on each bin, to be compared with binned computations on maps.
 93        If False, the results are the evaluation on the center of each bin.
 94        The value is always exactly computed for V0, as the computation on maps does not imply binning.
 95        Defaul : True
 96        
 97    edges : bool, optional
 98        If False, the given 'us' is considered as an array of uniformly distributed thresholds. 
 99        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. 
100        In this last case, the thresholds are the central value of the given bins.
101        Neglected if 'us' is not given.
102        Default : False.
103
104    Attributes
105    ----------
106    us : np.array
107        The thresholds at which the theoretical MFs are computed. 
108        
109    μ : float
110        The derivative of the covariance function at the origin for the sum of two squared Gaussian isotropic fields.
111        
112    """    
113    def __init__(self, us=None, Cls=None, μ=None, average_bin=True, edges=False):
114        """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere.
115
116        """    
117        if (us is None):
118            Δu = 0.05
119            self.us = np.arange(Δu/2., 5.+Δu/2., Δu)
120            self.dus = Δu*np.ones(self.us.shape[0])
121        else:
122            us = np.array(us)
123            if us.shape == (1,):
124                self.us = us
125                self.dus = 0.
126            else:
127                if edges:
128                    self.dus = (us[1:]-us[:-1])
129                    self.us = (us[1:]+us[:-1])/2.
130                else:
131                    self.us = us
132                    self.dus = (us[1]-us[0])*np.ones(us.shape[0])
133
134        if (Cls is not None) and (μ is None):
135            if (Cls.ndim == 2) and (Cls.shape[0]==2):
136                cls = (cls[0]+cls[1])/2.
137            elif (Cls.ndim == 1):
138                cls = cls/2.
139            else:
140                raise ValueError(r"Cls dimension has to be either (2,lmax+1) or (lmax+1)")
141                
142        self.μ = define_mu(Cls,μ)   
143        if not average_bin:
144            self.dus = 0.*self.dus
145        
146    
147    def V0(self):
148        """Compute the expected values of the normalised first MF v0 at the different thresholds us.
149
150        $$\mathbb{E}[{v_{0}(u)}] = \exp (-u/2)$$
151        """    
152        return (V0_th_P2(self.us))
153
154    def V1(self):
155        """Compute the expected values of the normalised second MF v1 at the different thresholds us.
156        
157        $$\mathbb{E}[{v_{1}(u)}] = {\sqrt{2\pi } \over 8} \sqrt{\mu u}\exp (-{u \over 2})$$
158        """ 
159        us_ = define_us_for_V(self.us,self.dus)
160        v1_ = V1_th_P2(us_, self.μ)
161        
162        return np.mean(v1_, axis=1)
163    
164    def V2(self):
165        """Compute the expected values of the normalised third MF v2 at the different thresholds us.
166        
167        $$\mathbb{E}[{v_{2}(u)}] = \mu {(u-1)\exp (-u/2) \over 2\pi }$$
168        """    
169        us_ = define_us_for_V(self.us,self.dus)
170        v2_ = V2_th_P2(us_, self.μ)
171        
172        return np.mean(v2_, axis=1)
173
174
175__all__ = ["TheoryP2"]
176
177__docformat__ = "numpy"
class TheoryP2:
 69class TheoryP2():
 70    """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 
 71    like the polarised intensity of the CMB ($P^2 = Q^2 + U^2$).
 72
 73    Parameters
 74    ----------
 75    us : np.array, optional
 76        The thresholds at which the theoretical MFs will be computed. 
 77        If not given, a range between 0 and 5σ with steps of 0.1σ is considered, 
 78        with σ=1 the expected standard deviation of the fields U and Q.
 79    
 80    cls : np.array, optional
 81        The angular power spectrum associated to the Gaussian isotropic fields. 
 82        Shape '(..., lmax+1)'. '...' can be 2 (EE, BB) or absent (assumed to be EE+BB).
 83        Default : None 
 84    
 85    μ : float, optional
 86        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).
 87        If both μ and cls are given, an error will be raised.
 88        If only cls is given, μ will be computed from input cls.
 89        If neither μ nor cls are given, μ is assumed to be 1.
 90        Default : None
 91        
 92    average_bin : bool, optional
 93        If True, the results of V1 and V2 are the average on each bin, to be compared with binned computations on maps.
 94        If False, the results are the evaluation on the center of each bin.
 95        The value is always exactly computed for V0, as the computation on maps does not imply binning.
 96        Defaul : True
 97        
 98    edges : bool, optional
 99        If False, the given 'us' is considered as an array of uniformly distributed thresholds. 
100        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. 
101        In this last case, the thresholds are the central value of the given bins.
102        Neglected if 'us' is not given.
103        Default : False.
104
105    Attributes
106    ----------
107    us : np.array
108        The thresholds at which the theoretical MFs are computed. 
109        
110    μ : float
111        The derivative of the covariance function at the origin for the sum of two squared Gaussian isotropic fields.
112        
113    """    
114    def __init__(self, us=None, Cls=None, μ=None, average_bin=True, edges=False):
115        """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere.
116
117        """    
118        if (us is None):
119            Δu = 0.05
120            self.us = np.arange(Δu/2., 5.+Δu/2., Δu)
121            self.dus = Δu*np.ones(self.us.shape[0])
122        else:
123            us = np.array(us)
124            if us.shape == (1,):
125                self.us = us
126                self.dus = 0.
127            else:
128                if edges:
129                    self.dus = (us[1:]-us[:-1])
130                    self.us = (us[1:]+us[:-1])/2.
131                else:
132                    self.us = us
133                    self.dus = (us[1]-us[0])*np.ones(us.shape[0])
134
135        if (Cls is not None) and (μ is None):
136            if (Cls.ndim == 2) and (Cls.shape[0]==2):
137                cls = (cls[0]+cls[1])/2.
138            elif (Cls.ndim == 1):
139                cls = cls/2.
140            else:
141                raise ValueError(r"Cls dimension has to be either (2,lmax+1) or (lmax+1)")
142                
143        self.μ = define_mu(Cls,μ)   
144        if not average_bin:
145            self.dus = 0.*self.dus
146        
147    
148    def V0(self):
149        """Compute the expected values of the normalised first MF v0 at the different thresholds us.
150
151        $$\mathbb{E}[{v_{0}(u)}] = \exp (-u/2)$$
152        """    
153        return (V0_th_P2(self.us))
154
155    def V1(self):
156        """Compute the expected values of the normalised second MF v1 at the different thresholds us.
157        
158        $$\mathbb{E}[{v_{1}(u)}] = {\sqrt{2\pi } \over 8} \sqrt{\mu u}\exp (-{u \over 2})$$
159        """ 
160        us_ = define_us_for_V(self.us,self.dus)
161        v1_ = V1_th_P2(us_, self.μ)
162        
163        return np.mean(v1_, axis=1)
164    
165    def V2(self):
166        """Compute the expected values of the normalised third MF v2 at the different thresholds us.
167        
168        $$\mathbb{E}[{v_{2}(u)}] = \mu {(u-1)\exp (-u/2) \over 2\pi }$$
169        """    
170        us_ = define_us_for_V(self.us,self.dus)
171        v2_ = V2_th_P2(us_, self.μ)
172        
173        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.
TheoryP2(us=None, Cls=None, μ=None, average_bin=True, edges=False)
114    def __init__(self, us=None, Cls=None, μ=None, average_bin=True, edges=False):
115        """Class to compute the expected values of Minkowski functionals (MFs) for a Gaussian isotropic scalar field defined on the sphere.
116
117        """    
118        if (us is None):
119            Δu = 0.05
120            self.us = np.arange(Δu/2., 5.+Δu/2., Δu)
121            self.dus = Δu*np.ones(self.us.shape[0])
122        else:
123            us = np.array(us)
124            if us.shape == (1,):
125                self.us = us
126                self.dus = 0.
127            else:
128                if edges:
129                    self.dus = (us[1:]-us[:-1])
130                    self.us = (us[1:]+us[:-1])/2.
131                else:
132                    self.us = us
133                    self.dus = (us[1]-us[0])*np.ones(us.shape[0])
134
135        if (Cls is not None) and (μ is None):
136            if (Cls.ndim == 2) and (Cls.shape[0]==2):
137                cls = (cls[0]+cls[1])/2.
138            elif (Cls.ndim == 1):
139                cls = cls/2.
140            else:
141                raise ValueError(r"Cls dimension has to be either (2,lmax+1) or (lmax+1)")
142                
143        self.μ = define_mu(Cls,μ)   
144        if not average_bin:
145            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.

def V0(self)
148    def V0(self):
149        """Compute the expected values of the normalised first MF v0 at the different thresholds us.
150
151        $$\mathbb{E}[{v_{0}(u)}] = \exp (-u/2)$$
152        """    
153        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)$$

def V1(self)
155    def V1(self):
156        """Compute the expected values of the normalised second MF v1 at the different thresholds us.
157        
158        $$\mathbb{E}[{v_{1}(u)}] = {\sqrt{2\pi } \over 8} \sqrt{\mu u}\exp (-{u \over 2})$$
159        """ 
160        us_ = define_us_for_V(self.us,self.dus)
161        v1_ = V1_th_P2(us_, self.μ)
162        
163        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})$$

def V2(self)
165    def V2(self):
166        """Compute the expected values of the normalised third MF v2 at the different thresholds us.
167        
168        $$\mathbb{E}[{v_{2}(u)}] = \mu {(u-1)\exp (-u/2) \over 2\pi }$$
169        """    
170        us_ = define_us_for_V(self.us,self.dus)
171        v2_ = V2_th_P2(us_, self.μ)
172        
173        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 }$$