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.
Files changed (113) hide show
  1. docs/conf.py +154 -0
  2. flip/__init__.py +4 -11
  3. flip/covariance/__init__.py +7 -8
  4. flip/covariance/analytical/__init__.py +11 -0
  5. flip/covariance/{adamsblake17plane → analytical/adamsblake17}/coefficients.py +1 -1
  6. flip/covariance/{adamsblake17plane → analytical/adamsblake17}/fisher_terms.py +1 -1
  7. flip/covariance/{adamsblake17 → analytical/adamsblake17}/flip_terms.py +0 -1
  8. flip/covariance/{adamsblake17 → analytical/adamsblake17plane}/coefficients.py +1 -1
  9. flip/covariance/{adamsblake17 → analytical/adamsblake17plane}/fisher_terms.py +1 -1
  10. flip/covariance/{adamsblake17plane → analytical/adamsblake17plane}/flip_terms.py +0 -1
  11. flip/covariance/{adamsblake17plane → analytical/adamsblake17plane}/generator.py +103 -19
  12. flip/covariance/{adamsblake20 → analytical/adamsblake20}/coefficients.py +1 -1
  13. flip/covariance/{adamsblake20 → analytical/adamsblake20}/fisher_terms.py +1 -1
  14. flip/covariance/{adamsblake20 → analytical/adamsblake20}/flip_terms.py +0 -1
  15. flip/covariance/{carreres23 → analytical/carreres23}/coefficients.py +1 -4
  16. flip/covariance/{ravouxnoanchor25 → analytical/carreres23}/fisher_terms.py +1 -1
  17. flip/covariance/{carreres23 → analytical/carreres23}/flip_terms.py +0 -1
  18. flip/covariance/analytical/carreres23/generator.py +198 -0
  19. flip/covariance/analytical/genericzdep/__init__.py +5 -0
  20. flip/covariance/analytical/genericzdep/coefficients.py +53 -0
  21. flip/covariance/analytical/genericzdep/flip_terms.py +99 -0
  22. flip/covariance/{lai22 → analytical/lai22}/coefficients.py +2 -3
  23. flip/covariance/{lai22 → analytical/lai22}/fisher_terms.py +1 -1
  24. flip/covariance/{lai22 → analytical/lai22}/flip_terms.py +0 -1
  25. flip/covariance/{lai22 → analytical/lai22}/generator.py +263 -58
  26. flip/covariance/{lai22 → analytical/lai22}/symbolic.py +55 -19
  27. flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/coefficients.py +1 -1
  28. flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/fisher_terms.py +1 -1
  29. flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/flip_terms.py +0 -1
  30. flip/covariance/{ravouxnoanchor25 → analytical/ravouxnoanchor25}/coefficients.py +3 -2
  31. flip/covariance/{carreres23 → analytical/ravouxnoanchor25}/fisher_terms.py +1 -1
  32. flip/covariance/{ravouxnoanchor25 → analytical/ravouxnoanchor25}/flip_terms.py +0 -9
  33. flip/covariance/{rcrk24 → analytical/rcrk24}/coefficients.py +6 -6
  34. flip/covariance/{rcrk24 → analytical/rcrk24}/fisher_terms.py +7 -9
  35. flip/covariance/{rcrk24 → analytical/rcrk24}/flip_terms.py +0 -8
  36. flip/covariance/contraction.py +82 -40
  37. flip/covariance/cov_utils.py +89 -81
  38. flip/covariance/covariance.py +172 -141
  39. flip/covariance/emulators/__init__.py +1 -1
  40. flip/covariance/emulators/generator.py +73 -3
  41. flip/covariance/emulators/gpmatrix.py +40 -1
  42. flip/covariance/emulators/nnmatrix.py +57 -1
  43. flip/covariance/emulators/skgpmatrix.py +125 -0
  44. flip/covariance/fisher.py +307 -0
  45. flip/{fit_utils.py → covariance/fit_utils.py} +185 -10
  46. flip/{fitter.py → covariance/fitter.py} +151 -125
  47. flip/covariance/generator.py +82 -106
  48. flip/{likelihood.py → covariance/likelihood.py} +286 -64
  49. flip/{plot_utils.py → covariance/plot_utils.py} +79 -4
  50. flip/covariance/symbolic.py +89 -44
  51. flip/data/__init__.py +1 -1
  52. flip/data/data_density.parquet +0 -0
  53. flip/data/data_velocity.parquet +0 -0
  54. flip/data/{grid_window_m.parquet → data_window_density.parquet} +0 -0
  55. flip/{gridding.py → data/gridding.py} +125 -130
  56. flip/data/load_data_test.py +102 -0
  57. flip/data/power_spectrum_mm.txt +2 -2
  58. flip/data/power_spectrum_mt.txt +2 -2
  59. flip/data/power_spectrum_tt.txt +2 -2
  60. flip/data/test_covariance_reference_values.json +145 -0
  61. flip/data/test_e2e_reference_values.json +14 -0
  62. flip/data_vector/basic.py +118 -101
  63. flip/data_vector/cosmo_utils.py +18 -0
  64. flip/data_vector/galaxypv_vectors.py +58 -94
  65. flip/data_vector/snia_vectors.py +60 -3
  66. flip/data_vector/vector_utils.py +47 -1
  67. flip/power_spectra/class_engine.py +36 -1
  68. flip/power_spectra/cosmoprimo_engine.py +37 -2
  69. flip/power_spectra/generator.py +47 -25
  70. flip/power_spectra/models.py +30 -31
  71. flip/power_spectra/pyccl_engine.py +36 -1
  72. flip/simulation/__init__.py +0 -0
  73. flip/utils.py +62 -91
  74. flipcosmo-1.2.1.dist-info/METADATA +78 -0
  75. flipcosmo-1.2.1.dist-info/RECORD +109 -0
  76. {flipcosmo-1.0.0.dist-info → flipcosmo-1.2.1.dist-info}/WHEEL +1 -1
  77. flipcosmo-1.2.1.dist-info/top_level.txt +7 -0
  78. scripts/flip_compute_correlation_model.py +70 -0
  79. scripts/flip_compute_power_spectra.py +50 -0
  80. scripts/flip_fisher_forecast_velocity.py +70 -0
  81. scripts/flip_fisher_rcrk24.py +164 -0
  82. scripts/flip_launch_minuit_density_fit.py +91 -0
  83. scripts/flip_launch_minuit_full_fit.py +117 -0
  84. scripts/flip_launch_minuit_velocity_fit.py +78 -0
  85. scripts/flip_launch_minuit_velocity_fit_full.py +107 -0
  86. scripts/flip_launch_minuit_velocity_fit_interpolation.py +93 -0
  87. test/refresh_reference_values.py +43 -0
  88. test/test_covariance_assembly.py +102 -0
  89. test/test_covariance_reference_values.py +125 -0
  90. test/test_covariance_utils.py +34 -0
  91. test/test_e2e_density.py +50 -0
  92. test/test_e2e_joint.py +65 -0
  93. test/test_e2e_velocity.py +53 -0
  94. test/test_likelihood_inversions.py +31 -0
  95. flip/covariance/carreres23/generator.py +0 -132
  96. flip/data/density_data.parquet +0 -0
  97. flip/data/velocity_data.parquet +0 -0
  98. flip/fisher.py +0 -190
  99. flipcosmo-1.0.0.dist-info/METADATA +0 -32
  100. flipcosmo-1.0.0.dist-info/RECORD +0 -82
  101. flipcosmo-1.0.0.dist-info/top_level.txt +0 -1
  102. /flip/{config.py → _config.py} +0 -0
  103. /flip/covariance/{adamsblake17 → analytical/adamsblake17}/__init__.py +0 -0
  104. /flip/covariance/{adamsblake17plane → analytical/adamsblake17plane}/__init__.py +0 -0
  105. /flip/covariance/{adamsblake20 → analytical/adamsblake20}/__init__.py +0 -0
  106. /flip/covariance/{carreres23 → analytical/carreres23}/__init__.py +0 -0
  107. /flip/covariance/{lai22 → analytical/lai22}/__init__.py +0 -0
  108. /flip/covariance/{lai22 → analytical/lai22}/h_terms.py +0 -0
  109. /flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/__init__.py +0 -0
  110. /flip/covariance/{ravouxcarreres → analytical/ravouxcarreres}/flip_terms_lmax.py +0 -0
  111. /flip/covariance/{ravouxnoanchor25 → analytical/ravouxnoanchor25}/__init__.py +0 -0
  112. /flip/covariance/{rcrk24 → analytical/rcrk24}/__init__.py +0 -0
  113. {flipcosmo-1.0.0.dist-info → flipcosmo-1.2.1.dist-info}/licenses/LICENSE +0 -0
@@ -12,23 +12,20 @@ def compute_sep(
12
12
  los_definition="bisector",
13
13
  size_batch=10_000,
14
14
  ):
15
- """
16
- The compute_sep function computes the separation between all pairs of objects in a catalog.
15
+ """Compute pair separations in batches, returning r, r_perp, r_par.
17
16
 
18
17
  Args:
19
- ra: Store the right ascension of each object
20
- dec: Compute the angular separation between two objects
21
- comoving_distance: Calculate the separation between two objects
22
- size_batch: Control the number of objects that are processed at a time
23
- : Set the number of objects in a batch
18
+ ra (ndarray): Right ascensions in radians.
19
+ dec (ndarray): Declinations in radians.
20
+ comoving_distance (ndarray): Comoving distances in Mpc/h.
21
+ los_definition (str): Line-of-sight convention: `"bisector"`, `"mean"`, `"endpoint"`.
22
+ size_batch (int): Batch size for pairwise computation.
24
23
 
25
24
  Returns:
26
- The separation, the perpendicular component of the separation, and
27
-
25
+ tuple: `(sep, sep_perp, sep_par)` as 1D arrays including a leading zero for diagonal.
28
26
  """
29
27
  number_objects = len(ra)
30
28
  n_task = int((number_objects * (number_objects + 1)) / 2) - number_objects
31
-
32
29
  sep = []
33
30
  sep_perp = []
34
31
  sep_par = []
@@ -55,6 +52,44 @@ def compute_sep(
55
52
  return sep, sep_perp, sep_par
56
53
 
57
54
 
55
+ def compute_function_sym_matrix(
56
+ f, *args, compute_diag=True, fill_diag=0, size_batch=10_000
57
+ ):
58
+ """Apply a symmetric function over upper-triangular indices in batches.
59
+
60
+ Args:
61
+ f (callable): Function accepting stacked pair arrays per argument.
62
+ *args: Vectors to index into; each should be 1D arrays of same length.
63
+ compute_diag (bool): Include diagonal pairs when True.
64
+ fill_diag (int|float): Value inserted at the start when diagonal excluded.
65
+ size_batch (int): Batch size.
66
+
67
+ Returns:
68
+ ndarray: Concatenated results from `f` over all pairs.
69
+ """
70
+ number_objects = len(args[0])
71
+ if compute_diag:
72
+ k = 0
73
+ else:
74
+ k = 1
75
+
76
+ i_ref, j_ref = np.triu_indices(number_objects, k=k)
77
+ n_task = int((number_objects * (number_objects + 1)) / 2)
78
+ if not compute_diag:
79
+ n_task -= number_objects
80
+
81
+ res = []
82
+ for n in range(0, n_task, size_batch):
83
+ batches = np.arange(n, np.min((n + size_batch, n_task)))
84
+ i_list, j_list = i_ref[batches], j_ref[batches]
85
+ res.append(f(*np.vstack([[a[i_list], a[j_list]] for a in args])))
86
+ res = np.concatenate(res)
87
+
88
+ if fill_diag:
89
+ res = np.insert(res, 0, 0)
90
+ return res
91
+
92
+
58
93
  def compute_i_j(N, seq):
59
94
  """
60
95
  The compute_i_j function takes in a number of nodes N and a sequence number seq.
@@ -68,7 +103,7 @@ def compute_i_j(N, seq):
68
103
  seq: Find the row and column of the element in a matrix
69
104
 
70
105
  Returns:
71
- The row and column of the lower triangle matrix
106
+ tuple: `(i, j)` index arrays for the upper triangle.
72
107
 
73
108
  """
74
109
  i = (N - 2 - np.floor(np.sqrt(-8 * seq + 4 * N * (N - 1) - 7) / 2.0 - 0.5)).astype(
@@ -79,6 +114,17 @@ def compute_i_j(N, seq):
79
114
 
80
115
 
81
116
  def flatshape_to_fullshape(flat_shape_non_diagonal):
117
+ """Infer full matrix size from number of upper-triangular elements.
118
+
119
+ Args:
120
+ flat_shape_non_diagonal (int): Count of off-diagonal upper-triangular elements.
121
+
122
+ Returns:
123
+ int: Size `N` of the full square matrix.
124
+
125
+ Raises:
126
+ ValueError: If the provided count is not valid for any `N`.
127
+ """
82
128
  Delta = 1 + 8 * flat_shape_non_diagonal
83
129
  Nfull = (1 + np.sqrt(Delta)) / 2
84
130
  if Nfull - int(Nfull) > 0:
@@ -97,7 +143,7 @@ def compute_i_j_cross_matrix(Nv, seq):
97
143
  seq: Create the i and j arrays
98
144
 
99
145
  Returns:
100
- The indices of the cross-terms in the matrix
146
+ tuple: `(i, j)` index arrays for the rectangular cross matrix.
101
147
 
102
148
  """
103
149
  i = np.floor(1 + (seq - Nv) / Nv).astype("int")
@@ -123,7 +169,7 @@ def compute_phi(ra_0, ra_1, dec_0, dec_1, r_0, r_1, los_definition):
123
169
  los_definition: Define the line of sight
124
170
 
125
171
  Returns:
126
- The angle between the line of sight and the separation vector
172
+ ndarray: Angle `phi` in radians.
127
173
  """
128
174
  x_0, y_0, z_0 = utils.radec2cart(r_0, ra_0, dec_0)
129
175
  x_1, y_1, z_1 = utils.radec2cart(r_1, ra_1, dec_1)
@@ -177,21 +223,19 @@ def angle_separation(
177
223
  r_1,
178
224
  los_definition="bisector",
179
225
  ):
180
- """
181
- The angle_separation function computes the angle between two points on a sphere.
226
+ """Compute pair separation `r` and angles `theta`, `phi` between two points.
182
227
 
183
228
  Args:
184
- ra_0: Set the right ascension of the first galaxy
185
- ra_1: Calculate the angle between two points in the sky
186
- dec_0: Define the declination of the first galaxy
187
- dec_1: Calculate the cosine of theta
188
- r_0: Compute the distance between two points
189
- r_1: Compute the distance between two points in space
190
- los_definition: Define the line of sight
191
- : Define the line of sight
229
+ ra_0 (ndarray): RA for point 0.
230
+ ra_1 (ndarray): RA for point 1.
231
+ dec_0 (ndarray): Dec for point 0.
232
+ dec_1 (ndarray): Dec for point 1.
233
+ r_0 (ndarray): Comoving distance for point 0.
234
+ r_1 (ndarray): Comoving distance for point 1.
235
+ los_definition (str): Line-of-sight convention.
192
236
 
193
237
  Returns:
194
- The separation between two points in
238
+ tuple: `(r, theta, phi)` arrays.
195
239
  """
196
240
 
197
241
  cos_theta = np.cos(ra_1 - ra_0) * np.cos(dec_0) * np.cos(dec_1) + np.sin(
@@ -221,7 +265,7 @@ def return_matrix_covariance(flat_covariance):
221
265
  the upper-triangular elements of the covariance matrix.
222
266
 
223
267
  Returns:
224
- np.ndarray: The reconstructed full covariance matrix.
268
+ np.ndarray: Reconstructed full covariance matrix.
225
269
 
226
270
  Notes:
227
271
  - The function uses `flatshape_to_fullshape` to determine the size of the full matrix.
@@ -248,15 +292,11 @@ def return_flat_covariance(matrix_covariance):
248
292
  The returned array starts with the variance value (element at position [0, 0]),
249
293
  followed by the upper triangular elements of the covariance matrix (excluding the diagonal).
250
294
 
251
- Parameters
252
- ----------
253
- cov : numpy.ndarray
254
- A square covariance matrix.
295
+ Args:
296
+ matrix_covariance (ndarray): Square covariance matrix.
255
297
 
256
- Returns
257
- -------
258
- numpy.ndarray
259
- A one-dimensional array containing the variance and upper triangular covariance values.
298
+ Returns:
299
+ ndarray: 1D array containing variance then upper-triangular values.
260
300
  """
261
301
  variance_val = matrix_covariance[0, 0]
262
302
  flat_cov = matrix_covariance[np.triu_indices_from(matrix_covariance, k=1)]
@@ -265,6 +305,14 @@ def return_flat_covariance(matrix_covariance):
265
305
 
266
306
 
267
307
  def return_flat_cross_cov(cov):
308
+ """Flatten a rectangular cross-covariance matrix.
309
+
310
+ Args:
311
+ cov (ndarray): Rectangular covariance.
312
+
313
+ Returns:
314
+ ndarray: Flattened 1D array.
315
+ """
268
316
  return cov.flatten()
269
317
 
270
318
 
@@ -279,7 +327,7 @@ def return_matrix_covariance_cross(cov, number_objects_g, number_objects_v):
279
327
  number_objects_v: Reshape the covariance matrix into a full covariance matrix
280
328
 
281
329
  Returns:
282
- The full covariance matrix
330
+ ndarray: Reconstructed full cross-covariance matrix.
283
331
 
284
332
  """
285
333
  full_cov = cov.reshape((number_objects_g, number_objects_v))
@@ -295,7 +343,7 @@ def return_correlation_matrix(cov):
295
343
  cov: Calculate the correlation matrix
296
344
 
297
345
  Returns:
298
- The correlation matrix
346
+ ndarray: Correlation matrix.
299
347
 
300
348
  """
301
349
  sigma = np.sqrt(np.diag(cov))
@@ -312,7 +360,7 @@ def save_matrix(matrix, name):
312
360
  name: Save the matrix with a name
313
361
 
314
362
  Returns:
315
- The name of the file that was saved
363
+ str: Path of the saved file.
316
364
 
317
365
  """
318
366
  np.save(f"{name}.npy", matrix)
@@ -326,7 +374,7 @@ def open_matrix(name):
326
374
  name: Specify the name of the matrix to be loaded
327
375
 
328
376
  Returns:
329
- A matrix
377
+ ndarray: Loaded matrix.
330
378
 
331
379
  """
332
380
  matrix = np.load(f"{name}.npy")
@@ -348,19 +396,19 @@ def generator_need(
348
396
  : Check if the coordinates are provided or not
349
397
 
350
398
  Returns:
351
- A list of the coordinates that are needed to proceed with covariance generation
399
+ None
352
400
 
353
401
  """
354
402
  if coordinates_density is not False:
355
403
  if coordinates_density is None:
356
404
  log.add(
357
- f"The coordinates_density input is needed to proceed covariance generation, please provide it"
405
+ "The coordinates_density input is needed to proceed covariance generation, please provide it"
358
406
  )
359
407
  raise ValueError("Density coordinates not provided")
360
408
  if coordinates_velocity is not False:
361
409
  if coordinates_velocity is None:
362
410
  log.add(
363
- f"The coordinates_velocity input is needed to proceed covariance generation, please provide it"
411
+ "The coordinates_velocity input is needed to proceed covariance generation, please provide it"
364
412
  )
365
413
  raise ValueError("Velocity coordinates not provided")
366
414
 
@@ -377,7 +425,7 @@ def check_generator_need(model_kind, coordinates_density, coordinates_velocity):
377
425
  coordinates_velocity: Determine whether the velocity model is needed
378
426
 
379
427
  Returns:
380
- A boolean
428
+ None
381
429
 
382
430
  """
383
431
  if model_kind == "density":
@@ -395,43 +443,3 @@ def check_generator_need(model_kind, coordinates_density, coordinates_velocity):
395
443
  coordinates_density=coordinates_density,
396
444
  coordinates_velocity=coordinates_velocity,
397
445
  )
398
-
399
-
400
- def generate_redshift_dict(
401
- redshift_dependent_model,
402
- model_kind,
403
- redshift_velocity=None,
404
- redshift_density=None,
405
- coordinates_velocity=None,
406
- coordinates_density=None,
407
- ):
408
-
409
- redshift_dict = {}
410
-
411
- if model_kind in ["density", "full", "density_velocity"]:
412
- if redshift_dependent_model:
413
- if redshift_density is not None:
414
- redshift_dict["g"] = redshift_density
415
- else:
416
- if len(coordinates_density) < 4:
417
- raise ValueError(
418
- "You are using a model which is redshift dependent."
419
- "Please provide redshifts as the fourth field"
420
- "of the coordinates_density value"
421
- )
422
- else:
423
- redshift_dict["g"] = coordinates_density[3]
424
- if model_kind in ["velocity", "full", "density_velocity"]:
425
- if redshift_dependent_model:
426
- if redshift_velocity is not None:
427
- redshift_dict["v"] = redshift_velocity
428
- else:
429
- if len(coordinates_velocity) < 4:
430
- raise ValueError(
431
- "You are using a model which is redshift dependent."
432
- "Please provide redshifts as the fourth field"
433
- "of the coordinates_velocity value"
434
- )
435
- else:
436
- redshift_dict["v"] = coordinates_velocity[3]
437
- return redshift_dict