Numerics¶
Pure numerical routines — no cosmology knowledge; they operate on callables and arrays. See Architecture.
Interpolation¶
liulu.numerics.interpolation.loglog_interp ¶
Hybrid power-law interpolation. Within a table interval whose both endpoint ordinates are positive it is linear in (log x, log y) -- exact for power laws, so the steeply-falling xi(r) of the streaming weight is captured without the convex overestimate of log-linear interpolation. Any interval touching a non-positive ordinate is instead interpolated linearly in (log x, y), which honours tabulated negative values and sign changes (e.g. xi(r) beyond its zero crossing): node values are always reproduced exactly, whatever their sign.
Out-of-range: fill_value follows the same scalar / (below, above) /
"edge" convention as :func:log_linear_interp; the above side also
accepts "power", continuing the power law of the trailing (up to 4)
consistent-sign points -- a table ending negative yields a decaying
negative tail, so a BAO-style xi -> 0^- continuation is preserved. If
the table does not end with at least two points of consistent sign, a
requested power tail degrades to edge extrapolation (announced with a
RuntimeWarning).
Source code in liulu/numerics/interpolation.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
liulu.numerics.interpolation.log_linear_interp ¶
Log-linear interpolation: linear in log(x), linear in y.
Handles negative y values (e.g. pairwise velocities) by interpolating y directly (not log(y)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Abscissae (must be positive, ascending). |
required |
y
|
ndarray
|
Ordinates. |
required |
fill_value
|
float or tuple
|
Out-of-range policy; see the module docstring. Defaults to |
0.0
|
name
|
str
|
Label used in the out-of-range warning. |
'table'
|
warn
|
bool
|
Whether to warn on out-of-range queries. |
True
|
Returns:
| Type | Description |
|---|---|
callable
|
Interpolator f(x_new) -> y_new. |
Source code in liulu/numerics/interpolation.py
liulu.numerics.interpolation.log_spline_interp ¶
Cubic spline interpolation in log(x) space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Abscissae (must be positive, ascending). |
required |
y
|
ndarray
|
Ordinates. |
required |
fill_value
|
float or tuple
|
Out-of-range policy; see the module docstring. Defaults to |
0.0
|
name
|
str
|
Label used in the out-of-range warning. |
'table'
|
warn
|
bool
|
Whether to warn on out-of-range queries. |
True
|
Returns:
| Type | Description |
|---|---|
callable
|
Interpolator f(x_new) -> y_new. |
Source code in liulu/numerics/interpolation.py
Extrapolation¶
liulu.numerics.extrapolation.extend_table ¶
Extend (r, y) onto [r_lo, r_hi].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
array_like
|
Tabulated abscissae (positive, ascending) and ordinates. |
required |
y
|
array_like
|
Tabulated abscissae (positive, ascending) and ordinates. |
required |
r_lo
|
float
|
Target lower/upper bounds. Padding is added only where it widens |
required |
r_hi
|
float
|
Target lower/upper bounds. Padding is added only where it widens |
required |
low
|
edge
|
Fill below |
"edge"
|
high
|
(edge, zero, power, rise)
|
Tail above
|
"edge"
|
n_pad
|
int
|
Number of padding points added per side. |
24
|
Returns:
| Type | Description |
|---|---|
(ndarray, ndarray)
|
Extended |
Source code in liulu/numerics/extrapolation.py
Binning¶
liulu.numerics.binning.pair_weighted_centres ¶
Effective (count-weighted) abscissa of each bin of a pair-count estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edges
|
(array_like, shape(n_bins + 1))
|
Bin edges (positive, ascending). |
required |
f
|
callable
|
The binned function itself, |
required |
n_sub
|
int
|
Gauss-Legendre nodes per bin. |
64
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(n_bins))
|
|
Source code in liulu/numerics/binning.py
Hankel transforms¶
liulu.numerics.hankel.pk_to_xi ¶
Transform P(k) to xi(r) via direct quadrature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
ndarray
|
Wavenumbers, h/Mpc. |
required |
pk
|
ndarray
|
Power spectrum, (Mpc/h)^3. |
required |
r
|
array_like
|
Separations at which to evaluate xi, Mpc/h. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Correlation function xi(r). |
Source code in liulu/numerics/hankel.py
liulu.numerics.hankel.xi_to_pk ¶
Transform xi(r) to P(k) via direct quadrature (inverse Hankel).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
ndarray
|
Separations, Mpc/h. |
required |
xi
|
ndarray
|
Correlation function. |
required |
k
|
array_like
|
Wavenumbers at which to evaluate P(k), h/Mpc. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Power spectrum P(k), (Mpc/h)^3. |