flipcosmo 1.0.0__py3-none-any.whl → 1.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docs/conf.py +154 -0
- flip/__init__.py +4 -11
- flip/covariance/__init__.py +7 -8
- flip/covariance/analytical/__init__.py +11 -0
- flip/covariance/{adamsblake17plane → analytical/adamsblake17}/coefficients.py +1 -1
- flip/covariance/{adamsblake17plane → analytical/adamsblake17}/fisher_terms.py +1 -1
- flip/covariance/{adamsblake17 → analytical/adamsblake17}/flip_terms.py +0 -1
- flip/covariance/{adamsblake17 → analytical/adamsblake17plane}/coefficients.py +1 -1
- flip/covariance/{adamsblake17 → analytical/adamsblake17plane}/fisher_terms.py +1 -1
- flip/covariance/{adamsblake17plane → analytical/adamsblake17plane}/flip_terms.py +0 -1
- flip/covariance/{adamsblake17plane → analytical/adamsblake17plane}/generator.py +103 -19
- flip/covariance/{adamsblake20 → analytical/adamsblake20}/coefficients.py +1 -1
- flip/covariance/{adamsblake20 → analytical/adamsblake20}/fisher_terms.py +1 -1
- flip/covariance/{adamsblake20 → analytical/adamsblake20}/flip_terms.py +0 -1
- flip/covariance/{carreres23 → analytical/carreres23}/coefficients.py +1 -4
- flip/covariance/{ravouxnoanchor25 → analytical/carreres23}/fisher_terms.py +1 -1
- flip/covariance/{carreres23 → analytical/carreres23}/flip_terms.py +0 -1
- flip/covariance/analytical/carreres23/generator.py +198 -0
- flip/covariance/analytical/genericzdep/__init__.py +5 -0
- flip/covariance/analytical/genericzdep/coefficients.py +53 -0
- flip/covariance/analytical/genericzdep/flip_terms.py +99 -0
- flip/covariance/{lai22 → analytical/lai22}/coefficients.py +2 -3
- flip/covariance/{lai22 → analytical/lai22}/fisher_terms.py +1 -1
- flip/covariance/{lai22 → analytical/lai22}/flip_terms.py +0 -1
- flip/covariance/{lai22 → analytical/lai22}/generator.py +263 -58
- flip/covariance/{lai22 → analytical/lai22}/symbolic.py +55 -19
- flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/coefficients.py +1 -1
- flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/fisher_terms.py +1 -1
- flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/flip_terms.py +0 -1
- flip/covariance/{ravouxnoanchor25 → analytical/ravouxnoanchor25}/coefficients.py +3 -2
- flip/covariance/{carreres23 → analytical/ravouxnoanchor25}/fisher_terms.py +1 -1
- flip/covariance/{ravouxnoanchor25 → analytical/ravouxnoanchor25}/flip_terms.py +0 -9
- flip/covariance/{rcrk24 → analytical/rcrk24}/coefficients.py +6 -6
- flip/covariance/{rcrk24 → analytical/rcrk24}/fisher_terms.py +7 -9
- flip/covariance/{rcrk24 → analytical/rcrk24}/flip_terms.py +0 -8
- flip/covariance/contraction.py +82 -40
- flip/covariance/cov_utils.py +89 -81
- flip/covariance/covariance.py +172 -141
- flip/covariance/emulators/__init__.py +1 -1
- flip/covariance/emulators/generator.py +73 -3
- flip/covariance/emulators/gpmatrix.py +40 -1
- flip/covariance/emulators/nnmatrix.py +57 -1
- flip/covariance/emulators/skgpmatrix.py +125 -0
- flip/covariance/fisher.py +307 -0
- flip/{fit_utils.py → covariance/fit_utils.py} +185 -10
- flip/{fitter.py → covariance/fitter.py} +151 -125
- flip/covariance/generator.py +82 -106
- flip/{likelihood.py → covariance/likelihood.py} +286 -64
- flip/{plot_utils.py → covariance/plot_utils.py} +79 -4
- flip/covariance/symbolic.py +89 -44
- flip/data/__init__.py +1 -1
- flip/data/data_density.parquet +0 -0
- flip/data/data_velocity.parquet +0 -0
- flip/data/{grid_window_m.parquet → data_window_density.parquet} +0 -0
- flip/{gridding.py → data/gridding.py} +125 -130
- flip/data/load_data_test.py +102 -0
- flip/data/power_spectrum_mm.txt +2 -2
- flip/data/power_spectrum_mt.txt +2 -2
- flip/data/power_spectrum_tt.txt +2 -2
- flip/data/test_covariance_reference_values.json +145 -0
- flip/data/test_e2e_reference_values.json +14 -0
- flip/data_vector/basic.py +118 -101
- flip/data_vector/cosmo_utils.py +18 -0
- flip/data_vector/galaxypv_vectors.py +58 -94
- flip/data_vector/snia_vectors.py +60 -3
- flip/data_vector/vector_utils.py +47 -1
- flip/power_spectra/class_engine.py +36 -1
- flip/power_spectra/cosmoprimo_engine.py +37 -2
- flip/power_spectra/generator.py +47 -25
- flip/power_spectra/models.py +30 -31
- flip/power_spectra/pyccl_engine.py +36 -1
- flip/simulation/__init__.py +0 -0
- flip/utils.py +62 -91
- flipcosmo-1.2.1.dist-info/METADATA +78 -0
- flipcosmo-1.2.1.dist-info/RECORD +109 -0
- {flipcosmo-1.0.0.dist-info → flipcosmo-1.2.1.dist-info}/WHEEL +1 -1
- flipcosmo-1.2.1.dist-info/top_level.txt +7 -0
- scripts/flip_compute_correlation_model.py +70 -0
- scripts/flip_compute_power_spectra.py +50 -0
- scripts/flip_fisher_forecast_velocity.py +70 -0
- scripts/flip_fisher_rcrk24.py +164 -0
- scripts/flip_launch_minuit_density_fit.py +91 -0
- scripts/flip_launch_minuit_full_fit.py +117 -0
- scripts/flip_launch_minuit_velocity_fit.py +78 -0
- scripts/flip_launch_minuit_velocity_fit_full.py +107 -0
- scripts/flip_launch_minuit_velocity_fit_interpolation.py +93 -0
- test/refresh_reference_values.py +43 -0
- test/test_covariance_assembly.py +102 -0
- test/test_covariance_reference_values.py +125 -0
- test/test_covariance_utils.py +34 -0
- test/test_e2e_density.py +50 -0
- test/test_e2e_joint.py +65 -0
- test/test_e2e_velocity.py +53 -0
- test/test_likelihood_inversions.py +31 -0
- flip/covariance/carreres23/generator.py +0 -132
- flip/data/density_data.parquet +0 -0
- flip/data/velocity_data.parquet +0 -0
- flip/fisher.py +0 -190
- flipcosmo-1.0.0.dist-info/METADATA +0 -32
- flipcosmo-1.0.0.dist-info/RECORD +0 -82
- flipcosmo-1.0.0.dist-info/top_level.txt +0 -1
- /flip/{config.py → _config.py} +0 -0
- /flip/covariance/{adamsblake17 → analytical/adamsblake17}/__init__.py +0 -0
- /flip/covariance/{adamsblake17plane → analytical/adamsblake17plane}/__init__.py +0 -0
- /flip/covariance/{adamsblake20 → analytical/adamsblake20}/__init__.py +0 -0
- /flip/covariance/{carreres23 → analytical/carreres23}/__init__.py +0 -0
- /flip/covariance/{lai22 → analytical/lai22}/__init__.py +0 -0
- /flip/covariance/{lai22 → analytical/lai22}/h_terms.py +0 -0
- /flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/__init__.py +0 -0
- /flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/flip_terms_lmax.py +0 -0
- /flip/covariance/{ravouxnoanchor25 → analytical/ravouxnoanchor25}/__init__.py +0 -0
- /flip/covariance/{rcrk24 → analytical/rcrk24}/__init__.py +0 -0
- {flipcosmo-1.0.0.dist-info → flipcosmo-1.2.1.dist-info}/licenses/LICENSE +0 -0
flip/covariance/generator.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import importlib
|
|
1
2
|
import multiprocessing as mp
|
|
2
3
|
from functools import partial
|
|
3
4
|
|
|
@@ -9,14 +10,6 @@ from scipy.signal import savgol_filter
|
|
|
9
10
|
from scipy.special import spherical_jn
|
|
10
11
|
|
|
11
12
|
from flip.covariance import cov_utils
|
|
12
|
-
from flip.covariance.adamsblake17 import flip_terms as flip_terms_adamsblake17
|
|
13
|
-
from flip.covariance.adamsblake17plane import flip_terms as flip_terms_adamsblake17plane
|
|
14
|
-
from flip.covariance.adamsblake20 import flip_terms as flip_terms_adamsblake20
|
|
15
|
-
from flip.covariance.carreres23 import flip_terms as flip_terms_carreres23
|
|
16
|
-
from flip.covariance.lai22 import flip_terms as flip_terms_lai22
|
|
17
|
-
from flip.covariance.ravouxcarreres import flip_terms as flip_terms_ravouxcarreres
|
|
18
|
-
from flip.covariance.ravouxnoanchor25 import flip_terms as flip_terms_ravouxnoanchor25
|
|
19
|
-
from flip.covariance.rcrk24 import flip_terms as flip_terms_rcrk24
|
|
20
13
|
from flip.utils import create_log
|
|
21
14
|
|
|
22
15
|
log = create_log()
|
|
@@ -38,7 +31,7 @@ _avail_regularization_option = [
|
|
|
38
31
|
]
|
|
39
32
|
|
|
40
33
|
|
|
41
|
-
def correlation_integration(
|
|
34
|
+
def correlation_integration(ell, r, k, integrand):
|
|
42
35
|
"""
|
|
43
36
|
The correlation_integration function is used to calculate the correlation function for a given multipole.
|
|
44
37
|
It does this by integrating over k, which is the magnitude of the wavevector. The integration is performed using
|
|
@@ -53,17 +46,20 @@ def correlation_integration(l, r, k, integrand):
|
|
|
53
46
|
integrand: Calculate the integrand of the correlation function
|
|
54
47
|
|
|
55
48
|
Returns:
|
|
56
|
-
|
|
49
|
+
ndarray: Correlation function $xi_\ell(r)$ via Simpson integration.
|
|
57
50
|
|
|
58
51
|
"""
|
|
59
52
|
kr = np.outer(k, r)
|
|
60
53
|
integrand = (
|
|
61
|
-
(-1) ** (
|
|
54
|
+
(-1) ** (ell // 2)
|
|
55
|
+
* (k**2 / (2 * np.pi**2))
|
|
56
|
+
* integrand
|
|
57
|
+
* spherical_jn(ell, kr).T
|
|
62
58
|
)
|
|
63
|
-
return (-1) ** (
|
|
59
|
+
return (-1) ** (ell % 2) * integrate.simpson(integrand, x=k)
|
|
64
60
|
|
|
65
61
|
|
|
66
|
-
def correlation_hankel(
|
|
62
|
+
def correlation_hankel(ell, r, k, integrand, hankel_overhead_coefficient=2, kmin=None):
|
|
67
63
|
"""
|
|
68
64
|
The correlation_hankel function is a wrapper for the cosmoprimo.fftlog.PowerToCorrelation function,
|
|
69
65
|
which computes the correlation function from power spectrum using FFTLog (Hamilton 2000).
|
|
@@ -79,12 +75,12 @@ def correlation_hankel(l, r, k, integrand, hankel_overhead_coefficient=2, kmin=N
|
|
|
79
75
|
hankel_overhead_coefficient: Determine the minimum r value for which to use the hankel transform
|
|
80
76
|
|
|
81
77
|
Returns:
|
|
82
|
-
|
|
78
|
+
ndarray: Correlation function $xi_\ell(r)$ combining Hankel and direct integration.
|
|
83
79
|
|
|
84
80
|
Note:
|
|
85
81
|
If l is odd, count a 1j term in the integrand, without the need for adding it
|
|
86
82
|
"""
|
|
87
|
-
Hankel = cosmoprimo.fftlog.PowerToCorrelation(k, ell=
|
|
83
|
+
Hankel = cosmoprimo.fftlog.PowerToCorrelation(k, ell=ell, q=0, complex=False)
|
|
88
84
|
Hankel.set_fft_engine("numpy")
|
|
89
85
|
r_hankel, xi_hankel = Hankel(integrand)
|
|
90
86
|
mask = r < np.min(r_hankel) * hankel_overhead_coefficient
|
|
@@ -93,13 +89,13 @@ def correlation_hankel(l, r, k, integrand, hankel_overhead_coefficient=2, kmin=N
|
|
|
93
89
|
"Min pw spectrum k is too high, please take a lower one. Use kmin parameter to lower bound integration."
|
|
94
90
|
)
|
|
95
91
|
output = np.empty_like(r)
|
|
96
|
-
output[mask] = correlation_integration(
|
|
97
|
-
output[~mask] = (-1) ** (
|
|
92
|
+
output[mask] = correlation_integration(ell, r[mask], k, integrand)
|
|
93
|
+
output[~mask] = (-1) ** (ell % 2) * np.interp(r[~mask], r_hankel, xi_hankel)
|
|
98
94
|
|
|
99
95
|
# Regularization
|
|
100
96
|
if kmin is not None:
|
|
101
97
|
kreg = np.geomspace(np.min(k), kmin, int(len(k) / 20))
|
|
102
|
-
output -= correlation_integration(
|
|
98
|
+
output -= correlation_integration(ell, r, kreg, np.interp(kreg, k, integrand))
|
|
103
99
|
return output
|
|
104
100
|
|
|
105
101
|
|
|
@@ -134,23 +130,24 @@ def coefficient_hankel(
|
|
|
134
130
|
: Define the model name
|
|
135
131
|
|
|
136
132
|
Returns:
|
|
137
|
-
|
|
133
|
+
ndarray: Covariance contribution for term `term_index`.
|
|
138
134
|
|
|
139
135
|
"""
|
|
136
|
+
flip_terms = importlib.import_module(
|
|
137
|
+
f"flip.covariance.analytical.{model_name}.flip_terms", package=__package__
|
|
138
|
+
)
|
|
139
|
+
|
|
140
140
|
cov_ab_i = 0
|
|
141
|
-
flip_terms = eval(f"flip_terms_{model_name}")
|
|
142
141
|
flip_terms.set_backend("numpy")
|
|
143
142
|
dictionary_subterms = flip_terms.dictionary_subterms
|
|
144
143
|
regularize_M_terms = flip_terms.regularize_M_terms
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
wavenumber, coord[3], coord[4], *additional_parameters_values
|
|
149
|
-
) # Shape issue: Z_ab_i is an outer product. How to include that in the Hankel transform?
|
|
150
|
-
for l in range(lmax + 1):
|
|
151
|
-
number_terms = dictionary_subterms[f"{covariance_type}_{term_index}_{l}"]
|
|
144
|
+
|
|
145
|
+
for ell in range(lmax + 1):
|
|
146
|
+
number_terms = dictionary_subterms[f"{covariance_type}_{term_index}_{ell}"]
|
|
152
147
|
for j in range(number_terms):
|
|
153
|
-
M_ab_i_l_j =
|
|
148
|
+
M_ab_i_l_j = getattr(
|
|
149
|
+
flip_terms, f"M_{covariance_type}_{term_index}_{ell}_{j}"
|
|
150
|
+
)
|
|
154
151
|
M_ab_i_l_j_evaluated = regularize_M(
|
|
155
152
|
M_ab_i_l_j,
|
|
156
153
|
wavenumber,
|
|
@@ -159,18 +156,18 @@ def coefficient_hankel(
|
|
|
159
156
|
flip_terms,
|
|
160
157
|
additional_parameters_values,
|
|
161
158
|
)
|
|
162
|
-
|
|
163
|
-
N_ab_i_l_j =
|
|
164
|
-
|
|
165
|
-
)
|
|
159
|
+
|
|
160
|
+
N_ab_i_l_j = getattr(
|
|
161
|
+
flip_terms, f"N_{covariance_type}_{term_index}_{ell}_{j}"
|
|
162
|
+
)(coord[1], coord[2])
|
|
166
163
|
hankel_ab_i_l_j = correlation_hankel(
|
|
167
|
-
|
|
164
|
+
ell,
|
|
168
165
|
coord[0],
|
|
169
166
|
wavenumber,
|
|
170
167
|
M_ab_i_l_j_evaluated * power_spectrum,
|
|
171
168
|
**kwargs,
|
|
172
169
|
)
|
|
173
|
-
cov_ab_i
|
|
170
|
+
cov_ab_i += N_ab_i_l_j * hankel_ab_i_l_j
|
|
174
171
|
return cov_ab_i
|
|
175
172
|
|
|
176
173
|
|
|
@@ -200,23 +197,23 @@ def coefficient_trapz(
|
|
|
200
197
|
: Determine the model to be used
|
|
201
198
|
|
|
202
199
|
Returns:
|
|
203
|
-
|
|
200
|
+
ndarray: Covariance contribution for term `term_index`.
|
|
204
201
|
|
|
205
202
|
"""
|
|
206
203
|
cov_ab_i = 0
|
|
207
|
-
flip_terms =
|
|
204
|
+
flip_terms = importlib.import_module(
|
|
205
|
+
f"flip.covariance.analytical.{model_name}.flip_terms", package=__package__
|
|
206
|
+
)
|
|
208
207
|
flip_terms.set_backend("numpy")
|
|
209
208
|
dictionary_subterms = flip_terms.dictionary_subterms
|
|
210
209
|
regularize_M_terms = flip_terms.regularize_M_terms
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
wavenumber, coord[3], coord[4], *additional_parameters_values
|
|
215
|
-
)
|
|
216
|
-
for l in range(lmax + 1):
|
|
217
|
-
number_terms = dictionary_subterms[f"{covariance_type}_{term_index}_{l}"]
|
|
210
|
+
|
|
211
|
+
for ell in range(lmax + 1):
|
|
212
|
+
number_terms = dictionary_subterms[f"{covariance_type}_{term_index}_{ell}"]
|
|
218
213
|
for j in range(number_terms):
|
|
219
|
-
M_ab_i_l_j =
|
|
214
|
+
M_ab_i_l_j = getattr(
|
|
215
|
+
flip_terms, f"M_{covariance_type}_{term_index}_{ell}_{j}"
|
|
216
|
+
)
|
|
220
217
|
M_ab_i_l_j_evaluated = regularize_M(
|
|
221
218
|
M_ab_i_l_j,
|
|
222
219
|
wavenumber,
|
|
@@ -225,20 +222,19 @@ def coefficient_trapz(
|
|
|
225
222
|
flip_terms,
|
|
226
223
|
additional_parameters_values,
|
|
227
224
|
)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
)
|
|
225
|
+
N_ab_i_l_j = getattr(
|
|
226
|
+
flip_terms, f"N_{covariance_type}_{term_index}_{ell}_{j}"
|
|
227
|
+
)(coord[1], coord[2])
|
|
232
228
|
kr = np.outer(wavenumber, coord[0])
|
|
233
229
|
integrand = (
|
|
234
|
-
(-1) ** (
|
|
230
|
+
(-1) ** (ell // 2)
|
|
235
231
|
* (wavenumber**2 / (2 * np.pi**2))
|
|
236
232
|
* M_ab_i_l_j_evaluated
|
|
237
233
|
* power_spectrum
|
|
238
|
-
* spherical_jn(
|
|
234
|
+
* spherical_jn(ell, kr).T
|
|
239
235
|
)
|
|
240
|
-
hankel_ab_i_l_j = (-1) ** (
|
|
241
|
-
cov_ab_i
|
|
236
|
+
hankel_ab_i_l_j = (-1) ** (ell % 2) * np.trapezoid(integrand, x=wavenumber)
|
|
237
|
+
cov_ab_i += N_ab_i_l_j * hankel_ab_i_l_j
|
|
242
238
|
return cov_ab_i
|
|
243
239
|
|
|
244
240
|
|
|
@@ -255,7 +251,28 @@ def regularize_M(
|
|
|
255
251
|
lowk_unstable_mean_filtering=10,
|
|
256
252
|
mpmmath_decimal_precision=50,
|
|
257
253
|
):
|
|
254
|
+
"""Evaluate and optionally regularize M(k) term.
|
|
255
|
+
|
|
256
|
+
Applies one of the supported regularizations to stabilize numerical
|
|
257
|
+
behavior (mpmath high-precision, Savitzky–Golay smoothing, or low-k
|
|
258
|
+
asymptote detection).
|
|
258
259
|
|
|
260
|
+
Args:
|
|
261
|
+
M_function (callable): Function returning M(k) given additional parameters.
|
|
262
|
+
wavenumber (ndarray): k samples.
|
|
263
|
+
regularize_M_terms (dict|None): Per type regularization option.
|
|
264
|
+
covariance_type (str): `"gg"`, `"gv"`, or `"vv"`.
|
|
265
|
+
flip_terms (module): Terms module to switch backend when needed.
|
|
266
|
+
additional_parameters_values (dict|tuple): Extra parameters for M.
|
|
267
|
+
savgol_window (int): Window size for Savitzky–Golay.
|
|
268
|
+
savgol_polynomial (int): Polynomial order for Savitzky–Golay.
|
|
269
|
+
lowk_unstable_threshold (float): Threshold for low-k asymptote detection.
|
|
270
|
+
lowk_unstable_mean_filtering (int): Window for mean filtering indices.
|
|
271
|
+
mpmmath_decimal_precision (int): Decimal precision for mpmath.
|
|
272
|
+
|
|
273
|
+
Returns:
|
|
274
|
+
ndarray: Evaluated M(k) after regularization.
|
|
275
|
+
"""
|
|
259
276
|
if regularize_M_terms is None:
|
|
260
277
|
return M_function(*additional_parameters_values)(wavenumber)
|
|
261
278
|
else:
|
|
@@ -331,7 +348,6 @@ def compute_coordinates(
|
|
|
331
348
|
covariance_type,
|
|
332
349
|
coordinates_density=None,
|
|
333
350
|
coordinates_velocity=None,
|
|
334
|
-
redshift_dict=None,
|
|
335
351
|
size_batch=10_000,
|
|
336
352
|
los_definition="bisector",
|
|
337
353
|
):
|
|
@@ -346,21 +362,17 @@ def compute_coordinates(
|
|
|
346
362
|
: Compute the angle separation between two objects
|
|
347
363
|
|
|
348
364
|
Returns:
|
|
349
|
-
|
|
365
|
+
list: Per-batch arrays `[r, theta, phi]`.
|
|
350
366
|
"""
|
|
351
367
|
if covariance_type == "gg":
|
|
352
368
|
ra = coordinates_density[0]
|
|
353
369
|
dec = coordinates_density[1]
|
|
354
370
|
comoving_distance = coordinates_density[2]
|
|
355
|
-
if redshift_dict is not None:
|
|
356
|
-
redshift = redshift_dict["g"]
|
|
357
371
|
number_objects = len(ra)
|
|
358
372
|
elif covariance_type == "vv":
|
|
359
373
|
ra = coordinates_velocity[0]
|
|
360
374
|
dec = coordinates_velocity[1]
|
|
361
375
|
comoving_distance = coordinates_velocity[2]
|
|
362
|
-
if redshift_dict is not None:
|
|
363
|
-
redshift = redshift_dict["v"]
|
|
364
376
|
number_objects = len(ra)
|
|
365
377
|
elif covariance_type == "gv":
|
|
366
378
|
ra_g = coordinates_density[0]
|
|
@@ -368,9 +380,6 @@ def compute_coordinates(
|
|
|
368
380
|
comoving_distance_g = coordinates_density[2]
|
|
369
381
|
ra_v = coordinates_velocity[0]
|
|
370
382
|
dec_v = coordinates_velocity[1]
|
|
371
|
-
if redshift_dict is not None:
|
|
372
|
-
redshift_g = redshift_dict["g"]
|
|
373
|
-
redshift_v = redshift_dict["v"]
|
|
374
383
|
comoving_distance_v = coordinates_velocity[2]
|
|
375
384
|
number_objects_g = len(ra_g)
|
|
376
385
|
number_objects_v = len(ra_v)
|
|
@@ -399,9 +408,6 @@ def compute_coordinates(
|
|
|
399
408
|
dec_v[j_list],
|
|
400
409
|
comoving_distance_v[j_list],
|
|
401
410
|
)
|
|
402
|
-
if redshift_dict is not None:
|
|
403
|
-
z_i = redshift_g[i_list]
|
|
404
|
-
z_j = redshift_v[j_list]
|
|
405
411
|
else:
|
|
406
412
|
i_list, j_list = cov_utils.compute_i_j(number_objects, batches)
|
|
407
413
|
ra_i, dec_i, r_i = (
|
|
@@ -414,16 +420,10 @@ def compute_coordinates(
|
|
|
414
420
|
dec[j_list],
|
|
415
421
|
comoving_distance[j_list],
|
|
416
422
|
)
|
|
417
|
-
if redshift_dict is not None:
|
|
418
|
-
z_i = redshift[i_list]
|
|
419
|
-
z_j = redshift[j_list]
|
|
420
423
|
r, theta, phi = cov_utils.angle_separation(
|
|
421
424
|
ra_i, ra_j, dec_i, dec_j, r_i, r_j, los_definition=los_definition
|
|
422
425
|
)
|
|
423
|
-
|
|
424
|
-
parameters.append([r, theta, phi, z_i, z_j])
|
|
425
|
-
else:
|
|
426
|
-
parameters.append([r, theta, phi])
|
|
426
|
+
parameters.append([r, theta, phi])
|
|
427
427
|
return parameters
|
|
428
428
|
|
|
429
429
|
|
|
@@ -451,18 +451,21 @@ def compute_coeficient(
|
|
|
451
451
|
: Define the number of threads used to compute the covariance matrix
|
|
452
452
|
|
|
453
453
|
Returns:
|
|
454
|
-
|
|
454
|
+
ndarray: Stacked covariance arrays per term index.
|
|
455
455
|
"""
|
|
456
456
|
if additional_parameters_values is None:
|
|
457
|
-
additional_parameters_values =
|
|
457
|
+
additional_parameters_values = {}
|
|
458
458
|
if hankel:
|
|
459
459
|
coefficient = coefficient_hankel
|
|
460
460
|
else:
|
|
461
461
|
coefficient = coefficient_trapz
|
|
462
462
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
463
|
+
flip_terms = importlib.import_module(
|
|
464
|
+
f"flip.covariance.analytical.{model_name}.flip_terms", package=__package__
|
|
465
|
+
)
|
|
466
|
+
term_index_list = getattr(flip_terms, "dictionary_terms")[covariance_type]
|
|
467
|
+
lmax_list = getattr(flip_terms, "dictionary_lmax")[covariance_type]
|
|
468
|
+
multi_index_model = getattr(flip_terms, "multi_index_model")
|
|
466
469
|
|
|
467
470
|
function_covariance_dict = {}
|
|
468
471
|
for i, index in enumerate(term_index_list):
|
|
@@ -540,7 +543,6 @@ def compute_cov(
|
|
|
540
543
|
power_spectrum_list,
|
|
541
544
|
coordinates_density=None,
|
|
542
545
|
coordinates_velocity=None,
|
|
543
|
-
redshift_dict=None,
|
|
544
546
|
additional_parameters_values=None,
|
|
545
547
|
size_batch=10_000,
|
|
546
548
|
number_worker=8,
|
|
@@ -564,7 +566,7 @@ def compute_cov(
|
|
|
564
566
|
: Compute the covariance matrix for a given model
|
|
565
567
|
|
|
566
568
|
Returns:
|
|
567
|
-
|
|
569
|
+
ndarray: Covariance arrays per term index.
|
|
568
570
|
|
|
569
571
|
"""
|
|
570
572
|
if model_name not in _avail_models:
|
|
@@ -577,7 +579,6 @@ def compute_cov(
|
|
|
577
579
|
covariance_type,
|
|
578
580
|
coordinates_density=coordinates_density,
|
|
579
581
|
coordinates_velocity=coordinates_velocity,
|
|
580
|
-
redshift_dict=redshift_dict,
|
|
581
582
|
size_batch=size_batch,
|
|
582
583
|
los_definition=los_definition,
|
|
583
584
|
)
|
|
@@ -595,17 +596,6 @@ def compute_cov(
|
|
|
595
596
|
return covariance
|
|
596
597
|
|
|
597
598
|
|
|
598
|
-
def get_redshift_dependent_model_flag(model_name):
|
|
599
|
-
"""
|
|
600
|
-
The get_redshift_dependent_model_flag function returns a boolean indicating whether the model is redshift dependent or not.
|
|
601
|
-
|
|
602
|
-
Args:
|
|
603
|
-
model_name: Determine which model to use
|
|
604
|
-
"""
|
|
605
|
-
redshift_dependent_model = eval(f"flip_terms_{model_name}.redshift_dependent_model")
|
|
606
|
-
return redshift_dependent_model
|
|
607
|
-
|
|
608
|
-
|
|
609
599
|
def generate_covariance(
|
|
610
600
|
model_name,
|
|
611
601
|
model_kind,
|
|
@@ -635,7 +625,7 @@ def generate_covariance(
|
|
|
635
625
|
: Define the number of workers to use for the computation
|
|
636
626
|
|
|
637
627
|
Returns:
|
|
638
|
-
|
|
628
|
+
tuple: `(covariance_dict, number_densities, number_velocities)`.
|
|
639
629
|
|
|
640
630
|
"""
|
|
641
631
|
cov_utils.check_generator_need(
|
|
@@ -645,17 +635,6 @@ def generate_covariance(
|
|
|
645
635
|
)
|
|
646
636
|
covariance_dict = {}
|
|
647
637
|
|
|
648
|
-
redshift_dependent_model = get_redshift_dependent_model_flag(model_name)
|
|
649
|
-
if redshift_dependent_model:
|
|
650
|
-
redshift_dict = cov_utils.generate_redshift_dict(
|
|
651
|
-
redshift_dependent_model,
|
|
652
|
-
model_kind,
|
|
653
|
-
coordinates_velocity=coordinates_velocity,
|
|
654
|
-
coordinates_density=coordinates_density,
|
|
655
|
-
)
|
|
656
|
-
else:
|
|
657
|
-
redshift_dict = None
|
|
658
|
-
|
|
659
638
|
if model_kind in ["density", "full", "density_velocity"]:
|
|
660
639
|
covariance_dict["gg"] = compute_cov(
|
|
661
640
|
model_name,
|
|
@@ -663,7 +642,6 @@ def generate_covariance(
|
|
|
663
642
|
power_spectrum_dict["gg"],
|
|
664
643
|
coordinates_density=coordinates_density,
|
|
665
644
|
coordinates_velocity=coordinates_velocity,
|
|
666
|
-
redshift_dict=redshift_dict,
|
|
667
645
|
additional_parameters_values=additional_parameters_values,
|
|
668
646
|
size_batch=size_batch,
|
|
669
647
|
number_worker=number_worker,
|
|
@@ -682,7 +660,6 @@ def generate_covariance(
|
|
|
682
660
|
power_spectrum_dict["vv"],
|
|
683
661
|
coordinates_density=coordinates_density,
|
|
684
662
|
coordinates_velocity=coordinates_velocity,
|
|
685
|
-
redshift_dict=redshift_dict,
|
|
686
663
|
additional_parameters_values=additional_parameters_values,
|
|
687
664
|
size_batch=size_batch,
|
|
688
665
|
number_worker=number_worker,
|
|
@@ -701,7 +678,6 @@ def generate_covariance(
|
|
|
701
678
|
power_spectrum_dict["gv"],
|
|
702
679
|
coordinates_density=coordinates_density,
|
|
703
680
|
coordinates_velocity=coordinates_velocity,
|
|
704
|
-
redshift_dict=redshift_dict,
|
|
705
681
|
additional_parameters_values=additional_parameters_values,
|
|
706
682
|
size_batch=size_batch,
|
|
707
683
|
number_worker=number_worker,
|
|
@@ -710,4 +686,4 @@ def generate_covariance(
|
|
|
710
686
|
kmin=kmin,
|
|
711
687
|
)
|
|
712
688
|
|
|
713
|
-
return covariance_dict, number_densities, number_velocities
|
|
689
|
+
return covariance_dict, number_densities, number_velocities
|