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
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
{
|
|
2
|
+
"carreres23:velocity": {
|
|
3
|
+
"shape": [
|
|
4
|
+
50,
|
|
5
|
+
50
|
|
6
|
+
],
|
|
7
|
+
"trace": 3611379.1088774186,
|
|
8
|
+
"diag_mean": 72227.58217754838,
|
|
9
|
+
"entry_0_0": 72227.58217754838,
|
|
10
|
+
"entry_0_-1": 61263.88827893213,
|
|
11
|
+
"entry_mid_mid": 72227.58217754838
|
|
12
|
+
},
|
|
13
|
+
"adamsblake17plane:density": {
|
|
14
|
+
"shape": [
|
|
15
|
+
50,
|
|
16
|
+
50
|
|
17
|
+
],
|
|
18
|
+
"trace": 12.912536222207837,
|
|
19
|
+
"diag_mean": 0.25825072444415675,
|
|
20
|
+
"entry_0_0": 0.25894497176118253,
|
|
21
|
+
"entry_0_-1": -0.00012572887297247905,
|
|
22
|
+
"entry_mid_mid": 0.2579469829436334
|
|
23
|
+
},
|
|
24
|
+
"adamsblake17plane:velocity": {
|
|
25
|
+
"shape": [
|
|
26
|
+
50,
|
|
27
|
+
50
|
|
28
|
+
],
|
|
29
|
+
"trace": 3611379.108877419,
|
|
30
|
+
"diag_mean": 72227.58217754838,
|
|
31
|
+
"entry_0_0": 72227.5821775484,
|
|
32
|
+
"entry_0_-1": 62509.77032963803,
|
|
33
|
+
"entry_mid_mid": 72227.5821775484
|
|
34
|
+
},
|
|
35
|
+
"adamsblake17plane:full": {
|
|
36
|
+
"shape": [
|
|
37
|
+
100,
|
|
38
|
+
100
|
|
39
|
+
],
|
|
40
|
+
"trace": 3611392.021413641,
|
|
41
|
+
"diag_mean": 36113.92021413641,
|
|
42
|
+
"entry_0_0": 0.25894497176118253,
|
|
43
|
+
"entry_0_-1": 0.11198990205834854,
|
|
44
|
+
"entry_mid_mid": 72227.5821775484
|
|
45
|
+
},
|
|
46
|
+
"adamsblake20:density": {
|
|
47
|
+
"shape": [
|
|
48
|
+
50,
|
|
49
|
+
50
|
|
50
|
+
],
|
|
51
|
+
"trace": 10.839977330113454,
|
|
52
|
+
"diag_mean": 0.21679954660226908,
|
|
53
|
+
"entry_0_0": 0.2174937939192948,
|
|
54
|
+
"entry_0_-1": 8.86951966632375e-05,
|
|
55
|
+
"entry_mid_mid": 0.21649580510174568
|
|
56
|
+
},
|
|
57
|
+
"adamsblake20:velocity": {
|
|
58
|
+
"shape": [
|
|
59
|
+
50,
|
|
60
|
+
50
|
|
61
|
+
],
|
|
62
|
+
"trace": 3611379.108877419,
|
|
63
|
+
"diag_mean": 72227.58217754838,
|
|
64
|
+
"entry_0_0": 72227.5821775484,
|
|
65
|
+
"entry_0_-1": 62509.77032963803,
|
|
66
|
+
"entry_mid_mid": 72227.5821775484
|
|
67
|
+
},
|
|
68
|
+
"adamsblake20:full": {
|
|
69
|
+
"shape": [
|
|
70
|
+
100,
|
|
71
|
+
100
|
|
72
|
+
],
|
|
73
|
+
"trace": 3611389.9488547486,
|
|
74
|
+
"diag_mean": 36113.89948854749,
|
|
75
|
+
"entry_0_0": 0.2174937939192948,
|
|
76
|
+
"entry_0_-1": 0.2153532060784413,
|
|
77
|
+
"entry_mid_mid": 72227.5821775484
|
|
78
|
+
},
|
|
79
|
+
"ravouxcarreres:velocity": {
|
|
80
|
+
"shape": [
|
|
81
|
+
50,
|
|
82
|
+
50
|
|
83
|
+
],
|
|
84
|
+
"trace": 3611379.1088774186,
|
|
85
|
+
"diag_mean": 72227.58217754838,
|
|
86
|
+
"entry_0_0": 72227.58217754838,
|
|
87
|
+
"entry_0_-1": 61263.88827893213,
|
|
88
|
+
"entry_mid_mid": 72227.58217754838
|
|
89
|
+
},
|
|
90
|
+
"ravouxcarreres:density": {
|
|
91
|
+
"shape": [
|
|
92
|
+
50,
|
|
93
|
+
50
|
|
94
|
+
],
|
|
95
|
+
"trace": 10.818743417176453,
|
|
96
|
+
"diag_mean": 0.21637486834352906,
|
|
97
|
+
"entry_0_0": 0.21706911566055476,
|
|
98
|
+
"entry_0_-1": -0.00019596175905701665,
|
|
99
|
+
"entry_mid_mid": 0.21607112684300564
|
|
100
|
+
},
|
|
101
|
+
"ravouxcarreres:full": {
|
|
102
|
+
"shape": [
|
|
103
|
+
100,
|
|
104
|
+
100
|
|
105
|
+
],
|
|
106
|
+
"trace": 3611389.9276208356,
|
|
107
|
+
"diag_mean": 36113.89927620836,
|
|
108
|
+
"entry_0_0": 0.21706911566055476,
|
|
109
|
+
"entry_0_-1": -0.8829953575001571,
|
|
110
|
+
"entry_mid_mid": 72227.58217754838
|
|
111
|
+
},
|
|
112
|
+
"lai22:density": {
|
|
113
|
+
"shape": [
|
|
114
|
+
50,
|
|
115
|
+
50
|
|
116
|
+
],
|
|
117
|
+
"trace": 24.619958402798297,
|
|
118
|
+
"diag_mean": 0.49239916805596595,
|
|
119
|
+
"entry_0_0": 0.49309341537299173,
|
|
120
|
+
"entry_0_-1": -0.0001843060148694274,
|
|
121
|
+
"entry_mid_mid": 0.4920954265554426
|
|
122
|
+
},
|
|
123
|
+
"lai22:velocity": {
|
|
124
|
+
"shape": [
|
|
125
|
+
50,
|
|
126
|
+
50
|
|
127
|
+
],
|
|
128
|
+
"trace": 3611379.1088774186,
|
|
129
|
+
"diag_mean": 72227.58217754838,
|
|
130
|
+
"entry_0_0": 72227.58217754838,
|
|
131
|
+
"entry_0_-1": 61263.88827893213,
|
|
132
|
+
"entry_mid_mid": 72227.58217754838
|
|
133
|
+
},
|
|
134
|
+
"lai22:full": {
|
|
135
|
+
"shape": [
|
|
136
|
+
100,
|
|
137
|
+
100
|
|
138
|
+
],
|
|
139
|
+
"trace": 3611403.728835821,
|
|
140
|
+
"diag_mean": 36114.03728835821,
|
|
141
|
+
"entry_0_0": 0.49309341537299173,
|
|
142
|
+
"entry_0_-1": -0.861244816639371,
|
|
143
|
+
"entry_mid_mid": 72227.58217754838
|
|
144
|
+
}
|
|
145
|
+
}
|
flip/data_vector/basic.py
CHANGED
|
@@ -7,13 +7,13 @@ import numpy as np
|
|
|
7
7
|
from flip.covariance import CovMatrix
|
|
8
8
|
from flip.utils import create_log
|
|
9
9
|
|
|
10
|
-
from ..
|
|
10
|
+
from .._config import __use_jax__
|
|
11
11
|
from . import vector_utils
|
|
12
12
|
|
|
13
13
|
if __use_jax__:
|
|
14
14
|
try:
|
|
15
15
|
import jax.numpy as jnp
|
|
16
|
-
from jax import jit
|
|
16
|
+
from jax import jit, random
|
|
17
17
|
from jax.experimental.sparse import BCOO
|
|
18
18
|
|
|
19
19
|
jax_installed = True
|
|
@@ -25,6 +25,7 @@ if __use_jax__:
|
|
|
25
25
|
else:
|
|
26
26
|
|
|
27
27
|
import numpy as jnp
|
|
28
|
+
from numpy import random
|
|
28
29
|
|
|
29
30
|
jax_installed = False
|
|
30
31
|
|
|
@@ -32,43 +33,100 @@ log = create_log()
|
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
class DataVector(abc.ABC):
|
|
36
|
+
"""Abstract base for data vectors used in fits.
|
|
37
|
+
|
|
38
|
+
Provides common storage, key validation, optional JAX acceleration,
|
|
39
|
+
covariance-aware masking, and covariance construction helpers.
|
|
40
|
+
|
|
41
|
+
Attributes:
|
|
42
|
+
_free_par (list[str]): Model parameters this vector depends on.
|
|
43
|
+
_kind (str): One of "velocity", "density" or "cross".
|
|
44
|
+
"""
|
|
45
|
+
|
|
35
46
|
_free_par = []
|
|
36
47
|
_kind = "" # 'velocity', 'density' or 'cross'
|
|
37
48
|
|
|
38
49
|
@property
|
|
39
50
|
def conditional_free_par(self):
|
|
51
|
+
"""Conditional extra parameters required by this vector.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
list[str]: Parameter names required depending on data content.
|
|
55
|
+
"""
|
|
40
56
|
return []
|
|
41
57
|
|
|
42
58
|
@property
|
|
43
59
|
def free_par(self):
|
|
60
|
+
"""All free parameters for this vector.
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
list[str]: Base plus conditional parameters.
|
|
64
|
+
"""
|
|
44
65
|
return self._free_par + self.conditional_free_par
|
|
45
66
|
|
|
46
67
|
@property
|
|
47
68
|
def kind(self):
|
|
69
|
+
"""Return the data vector type.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
str: "velocity", "density" or "cross".
|
|
73
|
+
"""
|
|
48
74
|
return self._kind
|
|
49
75
|
|
|
50
76
|
@property
|
|
51
77
|
def conditional_needed_keys(self):
|
|
78
|
+
"""Keys conditionally required in input `data`.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
list[str]: Extra keys required depending on configuration.
|
|
82
|
+
"""
|
|
52
83
|
return []
|
|
53
84
|
|
|
54
85
|
@property
|
|
55
86
|
def needed_keys(self):
|
|
87
|
+
"""All required keys for this data vector.
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
list[str]: Static plus conditional keys.
|
|
91
|
+
"""
|
|
56
92
|
return self._needed_keys + self.conditional_needed_keys
|
|
57
93
|
|
|
58
94
|
@property
|
|
59
95
|
def data(self):
|
|
96
|
+
"""Access the underlying data dictionary.
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
dict: Data fields as arrays.
|
|
100
|
+
"""
|
|
60
101
|
return self._data
|
|
61
102
|
|
|
62
103
|
@abc.abstractmethod
|
|
63
104
|
def give_data_and_variance(self, **kwargs):
|
|
105
|
+
"""Return data vector and its variance/covariance.
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
tuple: (data_array, variance_or_cov).
|
|
109
|
+
"""
|
|
64
110
|
pass
|
|
65
111
|
|
|
66
112
|
def _check_keys(self, data):
|
|
113
|
+
"""Validate that `data` contains all required keys.
|
|
114
|
+
|
|
115
|
+
Raises:
|
|
116
|
+
ValueError: When a required key is missing.
|
|
117
|
+
"""
|
|
67
118
|
for k in self.needed_keys:
|
|
68
119
|
if k not in data:
|
|
69
120
|
raise ValueError(f"{k} field is needed in data")
|
|
70
121
|
|
|
71
122
|
def __init__(self, data, covariance_observation=None, **kwargs):
|
|
123
|
+
"""Initialize data vector with data and optional observation covariance.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
data (dict): Mapping of required fields to arrays.
|
|
127
|
+
covariance_observation (ndarray|None): Observation covariance matrix or None.
|
|
128
|
+
**kwargs: Extra configuration for subclasses.
|
|
129
|
+
"""
|
|
72
130
|
self._covariance_observation = covariance_observation
|
|
73
131
|
self._check_keys(data)
|
|
74
132
|
self._data = copy.copy(data)
|
|
@@ -80,11 +138,18 @@ class DataVector(abc.ABC):
|
|
|
80
138
|
if jax_installed:
|
|
81
139
|
self.give_data_and_variance_jit = jit(self.give_data_and_variance)
|
|
82
140
|
|
|
83
|
-
# TODO: deprecate this call
|
|
84
|
-
def __call__(self, *args):
|
|
85
|
-
return self.give_data_and_variance(*args)
|
|
86
|
-
|
|
87
141
|
def get_masked_data_and_cov(self, bool_mask):
|
|
142
|
+
"""Return masked data and corresponding masked observation covariance.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
bool_mask (array-like): Boolean mask aligned with first data key length.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
tuple: (new_data_dict, new_cov) with covariance masked or None.
|
|
149
|
+
|
|
150
|
+
Raises:
|
|
151
|
+
ValueError: If mask length mismatches data length.
|
|
152
|
+
"""
|
|
88
153
|
if len(bool_mask) != len(self.data[self.needed_keys[0]]):
|
|
89
154
|
raise ValueError("Boolean mask does not align with data")
|
|
90
155
|
new_data = {k: v[bool_mask] for k, v in self._data.items()}
|
|
@@ -95,9 +160,19 @@ class DataVector(abc.ABC):
|
|
|
95
160
|
return new_data, new_cov
|
|
96
161
|
|
|
97
162
|
def compute_covariance(self, model, power_spectrum_dict, **kwargs):
|
|
163
|
+
"""Build a `CovMatrix` for this vector and model.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
model (str): Covariance model module under `flip.covariance`.
|
|
167
|
+
power_spectrum_dict (dict): Power spectra inputs for model.
|
|
168
|
+
**kwargs: Model-specific options.
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
CovMatrix: Initialized covariance matrix object.
|
|
172
|
+
"""
|
|
98
173
|
|
|
99
174
|
coordinate_keys = importlib.import_module(
|
|
100
|
-
f"flip.covariance.{model}"
|
|
175
|
+
f"flip.covariance.analytical.{model}"
|
|
101
176
|
)._coordinate_keys
|
|
102
177
|
|
|
103
178
|
coords = np.vstack([self.data[k] for k in coordinate_keys])
|
|
@@ -116,6 +191,11 @@ class Dens(DataVector):
|
|
|
116
191
|
_needed_keys = ["density", "density_error"]
|
|
117
192
|
|
|
118
193
|
def give_data_and_variance(self, *args):
|
|
194
|
+
"""Return density data and diagonal variance from `density_error`.
|
|
195
|
+
|
|
196
|
+
Returns:
|
|
197
|
+
tuple: (density, density_error^2).
|
|
198
|
+
"""
|
|
119
199
|
return self._data["density"], self._data["density_error"] ** 2
|
|
120
200
|
|
|
121
201
|
|
|
@@ -230,7 +310,7 @@ class DensVel(DataVector):
|
|
|
230
310
|
)
|
|
231
311
|
|
|
232
312
|
|
|
233
|
-
class VelFromHDres(
|
|
313
|
+
class VelFromHDres(DataVector):
|
|
234
314
|
_needed_keys = ["dmu", "zobs"]
|
|
235
315
|
_free_par = ["M_0"]
|
|
236
316
|
|
|
@@ -248,54 +328,37 @@ class VelFromHDres(DirectVel):
|
|
|
248
328
|
)
|
|
249
329
|
)
|
|
250
330
|
velocity = (
|
|
251
|
-
self._data["
|
|
331
|
+
distance_modulus_difference_to_velocity * self._data["dmu"]
|
|
252
332
|
- distance_modulus_difference_to_velocity * parameter_values_dict["M_0"]
|
|
253
333
|
)
|
|
334
|
+
if self._covariance_observation is None and "dmu_error" in self._data:
|
|
335
|
+
velocity_error = (
|
|
336
|
+
distance_modulus_difference_to_velocity * self._data["dmu_error"]
|
|
337
|
+
)
|
|
338
|
+
return velocity, velocity_error**2
|
|
254
339
|
|
|
255
|
-
|
|
340
|
+
elif self._covariance_observation is not None:
|
|
256
341
|
J = jnp.diag(self._distance_modulus_difference_to_velocity)
|
|
257
342
|
velocity_variance = J @ self._covariance_observation @ J.T
|
|
258
343
|
return velocity, velocity_variance
|
|
259
|
-
|
|
344
|
+
else:
|
|
345
|
+
raise ValueError(
|
|
346
|
+
"Cannot compute velocity variance without dmu_error or covariance_observation"
|
|
347
|
+
)
|
|
260
348
|
|
|
261
349
|
def __init__(
|
|
262
350
|
self, data, covariance_observation=None, velocity_estimator="full", **kwargs
|
|
263
351
|
):
|
|
264
352
|
# Compute conversion using provided input data, not uninitialized self._data
|
|
265
|
-
|
|
266
|
-
vector_utils.redshift_dependence_velocity(
|
|
267
|
-
data, velocity_estimator, **kwargs
|
|
268
|
-
)
|
|
269
|
-
)
|
|
353
|
+
|
|
270
354
|
self.velocity_estimator = velocity_estimator
|
|
271
|
-
data = dict(data) # shallow copy to avoid side-effects upstream
|
|
272
|
-
data["velocity"] = distance_modulus_difference_to_velocity * data["dmu"]
|
|
273
355
|
|
|
274
|
-
if covariance_observation is None and "dmu_error" in data:
|
|
275
|
-
data["velocity_error"] = (
|
|
276
|
-
distance_modulus_difference_to_velocity * data["dmu_error"]
|
|
277
|
-
)
|
|
278
356
|
super().__init__(data, covariance_observation=covariance_observation)
|
|
279
357
|
|
|
280
358
|
|
|
281
|
-
class
|
|
359
|
+
class VelFromIntrinsicScatter(DataVector):
|
|
282
360
|
_kind = "velocity"
|
|
283
|
-
_needed_keys = ["zobs"
|
|
284
|
-
|
|
285
|
-
def give_data_and_variance(self, parameter_values_dict):
|
|
286
|
-
variance = self.data["velocity_variance"]
|
|
287
|
-
return self._distance_modulus_difference_to_velocity**2 * variance
|
|
288
|
-
|
|
289
|
-
def __init__(self, data, velocity_estimator="full", **kwargs):
|
|
290
|
-
super().__init__(data)
|
|
291
|
-
self._distance_modulus_difference_to_velocity = (
|
|
292
|
-
vector_utils.redshift_dependence_velocity(
|
|
293
|
-
self._data, velocity_estimator, **kwargs
|
|
294
|
-
)
|
|
295
|
-
)
|
|
296
|
-
class FisherVelFromHDres(DataVector):
|
|
297
|
-
_kind = "velocity"
|
|
298
|
-
_needed_keys = ["zobs", "ra", "dec", "rcom_zobs"]
|
|
361
|
+
_needed_keys = ["zobs"]
|
|
299
362
|
_free_par = ["sigma_M"]
|
|
300
363
|
|
|
301
364
|
def give_data_and_variance(self, parameter_values_dict):
|
|
@@ -304,71 +367,25 @@ class FisherVelFromHDres(DataVector):
|
|
|
304
367
|
self._data, self.velocity_estimator, **parameter_values_dict
|
|
305
368
|
)
|
|
306
369
|
)
|
|
370
|
+
if jax_installed:
|
|
371
|
+
key = random.PRNGKey(0)
|
|
372
|
+
distance_modulus = parameter_values_dict["sigma_M"] * random.normal(
|
|
373
|
+
key, (len(self._data["zobs"]),)
|
|
374
|
+
)
|
|
375
|
+
else:
|
|
376
|
+
distance_modulus = random.normal(
|
|
377
|
+
loc=0.0,
|
|
378
|
+
scale=parameter_values_dict["sigma_M"],
|
|
379
|
+
size=len(self._data["zobs"]),
|
|
380
|
+
)
|
|
307
381
|
|
|
308
382
|
variance = parameter_values_dict["sigma_M"] ** 2
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
383
|
+
|
|
384
|
+
return (
|
|
385
|
+
distance_modulus_difference_to_velocity * distance_modulus,
|
|
386
|
+
distance_modulus_difference_to_velocity**2 * variance,
|
|
387
|
+
)
|
|
312
388
|
|
|
313
389
|
def __init__(self, data, velocity_estimator="full"):
|
|
314
390
|
super().__init__(data)
|
|
315
391
|
self.velocity_estimator = velocity_estimator
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
class FisherDens(DataVector):
|
|
319
|
-
_kind = "density"
|
|
320
|
-
_needed_keys = ["ra", "dec", "rcom_zobs"]
|
|
321
|
-
_free_par = []
|
|
322
|
-
|
|
323
|
-
def give_data_and_variance(self, parameter_values_dict):
|
|
324
|
-
variance = 0
|
|
325
|
-
if "density_error" in self.data:
|
|
326
|
-
variance += self.data["density_error"] ** 2
|
|
327
|
-
return variance
|
|
328
|
-
|
|
329
|
-
def __init__(self, data, velocity_estimator="full", **kwargs):
|
|
330
|
-
super().__init__(data)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
class FisherDensVel(DataVector):
|
|
334
|
-
_kind = "cross"
|
|
335
|
-
|
|
336
|
-
def give_data_and_variance(self, *args):
|
|
337
|
-
density_variance = self.densities.give_data_and_variance(*args)
|
|
338
|
-
velocity_variance = self.velocities.give_data_and_variance(*args)
|
|
339
|
-
|
|
340
|
-
variance = np.hstack((density_variance, velocity_variance))
|
|
341
|
-
return variance
|
|
342
|
-
|
|
343
|
-
def __init__(self, fisher_density, fisher_velocity):
|
|
344
|
-
self.densities = fisher_density
|
|
345
|
-
self.velocities = fisher_velocity
|
|
346
|
-
|
|
347
|
-
if self.velocities._covariance_observation is not None:
|
|
348
|
-
raise NotImplementedError("Vel with cov + density not implemented yet")
|
|
349
|
-
|
|
350
|
-
def compute_covariance(self, model, power_spectrum_dict, **kwargs):
|
|
351
|
-
|
|
352
|
-
coords_dens = np.vstack(
|
|
353
|
-
(
|
|
354
|
-
self.densities.data["ra"],
|
|
355
|
-
self.densities.data["dec"],
|
|
356
|
-
self.densities.data["rcom_zobs"],
|
|
357
|
-
)
|
|
358
|
-
)
|
|
359
|
-
|
|
360
|
-
coords_vel = np.vstack(
|
|
361
|
-
(
|
|
362
|
-
self.velocities.data["ra"],
|
|
363
|
-
self.velocities.data["dec"],
|
|
364
|
-
self.velocities.data["rcom_zobs"],
|
|
365
|
-
)
|
|
366
|
-
)
|
|
367
|
-
return CovMatrix.init_from_flip(
|
|
368
|
-
model,
|
|
369
|
-
"full",
|
|
370
|
-
power_spectrum_dict,
|
|
371
|
-
coordinates_density=coords_dens,
|
|
372
|
-
coordinates_velocity=coords_vel,
|
|
373
|
-
**kwargs,
|
|
374
|
-
)
|
flip/data_vector/cosmo_utils.py
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
def compute_hubble_norm_zobs(z, cosmo):
|
|
2
|
+
"""Compute normalized Hubble parameter at redshift.
|
|
3
|
+
|
|
4
|
+
Args:
|
|
5
|
+
z (array-like): Redshift values.
|
|
6
|
+
cosmo: Astropy cosmology object with `efunc`.
|
|
7
|
+
|
|
8
|
+
Returns:
|
|
9
|
+
ndarray: `100 * E(z)`.
|
|
10
|
+
"""
|
|
2
11
|
return 100 * cosmo.efunc(z)
|
|
3
12
|
|
|
4
13
|
|
|
5
14
|
def compute_rcom_zobs(z, cosmo):
|
|
15
|
+
"""Compute comoving distance times little-h at redshift.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
z (array-like): Redshift values.
|
|
19
|
+
cosmo: Astropy cosmology object with `comoving_distance` and `h`.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
ndarray: `Dm(z) * h` in Mpc/h.
|
|
23
|
+
"""
|
|
6
24
|
return cosmo.comoving_distance(z).value * cosmo.h
|