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
|
@@ -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
|
-
|
|
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:
|
|
22
|
-
k:
|
|
23
|
-
order:
|
|
24
|
-
n:
|
|
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
|
-
|
|
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:
|
|
58
|
-
kh:
|
|
59
|
-
kind:
|
|
60
|
-
n:
|
|
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
|
-
|
|
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:
|
|
88
|
-
rcom_max:
|
|
85
|
+
grid_size (float): Cell size.
|
|
86
|
+
rcom_max (float): Maximum comoving radius cutoff.
|
|
89
87
|
|
|
90
88
|
Returns:
|
|
91
|
-
|
|
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
|
-
"
|
|
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:
|
|
131
|
-
rcom_max:
|
|
126
|
+
grid_size (float): Cell size.
|
|
127
|
+
rcom_max (float): Half-side length of the cube.
|
|
132
128
|
|
|
133
129
|
Returns:
|
|
134
|
-
|
|
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
|
-
"
|
|
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:
|
|
220
|
-
xobj:
|
|
221
|
-
yobj:
|
|
222
|
-
zobj:
|
|
223
|
-
xgrid:
|
|
224
|
-
ygrid:
|
|
225
|
-
zgrid:
|
|
226
|
-
weight_fun:
|
|
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
|
-
|
|
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:
|
|
370
|
-
grid_size:
|
|
371
|
-
ra:
|
|
372
|
-
dec:
|
|
373
|
-
rcom:
|
|
374
|
-
kind:
|
|
375
|
-
n_cut
|
|
376
|
-
weight_min:
|
|
377
|
-
verbose: Print
|
|
378
|
-
compute_density:
|
|
379
|
-
Nrandom:
|
|
380
|
-
random_method:
|
|
381
|
-
:
|
|
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
|
-
|
|
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["
|
|
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["
|
|
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:
|
|
480
|
-
remove_nan_density:
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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
|
-
|
|
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["
|
|
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 "
|
|
510
|
-
mask &= ~(np.isnan(grid["
|
|
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:
|
|
544
|
-
decobj:
|
|
545
|
-
rcomobj:
|
|
546
|
-
rcom_max:
|
|
547
|
-
grid_size:
|
|
548
|
-
grid_type:
|
|
549
|
-
kind:
|
|
550
|
-
Nrandom:
|
|
551
|
-
random_method:
|
|
552
|
-
interlacing:
|
|
553
|
-
compensate:
|
|
554
|
-
|
|
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
|
-
|
|
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
|
-
"
|
|
651
|
+
"rcom_zobs": rcomgrid,
|
|
651
652
|
"density": density_contrast,
|
|
652
|
-
"
|
|
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:
|
|
698
|
-
decobj:
|
|
699
|
-
rcomobj:
|
|
700
|
-
rcom_max:
|
|
701
|
-
variance:
|
|
702
|
-
velocity:
|
|
703
|
-
grid_size:
|
|
704
|
-
grid_type:
|
|
705
|
-
kind:
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|