• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LSSTDESC / CCL / 5191066774

06 Jun 2023 04:42PM UTC coverage: 97.543% (+0.4%) from 97.136%
5191066774

Pull #1087

github

web-flow
Merge 987bfdbae into 17a0e5a2a
Pull Request #1087: v3 preparation

83 of 83 new or added lines in 36 files covered. (100.0%)

5122 of 5251 relevant lines covered (97.54%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.52
/pyccl/nl_pt/tracers.py
1
__all__ = ("translate_IA_norm", "PTTracer", "PTMatterTracer",
1✔
2
           "PTNumberCountsTracer", "PTIntrinsicAlignmentTracer",)
3

4
from abc import abstractmethod
1✔
5

6
import numpy as np
1✔
7
from scipy.interpolate import interp1d
1✔
8

9
from .. import CCLAutoRepr, physical_constants
1✔
10
from ..pyutils import _check_array_params
1✔
11

12

13
def translate_IA_norm(cosmo, *, z, a1=1.0, a1delta=None, a2=None,
1✔
14
                      Om_m2_for_c2=False, Om_m_fid=0.3):
15
    """
16
    Function to convert from :math:`A_{ia}` values to :math:`c_{ia}` values,
17
    for the intrinsic alignment bias parameters using the standard
18
    convention of `Blazek et al. 2019 <https://arxiv.org/abs/1708.09247>`_
19
    or the variant used by the Dark Energy Survey analysis.
20

21
    Args:
22
        cosmo (:class:`~pyccl.cosmology.Cosmology`): cosmology object.
23
        z (:obj:`float` or `array`): z value(s) where amplitude is evaluated.
24
        a1 (:obj:`float` or `array`): IA :math:`A_1` at input z values.
25
        a1delta (:obj:`float` or `array`): IA :math:`A_{1\\delta}` at input
26
            z values.
27
        a2 (:obj:`float` or `array`): IA :math:`A_2` at input z values.
28
        Om_m2_for_c2 (:obj:`bool`): True to use the Blazek et al. 2019
29
            convention of :math:`\\Omega_m^2` scaling.
30
        Om_m_fid (:obj:`float`): Value for Blazek et al. 2019 scaling.
31

32
    Returns:
33
        Tuple of IA bias parameters
34

35
        - c1 (:obj:`float` or `array`): IA :math:`C_1` at input z values.
36
        - c1delta (:obj:`float` or `array`): IA :math:`C_{1\\delta}` at
37
          input z values.
38
        - c2 (:obj:`float` or `array`): IA :math:`C_2` at input z values.
39
    """
40

41
    Om_m = cosmo['Omega_m']
×
42
    rho_crit = physical_constants.RHO_CRITICAL
×
43
    c1 = c1delta = c2 = None
×
44
    gz = cosmo.growth_factor(1./(1+z))
×
45

46
    if a1 is not None:
×
47
        c1 = -1*a1*5e-14*rho_crit*Om_m/gz
×
48

49
    if a1delta is not None:
×
50
        c1delta = -1*a1delta*5e-14*rho_crit*Om_m/gz
×
51

52
    if a2 is not None:
×
53
        if Om_m2_for_c2:  # Blazek2019 convention
×
54
            c2 = a2*5*5e-14*rho_crit*Om_m**2/(Om_m_fid*gz**2)
×
55
        else:  # DES convention
56
            c2 = a2*5*5e-14*rho_crit*Om_m/(gz**2)
×
57

58
    return c1, c1delta, c2
×
59

60

61
class PTTracer(CCLAutoRepr):
1✔
62
    """PTTracers contain the information necessary to describe the
1✔
63
    perturbative, non-linear inhomogeneities associated with
64
    different physical quantities.
65

66
    In essence their main function is to store a set of
67
    redshift-dependent functions (e.g. perturbation theory biases)
68
    needed in a perturbation theory framework to provide N-point
69
    correlations.
70
    """
71
    __repr_attrs__ = __eq_attrs__ = ('type', 'biases')
1✔
72

73
    def __init__(self):
1✔
74
        self.biases = {}
×
75
        pass
×
76

77
    @property
1✔
78
    @abstractmethod
1✔
79
    def type(self):
1✔
80
        """String defining tracer type (``'M'``, ``'NC'`` and
81
        ``'IA'`` supported).
82
        """
83

84
    def get_bias(self, bias_name, z):
1✔
85
        """Get the value of one of the bias functions at a given
86
        redshift.
87

88
        Args:
89
            bias_name (:obj:`str`): name of the bias function to return.
90
            z (:obj:`float` or `array`): redshift.
91

92
        Returns:
93
            (:obj:`float` or `array`): bias value at the input redshifts.
94
        """
95
        if bias_name not in self.biases:
1✔
96
            raise KeyError(f"Bias {bias_name} not included in this tracer")
1✔
97
        return self.biases[bias_name](z)
1✔
98

99
    def _get_bias_function(self, b):
1✔
100
        # If None, assume it's zero
101
        if b is None:
1✔
102
            b = 0
1✔
103

104
        # If it's a scalar, then assume it's a constant function
105
        if np.ndim(b) == 0:
1✔
106
            def _const(z):
1✔
107
                if np.ndim(z) == 0:
1✔
108
                    return b
1✔
109
                else:
110
                    return b * np.ones_like(z)
1✔
111

112
            return _const
1✔
113
        else:  # Otherwise interpolate
114
            z, b = _check_array_params(b)
1✔
115
            return interp1d(z, b, bounds_error=False,
1✔
116
                            fill_value=b[-1])
117

118

119
class PTMatterTracer(PTTracer):
1✔
120
    """:class:`PTTracer` representing matter fluctuations.
1✔
121
    """
122
    type = 'M'
1✔
123

124
    def __init__(self):
1✔
125
        self.biases = {}
1✔
126

127

128
class PTNumberCountsTracer(PTTracer):
1✔
129
    """:class:`PTTracer` representing number count fluctuations.
1✔
130
    This is described by 1st and 2nd-order biases and
131
    a tidal field bias. These are provided as floating
132
    point numbers or tuples of `(reshift,bias)` arrays.
133
    If a number is provided, a constant bias is assumed.
134
    If ``None``, a bias of zero is assumed.
135

136
    Args:
137
        b1 (:obj:`float` or :obj:`tuple`): a single number or a
138
            tuple of arrays ``(z, b(z))`` giving the first-order
139
            bias.
140
        b2 (:obj:`float` or :obj:`tuple`): as above for the
141
            second-order bias.
142
        bs (:obj:`float` or :obj:`tuple`): as above for the
143
            tidal bias.
144
        b3nl (:obj:`float` or :obj:`tuple`): as above for the
145
            third-order bias.
146
        bk2 (:obj:`float` or :obj:`tuple`): as above for the
147
            non-local bias.
148
    """
149
    type = 'NC'
1✔
150

151
    def __init__(self, b1, b2=None, bs=None, b3nl=None, bk2=None):
1✔
152
        self.biases = {}
1✔
153

154
        # Initialize b1
155
        self.biases['b1'] = self._get_bias_function(b1)
1✔
156
        # Initialize b2
157
        self.biases['b2'] = self._get_bias_function(b2)
1✔
158
        # Initialize bs
159
        self.biases['bs'] = self._get_bias_function(bs)
1✔
160
        # Initialize b3nl
161
        self.biases['b3nl'] = self._get_bias_function(b3nl)
1✔
162
        # Initialize bk2
163
        self.biases['bk2'] = self._get_bias_function(bk2)
1✔
164

165
    @property
1✔
166
    def b1(self):
1✔
167
        """Internal first-order bias function.
168
        """
169
        return self.biases['b1']
1✔
170

171
    @property
1✔
172
    def b2(self):
1✔
173
        """Internal second-order bias function.
174
        """
175
        return self.biases['b2']
1✔
176

177
    @property
1✔
178
    def bs(self):
1✔
179
        """Internal tidal bias function.
180
        """
181
        return self.biases['bs']
1✔
182

183
    @property
1✔
184
    def b3nl(self):
1✔
185
        """Internal third-order bias function.
186
        """
187
        return self.biases['b3nl']
1✔
188

189
    @property
1✔
190
    def bk2(self):
1✔
191
        """Internal non-local bias function.
192
        """
193
        return self.biases['bk2']
1✔
194

195

196
class PTIntrinsicAlignmentTracer(PTTracer):
1✔
197
    """:class:`PTTracer` representing intrinsic alignments.
1✔
198
    This is described by 1st and 2nd-order alignment biases
199
    and an overdensity bias. These are provided as floating
200
    point numbers or tuples of (reshift,bias) arrays.
201
    If a number is provided, a constant bias is assumed.
202
    If ``None``, a bias of zero is assumed.
203

204
    Args:
205
        c1 (:obj:`float` or :obj:`tuple`): a single number or a
206
            tuple of arrays ``(z, c1(z))`` giving the first-order
207
            alignment bias :math:`C_1`.
208
        c2 (:obj:`float` or :obj:`tuple`): as above for the
209
            second-order alignment bias :math:`C_2`.
210
        cdelta (:obj:`float` or :obj:`tuple`): as above for the
211
            overdensity bias :math:`C_{1\\delta}`.
212
    """
213
    type = 'IA'
1✔
214

215
    def __init__(self, c1, c2=None, cdelta=None):
1✔
216

217
        self.biases = {}
1✔
218

219
        # Initialize c1
220
        self.biases['c1'] = self._get_bias_function(c1)
1✔
221
        # Initialize c2
222
        self.biases['c2'] = self._get_bias_function(c2)
1✔
223
        # Initialize cdelta
224
        self.biases['cdelta'] = self._get_bias_function(cdelta)
1✔
225

226
    @property
1✔
227
    def c1(self):
1✔
228
        """Internal first-order bias function.
229
        """
230
        return self.biases['c1']
1✔
231

232
    @property
1✔
233
    def c2(self):
1✔
234
        """Internal second-order bias function.
235
        """
236
        return self.biases['c2']
1✔
237

238
    @property
1✔
239
    def cdelta(self):
1✔
240
        """Internal overdensity bias function.
241
        """
242
        return self.biases['cdelta']
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc