pynkowski.theory.utils

 1 
 2import numpy as np
 3
 4def get_μ(cls):
 5    """Compute the first derivative of the covariance function at the origin for a Gaussian field 
 6    defined on the sphere with angular power spectrum 'cls', which are normalised to unit variance.
 7
 8    Parameters
 9    ----------
10    cls : np.array
11        The angular power spectrum of the Gaussian field.
12    
13    Returns
14    -------
15    μ : float
16        The first derivative of the covariance function of a field at the origin.
17    
18    """
19    cls = np.array(cls, dtype=float)
20     = np.arange(cls.shape[0])
21    cls /= np.sum(cls * (2.*+1.) / (4.*np.pi))
22    μ = np.sum(cls * (2.*+1.) * *(+1.) / (8.*np.pi))
23    return μ
24
25def define_mu(cls,μ):
26    """Return the first derivative of the covariance function at the origin for a field 
27    computed accordingly to which input variable is given.
28
29    Parameters
30    ----------
31    cls : np.array, optional
32        The angular power spectrum of the field.
33        Default : None
34
35    μ : scalar, optional
36        The first derivative of the covariance function at the origin for the field. If None, μ=1 is assumed.
37        Default : None
38
39    Returns
40    -------
41    μ : scalar
42        The first derivative of the covariance function of the field at the origin.
43
44    Notes
45    -----
46    The derivatives are always computed full-sky regardless of input mask.
47    
48    """
49    if (cls is not None) and (μ is not None):
50        raise ValueError(r"Both cls and $\mu$ cannot be given")
51    if (cls is not None) and (μ is None):
52        return get_μ(cls)
53    if (cls is None) and (μ is not None):
54        return μ
55    if (cls is None) and (μ is None):
56        return 1.
57    
58def define_us_for_V(us,dus,iters=1000):
59    """Return the thresholds where MFs (except for v0) are computed before averaging within the bins 'dus'.
60
61    Parameters
62    ----------
63    us : np.array
64        The thresholds at which MFs have to be computed.
65
66    dus : np.array
67        The width of the bins associated to the thresholds 'us'.
68        
69    iters : int, optional
70        the number of thresholds to consider within each bin.
71
72    Returns
73    -------
74    us_ : np.array
75        The sequence of thresholds where MFs are computed before averaging within each bin, with shape (us.shape, iters)
76        
77    iters : int, optional
78        the number of thresholds considered within each bin.
79    
80    """
81    return np.vstack([np.linspace(u-du/2, u+du/2, iters) for u, du in zip(us, dus)])
82
83
84
85
86__all__ = ["get_μ", "define_mu", "define_us_for_V"]
87
88__docformat__ = "numpy"
89
90 
def get_μ(cls)
 5def get_μ(cls):
 6    """Compute the first derivative of the covariance function at the origin for a Gaussian field 
 7    defined on the sphere with angular power spectrum 'cls', which are normalised to unit variance.
 8
 9    Parameters
10    ----------
11    cls : np.array
12        The angular power spectrum of the Gaussian field.
13    
14    Returns
15    -------
16    μ : float
17        The first derivative of the covariance function of a field at the origin.
18    
19    """
20    cls = np.array(cls, dtype=float)
21     = np.arange(cls.shape[0])
22    cls /= np.sum(cls * (2.*+1.) / (4.*np.pi))
23    μ = np.sum(cls * (2.*+1.) * *(+1.) / (8.*np.pi))
24    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', which are normalised to unit variance.

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.
def define_mu(cls, μ)
26def define_mu(cls,μ):
27    """Return the first derivative of the covariance function at the origin for a field 
28    computed accordingly to which input variable is given.
29
30    Parameters
31    ----------
32    cls : np.array, optional
33        The angular power spectrum of the field.
34        Default : None
35
36    μ : scalar, optional
37        The first derivative of the covariance function at the origin for the field. If None, μ=1 is assumed.
38        Default : None
39
40    Returns
41    -------
42    μ : scalar
43        The first derivative of the covariance function of the field at the origin.
44
45    Notes
46    -----
47    The derivatives are always computed full-sky regardless of input mask.
48    
49    """
50    if (cls is not None) and (μ is not None):
51        raise ValueError(r"Both cls and $\mu$ cannot be given")
52    if (cls is not None) and (μ is None):
53        return get_μ(cls)
54    if (cls is None) and (μ is not None):
55        return μ
56    if (cls is None) and (μ is None):
57        return 1.

Return the first derivative of the covariance function at the origin for a field computed accordingly to which input variable is given.

Parameters
  • cls (np.array, optional): The angular power spectrum of the field. Default : None
  • μ (scalar, optional): The first derivative of the covariance function at the origin for the field. If None, μ=1 is assumed. Default : None
Returns
  • μ (scalar): The first derivative of the covariance function of the field at the origin.
Notes

The derivatives are always computed full-sky regardless of input mask.

def define_us_for_V(us, dus, iters=1000)
59def define_us_for_V(us,dus,iters=1000):
60    """Return the thresholds where MFs (except for v0) are computed before averaging within the bins 'dus'.
61
62    Parameters
63    ----------
64    us : np.array
65        The thresholds at which MFs have to be computed.
66
67    dus : np.array
68        The width of the bins associated to the thresholds 'us'.
69        
70    iters : int, optional
71        the number of thresholds to consider within each bin.
72
73    Returns
74    -------
75    us_ : np.array
76        The sequence of thresholds where MFs are computed before averaging within each bin, with shape (us.shape, iters)
77        
78    iters : int, optional
79        the number of thresholds considered within each bin.
80    
81    """
82    return np.vstack([np.linspace(u-du/2, u+du/2, iters) for u, du in zip(us, dus)])

Return the thresholds where MFs (except for v0) are computed before averaging within the bins 'dus'.

Parameters
  • us (np.array): The thresholds at which MFs have to be computed.
  • dus (np.array): The width of the bins associated to the thresholds 'us'.
  • iters (int, optional): the number of thresholds to consider within each bin.
Returns
  • us_ (np.array): The sequence of thresholds where MFs are computed before averaging within each bin, with shape (us.shape, iters)
  • iters (int, optional): the number of thresholds considered within each bin.