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
@@ -5,7 +5,7 @@ from flip import utils
5
5
  log = utils.create_log()
6
6
  try:
7
7
  from pypower import CatalogMesh
8
- except:
8
+ except ImportError:
9
9
  log.add("No pypower module detected, gridding with this method is unavailable")
10
10
 
11
11
  # CR - No cut in healpix implemented with randoms
@@ -14,18 +14,19 @@ _GRID_KIND = ["ngp", "ngp_errw", "cic", "tsc", "pcs"]
14
14
 
15
15
 
16
16
  def _compute_grid_window(grid_size, k, order, n):
17
- """
18
- The _compute_grid_window function computes the window function for a given grid size.
17
+ """Numerically compute isotropic grid assignment window.
18
+
19
+ Uses spherical averaging over directions to produce a 1D window for
20
+ resampler order (NGP/CIC/TSC/PCS) given grid size.
19
21
 
20
22
  Args:
21
- grid_size: Determine the size of the grid
22
- k: Compute the window function
23
- order: Determine the order of the sinc function
24
- n: Determine the number of points in the grid
23
+ grid_size (float): Grid cell size.
24
+ k (array-like): Wavenumbers at which to evaluate the window.
25
+ order (int): Assignment order (1:NGP, 2:CIC, 3:TSC, 4:PCS).
26
+ n (int): Number of angular samples for spherical averaging.
25
27
 
26
28
  Returns:
27
- The window function for a given grid size, k, order and n
28
-
29
+ numpy.ndarray: Window values for each `k`.
29
30
  """
30
31
  window = np.zeros_like(k)
31
32
  theta = np.linspace(0, np.pi, n)
@@ -50,18 +51,16 @@ def _compute_grid_window(grid_size, k, order, n):
50
51
 
51
52
 
52
53
  def compute_grid_window(grid_size, kh, kind="ngp", n=1000):
53
- """
54
- The compute_grid_window function computes the window function for a given grid size and kind.
54
+ """Compute grid assignment window for a given resampler kind.
55
55
 
56
56
  Args:
57
- grid_size: Define the size of the grid
58
- kh: Compute the window function
59
- kind: Specify the type of grid
60
- n: Define the number of points used to compute the window function
57
+ grid_size (float): Grid cell size.
58
+ kh (array-like): Wavenumbers at which to evaluate the window.
59
+ kind (str): One of `ngp`, `ngp_errw`, `cic`, `tsc`, `pcs`.
60
+ n (int): Angular samples for spherical averaging.
61
61
 
62
62
  Returns:
63
- A window function
64
-
63
+ numpy.ndarray|None: Window values, or None if `grid_size==0`.
65
64
  """
66
65
  _order_dic = {
67
66
  "ngp": 1,
@@ -80,16 +79,14 @@ def compute_grid_window(grid_size, kh, kind="ngp", n=1000):
80
79
 
81
80
 
82
81
  def construct_grid_regular_sphere(grid_size, rcom_max):
83
- """
84
- The construct_grid_regular_sphere function constructs a regular spherical grid.
82
+ """Construct a regular spherical grid of voxel centers.
85
83
 
86
84
  Args:
87
- grid_size: Determine the number of grid voxels per axis
88
- rcom_max: Cut the grid with rcom_max
85
+ grid_size (float): Cell size.
86
+ rcom_max (float): Maximum comoving radius cutoff.
89
87
 
90
88
  Returns:
91
- A dictionary with the following keys:
92
-
89
+ dict: Grid dictionary with keys `ra`, `dec`, `rcom`, `x`, `y`, `z` after cut.
93
90
  """
94
91
 
95
92
  # Number of grid voxels per axis
@@ -112,7 +109,7 @@ def construct_grid_regular_sphere(grid_size, rcom_max):
112
109
  grid = {
113
110
  "ra": center_ra,
114
111
  "dec": center_dec,
115
- "rcom": center_r_comov,
112
+ "rcom_zobs": center_r_comov,
116
113
  "x": cp_x,
117
114
  "y": cp_y,
118
115
  "z": cp_z,
@@ -123,16 +120,14 @@ def construct_grid_regular_sphere(grid_size, rcom_max):
123
120
 
124
121
 
125
122
  def construct_grid_regular_rectangular(grid_size, rcom_max):
126
- """
127
- The construct_grid_regular_rectangular function constructs a regular rectangular grid.
123
+ """Construct a regular rectangular grid of voxel centers.
128
124
 
129
125
  Args:
130
- grid_size: Determine the number of grid voxels per axis
131
- rcom_max: Determine the size of the grid
126
+ grid_size (float): Cell size.
127
+ rcom_max (float): Half-side length of the cube.
132
128
 
133
129
  Returns:
134
- A dictionary with the grid coordinates
135
-
130
+ dict: Grid dictionary with `ra`, `dec`, `rcom`, `x`, `y`, `z`.
136
131
  """
137
132
 
138
133
  # Number of grid voxels per axis
@@ -155,7 +150,7 @@ def construct_grid_regular_rectangular(grid_size, rcom_max):
155
150
  grid = {
156
151
  "ra": center_ra,
157
152
  "dec": center_dec,
158
- "rcom": center_r_comov,
153
+ "rcom_zobs": center_r_comov,
159
154
  "x": cp_x,
160
155
  "y": cp_y,
161
156
  "z": cp_z,
@@ -208,26 +203,21 @@ def attribute_weight_density(
208
203
  zgrid,
209
204
  weight_fun,
210
205
  ):
211
- """
212
- The attribute_weight_density function takes in the grid size, xobj, yobj, zobj (the coordinates of the objects),
213
- xgrid, ygrid and zgrid (the coordinates of the grid) and a weight function. It then calculates how many objects are
214
- in each cell by using a for loop to iterate through all of them. The dX is calculated by taking the difference between
215
- each object's x coordinate and each cell's x coordinate divided by grid_size. This is done for both dY and dZ as well.
216
- The w variable is calculated using this formula: w = weight_fun(dX)
206
+ """Accumulate assignment weights and counts for objects onto a grid.
217
207
 
218
208
  Args:
219
- grid_size: Normalize the distances between objects and grid points
220
- xobj: Store the x coordinates of all objects in a galaxy
221
- yobj: Create a grid of y values
222
- zobj: Calculate the z-component of the distance between a grid point and an object
223
- xgrid: Define the x-coordinate of each grid cell
224
- ygrid: Calculate the distance between the object and grid
225
- zgrid: Determine the z-coordinate of the grid cell
226
- weight_fun: Determine the weight of each object
209
+ grid_size (float): Cell size.
210
+ xobj (array-like): Object x positions.
211
+ yobj (array-like): Object y positions.
212
+ zobj (array-like): Object z positions.
213
+ xgrid (array-like): Grid x centers.
214
+ ygrid (array-like): Grid y centers.
215
+ zgrid (array-like): Grid z centers.
216
+ weight_fun (Callable): Resampler weight function of distance.
227
217
 
228
218
  Returns:
229
- A tuple of three arrays
230
-
219
+ tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]:
220
+ sum of weights, sum of squared weights, and objects-per-cell counts.
231
221
  """
232
222
 
233
223
  Nobj = len(xobj)
@@ -265,6 +255,25 @@ def define_randoms(
265
255
  coord_randoms=None,
266
256
  max_coordinates=None,
267
257
  ):
258
+ """Generate random positions for density estimation.
259
+
260
+ Supports cartesian uniform, choice-based on observed distributions, or from file.
261
+
262
+ Args:
263
+ random_method (str): `cartesian`, `choice`, `choice_redshift`, or `file`.
264
+ xobj (array-like): Data x positions.
265
+ yobj (array-like): Data y positions.
266
+ zobj (array-like): Data z positions.
267
+ raobj (array-like): Data right ascensions.
268
+ decobj (array-like): Data declinations.
269
+ rcomobj (array-like): Data comoving distances.
270
+ Nrandom (int): Number of randoms per object.
271
+ coord_randoms (tuple, optional): `(ra, dec, rcom)` for `file` method.
272
+ max_coordinates (float, optional): Coordinate cutoff for `file` method.
273
+
274
+ Returns:
275
+ tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]: Random x, y, z positions.
276
+ """
268
277
  N = xobj.size
269
278
 
270
279
  # Uniform in X,Y,Z
@@ -360,29 +369,25 @@ def grid_data_density(
360
369
  random_method="cartesian",
361
370
  coord_randoms=None,
362
371
  ):
363
- """
364
- The grid_data_density function takes in the data and grids it using a given grid size.
365
- It also computes the density of each voxel, as well as its error.
366
-
372
+ """Grid objects onto a mesh and compute density contrast and errors.
367
373
 
368
374
  Args:
369
- grid: Store the grid properties
370
- grid_size: Define the size of each voxel in mpc/h
371
- ra: Define the right ascension of the object
372
- dec: Compute the cartesian coordinates of the objects
373
- rcom: Compute the comoving distance of each object
374
- kind: Select the method used to compute voxcell values
375
- n_cut: Cut the grid in cells with a minimum number of objects
376
- weight_min: Cut the grid
377
- verbose: Print the number of cells in the grid
378
- compute_density: Compute the density field
379
- Nrandom: Create random points in the grid_data_density function
380
- random_method: Choose the method to create random points
381
- : Define the grid size
375
+ grid (dict): Grid coordinates dictionary from constructors.
376
+ grid_size (float): Cell size.
377
+ ra (array-like): Object right ascensions.
378
+ dec (array-like): Object declinations.
379
+ rcom (array-like): Object comoving distances.
380
+ kind (str): Resampler kind (`ngp`, `cic`, `tsc`, `pcs`, `ngp_errw`).
381
+ n_cut (int, optional): Minimum objects per cell.
382
+ weight_min (float, optional): Minimum weight per cell.
383
+ verbose (bool): Print number of cells.
384
+ compute_density (bool): Whether to compute density contrast.
385
+ Nrandom (int): Randoms per object if computing density.
386
+ random_method (str): Random generation method.
387
+ coord_randoms (tuple, optional): Randoms coordinates for `file` method.
382
388
 
383
389
  Returns:
384
- A dictionary with the following keys:
385
-
390
+ dict: Updated grid with weights, counts, density, and errors.
386
391
  """
387
392
  # Check valid input grid kind
388
393
  kind = kind.lower()
@@ -392,7 +397,7 @@ def grid_data_density(
392
397
  )
393
398
 
394
399
  xobj, yobj, zobj = utils.radec2cart(rcom, ra, dec)
395
- xgrid, ygrid, zgrid = utils.radec2cart(grid["rcom"], grid["ra"], grid["dec"])
400
+ xgrid, ygrid, zgrid = utils.radec2cart(grid["rcom_zobs"], grid["ra"], grid["dec"])
396
401
 
397
402
  # Compute weight
398
403
  weight_fun = globals()[kind + "_weight"]
@@ -444,7 +449,7 @@ def grid_data_density(
444
449
  / (sum_weights_random / np.sum(sum_weights_random))
445
450
  ) - 1
446
451
 
447
- grid["density_err"] = np.sqrt(
452
+ grid["density_error"] = np.sqrt(
448
453
  1 / (n_in_cell_random * (np.sum(n_in_cell) / np.sum(n_in_cell_random)))
449
454
  )
450
455
 
@@ -472,23 +477,22 @@ def cut_grid(
472
477
  zmax=None,
473
478
  remove_origin=False,
474
479
  ):
475
- """
476
- The cut_grid function is used to remove grid cells from the catalog.
480
+ """Apply selection cuts to a grid in-place.
477
481
 
478
482
  Args:
479
- grid: Pass the grid data to the function
480
- remove_nan_density: Remove any cells that have a density of nan
481
- n_cut: Remove grid cells with less than n_cut stars
482
- weight_min: Remove cells with too few stars
483
- rcom_max: Cut the grid by a maximum comoving distance
484
- xmax: Remove the cells that are too far away from the center of mass
485
- ymax: Cut the grid in y direction
486
- zmax: Cut the grid in z direction
487
- remove_origin: Remove the origin of the grid
483
+ grid (dict): Grid dictionary to modify.
484
+ remove_nan_density (bool): Drop NaN density and errors.
485
+ remove_empty_cells (bool): Drop cells with zero counts.
486
+ n_cut (int, optional): Minimum objects per cell.
487
+ weight_min (float, optional): Minimum weight per cell.
488
+ rcom_max (float, optional): Radial cutoff.
489
+ xmax (float, optional): X cutoff.
490
+ ymax (float, optional): Y cutoff.
491
+ zmax (float, optional): Z cutoff.
492
+ remove_origin (bool): Remove the origin cell.
488
493
 
489
494
  Returns:
490
- A dictionary with the same keys as grid, but where
491
-
495
+ None: Modifies `grid` in-place.
492
496
  """
493
497
  mask = np.full(grid["ra"].shape, True)
494
498
  if n_cut is not None:
@@ -496,7 +500,7 @@ def cut_grid(
496
500
  if weight_min is not None:
497
501
  mask &= grid["sum_weights"] > weight_min
498
502
  if rcom_max is not None:
499
- mask &= grid["rcom"] < rcom_max
503
+ mask &= grid["rcom_zobs"] < rcom_max
500
504
  if xmax is not None:
501
505
  mask &= np.abs(grid["x"]) < xmax
502
506
  if ymax is not None:
@@ -506,8 +510,8 @@ def cut_grid(
506
510
  if remove_nan_density:
507
511
  if "density" in grid:
508
512
  mask &= ~(np.isnan(grid["density"]))
509
- if "density_err" in grid:
510
- mask &= ~(np.isnan(grid["density_err"]))
513
+ if "density_error" in grid:
514
+ mask &= ~(np.isnan(grid["density_error"]))
511
515
  if remove_empty_cells:
512
516
  if "N_in_cell" in grid:
513
517
  mask &= ~(grid["N_in_cell"].astype(int) == 0)
@@ -533,29 +537,26 @@ def grid_data_density_pypower(
533
537
  min_count_random=0,
534
538
  overhead=20,
535
539
  ):
536
- """
537
- The grid_data_density_pypower function takes in the ra, dec, and rcom values of a galaxy catalog
538
- and returns a grid of density contrast values. The function uses pypower to create the grid.
539
- The function also has options for creating random points using different methods: choice, healpix, or cartesian.
540
-
540
+ """Grid data with pypower and compute density contrast on a mesh.
541
541
 
542
542
  Args:
543
- raobj: Pass the ra values of the data
544
- decobj: Calculate the z coordinate of the object in cartesian coordinates
545
- rcomobj: Calculate the comoving distance of each galaxy
546
- rcom_max: Cut the grid in a sphere of radius rcom_max
547
- grid_size: Determine the size of each cell in the grid
548
- grid_type: Determine whether to use a rectangular or spherical grid
549
- kind: Set the resampler in the catalogmesh function
550
- Nrandom: Determine the number of random points to be generated
551
- random_method: Choose the method used to generate random points
552
- interlacing: Reduce the variance of the density field
553
- compensate: Correct for the fact that we are using a finite number of random points
554
- : Remove the nan values from the grid
543
+ raobj (array-like): Right ascensions.
544
+ decobj (array-like): Declinations.
545
+ rcomobj (array-like): Comoving distances.
546
+ rcom_max (float): Outer cutoff for grid.
547
+ grid_size (float): Cell size.
548
+ grid_type (str): `rect` or `sphere` cut behavior.
549
+ kind (str): Resampler passed to CatalogMesh.
550
+ Nrandom (int): Randoms per data object.
551
+ random_method (str): Random generation method.
552
+ interlacing (int): Interlacing factor.
553
+ compensate (bool): Apply resampler compensation.
554
+ coord_randoms (tuple, optional): Randoms coordinates for `file` method.
555
+ min_count_random (int): Minimum random count for valid error.
556
+ overhead (float): Extra margin around cutoff.
555
557
 
556
558
  Returns:
557
- A dictionary with the grid coordinates and density contrast values
558
-
559
+ dict: Grid with positions, density contrast, errors, and counts.
559
560
  """
560
561
  xobj, yobj, zobj = utils.radec2cart(rcomobj, raobj, decobj)
561
562
  mask = np.abs(xobj) < rcom_max + overhead
@@ -647,9 +648,9 @@ def grid_data_density_pypower(
647
648
  "z": zgrid,
648
649
  "ra": ragrid,
649
650
  "dec": decgrid,
650
- "rcom": rcomgrid,
651
+ "rcom_zobs": rcomgrid,
651
652
  "density": density_contrast,
652
- "density_err": density_contrast_err,
653
+ "density_error": density_contrast_err,
653
654
  "count_random": count_randoms,
654
655
  }
655
656
 
@@ -688,30 +689,24 @@ def grid_data_velocity_pypower(
688
689
  compensate=False,
689
690
  overhead=20,
690
691
  ):
691
- """
692
- The grid_data_velocity_pypower function takes in the ra, dec, rcom, variance, and velocity values of a velocity catalog
693
- and returns a grid of variance and velocities. The function uses pypower to create the grid.
694
-
692
+ """Grid velocity catalog with pypower and compute weighted means and variance.
695
693
 
696
694
  Args:
697
- raobj: Pass the ra values of the data
698
- decobj: Calculate the z coordinate of the object in cartesian coordinates
699
- rcomobj: Calculate the comoving distance of each galaxy
700
- rcom_max: Cut the grid in a sphere of radius rcom_max
701
- variance: variance of the data points
702
- velocity: veloctity of the data
703
- grid_size: Determine the size of each cell in the grid
704
- grid_type: Determine whether to use a rectangular or spherical grid
705
- kind: Set the resampler in the catalogmesh function
706
- Nrandom: Determine the number of random points to be generated
707
- random_method: Choose the method used to generate random points
708
- interlacing: Reduce the variance of the density field
709
- compensate: Correct for the fact that we are using a finite number of random points
710
- : Remove the nan values from the grid
695
+ raobj (array-like): Right ascensions.
696
+ decobj (array-like): Declinations.
697
+ rcomobj (array-like): Comoving distances.
698
+ rcom_max (float): Outer cutoff.
699
+ variance (array-like): Per-object variances.
700
+ velocity (array-like|None): Per-object velocities (optional for variance-only).
701
+ grid_size (float): Cell size.
702
+ grid_type (str): `rect` or `sphere` cut behavior.
703
+ kind (str): Resampler passed to CatalogMesh.
704
+ interlacing (int): Interlacing factor.
705
+ compensate (bool): Apply resampler compensation.
706
+ overhead (float): Extra margin around cutoff.
711
707
 
712
708
  Returns:
713
- A dictionary with the grid coordinates and density contrast values
714
-
709
+ dict: Grid with positions, velocity (optional), variance, and counts.
715
710
  """
716
711
  xobj, yobj, zobj = utils.radec2cart(rcomobj, raobj, decobj)
717
712
  mask = np.abs(xobj) < rcom_max + overhead
@@ -743,7 +738,7 @@ def grid_data_velocity_pypower(
743
738
  resampler=kind,
744
739
  position_type="pos",
745
740
  )
746
- if type(velocity) != type(None):
741
+ if velocity is not None:
747
742
  weights_weighted_mean = velocity / variance
748
743
  catalog_mesh_weighted_vel = CatalogMesh(
749
744
  data_positions=data_positions,
@@ -771,7 +766,7 @@ def grid_data_velocity_pypower(
771
766
  variance_grid = np.ravel(mesh_var.value) / (
772
767
  N_in_cell**2
773
768
  ) # *N_in_cell/np.abs(N_in_cell)
774
- if type(velocity) != type(None):
769
+ if velocity is not None:
775
770
  mesh_weighted_vel = catalog_mesh_weighted_vel.to_mesh(
776
771
  field="data", compensate=compensate
777
772
  )
@@ -792,14 +787,14 @@ def grid_data_velocity_pypower(
792
787
  ygrid = np.ravel(coord_mesh[1, :, :, :]) + grid_size / 2
793
788
  zgrid = np.ravel(coord_mesh[2, :, :, :]) + grid_size / 2
794
789
  rcomgrid, ragrid, decgrid = utils.cart2radec(xgrid, ygrid, zgrid)
795
- if type(velocity) != type(None):
790
+ if velocity is not None:
796
791
  grid = {
797
792
  "x": xgrid,
798
793
  "y": ygrid,
799
794
  "z": zgrid,
800
795
  "ra": ragrid,
801
796
  "dec": decgrid,
802
- "rcom": rcomgrid,
797
+ "rcom_zobs": rcomgrid,
803
798
  "velocity": velocity_grid,
804
799
  "velocity_variance": variance_grid,
805
800
  "N_in_cell": N_in_cell,
@@ -811,7 +806,7 @@ def grid_data_velocity_pypower(
811
806
  "z": zgrid,
812
807
  "ra": ragrid,
813
808
  "dec": decgrid,
814
- "rcom": rcomgrid,
809
+ "rcom_zobs": rcomgrid,
815
810
  "velocity_variance": variance_grid,
816
811
  "N_in_cell": N_in_cell,
817
812
  }
@@ -0,0 +1,102 @@
1
+ import json
2
+ import os
3
+ from pathlib import Path
4
+
5
+ import numpy as np
6
+ import pandas as pd
7
+
8
+
9
+ def get_data_path():
10
+ from flip import __flip_dir_path__
11
+
12
+ flip_base = Path(__flip_dir_path__)
13
+ data_path = flip_base / "data"
14
+ return data_path
15
+
16
+
17
+ def load_power_spectra():
18
+ data_path = get_data_path()
19
+ kmm, pmm = np.loadtxt(os.path.join(data_path, "power_spectrum_mm.txt"))
20
+ kmt, pmt = np.loadtxt(os.path.join(data_path, "power_spectrum_mt.txt"))
21
+ ktt, ptt = np.loadtxt(os.path.join(data_path, "power_spectrum_tt.txt"))
22
+ return (kmm, pmm), (kmt, pmt), (ktt, ptt)
23
+
24
+
25
+ def load_grid_windows():
26
+ data_path = get_data_path()
27
+ data_window_density = pd.read_parquet(
28
+ os.path.join(data_path, "data_window_density.parquet")
29
+ )
30
+ return data_window_density
31
+
32
+
33
+ def load_power_spectrum_dict(
34
+ sigmau_fiducial=15.0,
35
+ ):
36
+ from flip import utils
37
+
38
+ (kmm, pmm), (kmt, pmt), (ktt, ptt) = load_power_spectra()
39
+
40
+ window_density = load_grid_windows()
41
+
42
+ power_spectrum_dict = {
43
+ "gg": [
44
+ [kmm, pmm * np.array(window_density["window_mm"]) ** 2],
45
+ [kmt, pmt * np.array(window_density["window_mt"])],
46
+ [ktt, ptt],
47
+ ],
48
+ "gv": [
49
+ [
50
+ kmt,
51
+ pmt
52
+ * np.array(window_density["window_mt"])
53
+ * utils.Du(kmt, sigmau_fiducial),
54
+ ],
55
+ [ktt, ptt * utils.Du(kmt, sigmau_fiducial)],
56
+ ],
57
+ "vv": [[ktt, ptt * utils.Du(ktt, sigmau_fiducial) ** 2]],
58
+ }
59
+
60
+ return power_spectrum_dict
61
+
62
+
63
+ def load_density_data(subsample=None):
64
+ data_path = get_data_path()
65
+ density = pd.read_parquet(os.path.join(data_path, "data_density.parquet"))
66
+ if subsample is not None:
67
+ density = density.iloc[:subsample]
68
+ coordinates_density = np.array(
69
+ [density["ra"], density["dec"], density["rcom_zobs"]]
70
+ )
71
+ density = density.to_dict(orient="list")
72
+
73
+ return coordinates_density, density
74
+
75
+
76
+ def load_velocity_data(subsample=None):
77
+ data_path = get_data_path()
78
+ velocity = pd.read_parquet(os.path.join(data_path, "data_velocity.parquet"))
79
+ if subsample is not None:
80
+ velocity = velocity.iloc[:subsample]
81
+ coordinates_velocity = np.array(
82
+ [velocity["ra"], velocity["dec"], velocity["rcom_zobs"]]
83
+ )
84
+ velocity = velocity.to_dict(orient="list")
85
+
86
+ return coordinates_velocity, velocity
87
+
88
+
89
+ def load_e2e_test_reference_values():
90
+ data_path = get_data_path()
91
+ with open(os.path.join(data_path, "test_e2e_reference_values.json"), "r") as f:
92
+ reference_values = json.load(f)
93
+ return reference_values
94
+
95
+
96
+ def load_covariance_test_reference_values():
97
+ data_path = get_data_path()
98
+ with open(
99
+ os.path.join(data_path, "test_covariance_reference_values.json"), "r"
100
+ ) as f:
101
+ reference_values = json.load(f)
102
+ return reference_values