astrogwb 0.8.0__tar.gz
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.
- astrogwb-0.8.0/LICENSE +21 -0
- astrogwb-0.8.0/PKG-INFO +236 -0
- astrogwb-0.8.0/README.md +195 -0
- astrogwb-0.8.0/pyproject.toml +97 -0
- astrogwb-0.8.0/pyproject.toml.orig +102 -0
- astrogwb-0.8.0/src/astrogwb/__init__.py +16 -0
- astrogwb-0.8.0/src/astrogwb/background/__init__.py +39 -0
- astrogwb-0.8.0/src/astrogwb/background/analytic.py +560 -0
- astrogwb-0.8.0/src/astrogwb/background/importance/__init__.py +15 -0
- astrogwb-0.8.0/src/astrogwb/background/importance/catalog.py +119 -0
- astrogwb-0.8.0/src/astrogwb/background/importance/diagnostics.py +45 -0
- astrogwb-0.8.0/src/astrogwb/background/importance/model.py +443 -0
- astrogwb-0.8.0/src/astrogwb/background/importance/spectrum.py +440 -0
- astrogwb-0.8.0/src/astrogwb/background/simulation/__init__.py +33 -0
- astrogwb-0.8.0/src/astrogwb/background/simulation/_chunks.py +52 -0
- astrogwb-0.8.0/src/astrogwb/background/simulation/_keys.py +21 -0
- astrogwb-0.8.0/src/astrogwb/background/simulation/config.py +130 -0
- astrogwb-0.8.0/src/astrogwb/background/simulation/draw.py +753 -0
- astrogwb-0.8.0/src/astrogwb/background/simulation/ensemble.py +91 -0
- astrogwb-0.8.0/src/astrogwb/background/simulation/pool.py +73 -0
- astrogwb-0.8.0/src/astrogwb/background/snr.py +210 -0
- astrogwb-0.8.0/src/astrogwb/background/spectral.py +128 -0
- astrogwb-0.8.0/src/astrogwb/cli/__init__.py +36 -0
- astrogwb-0.8.0/src/astrogwb/cli/_common.py +20 -0
- astrogwb-0.8.0/src/astrogwb/cli/simulate.py +154 -0
- astrogwb-0.8.0/src/astrogwb/config.py +62 -0
- astrogwb-0.8.0/src/astrogwb/constants.py +65 -0
- astrogwb-0.8.0/src/astrogwb/cosmology.py +282 -0
- astrogwb-0.8.0/src/astrogwb/detector/__init__.py +77 -0
- astrogwb-0.8.0/src/astrogwb/detector/config.py +260 -0
- astrogwb-0.8.0/src/astrogwb/detector/effective_psd.py +221 -0
- astrogwb-0.8.0/src/astrogwb/detector/geometry.py +185 -0
- astrogwb-0.8.0/src/astrogwb/detector/geometry.toml +123 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/AplusDesign_psd.txt +3000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/ET-000A-18_ETD_hlf_psd.txt +3000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/ET_COBA_10km_psd.txt +3000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/ET_COBA_15km_psd.txt +3000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/ET_COBA_20km_psd.txt +3000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/avirgo_O5high_NEW_psd.txt +3000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/avirgo_O5low_NEW_psd.txt +3000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/cosmic_explorer_20km_pm_strain_psd.txt +1000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/cosmic_explorer_20km_strain_psd.txt +1000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/cosmic_explorer_40km_lf_strain_psd.txt +1000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/cosmic_explorer_strain_psd.txt +1000 -0
- astrogwb-0.8.0/src/astrogwb/detector/noise_curves/kagra_128Mpc_psd.txt +1000 -0
- astrogwb-0.8.0/src/astrogwb/detector/overlap.py +553 -0
- astrogwb-0.8.0/src/astrogwb/detector/projection.py +133 -0
- astrogwb-0.8.0/src/astrogwb/detector/psd.py +46 -0
- astrogwb-0.8.0/src/astrogwb/detector/response.py +294 -0
- astrogwb-0.8.0/src/astrogwb/detector/sensitivity.py +119 -0
- astrogwb-0.8.0/src/astrogwb/detector/sensitivity.toml +52 -0
- astrogwb-0.8.0/src/astrogwb/distributions/__init__.py +21 -0
- astrogwb-0.8.0/src/astrogwb/distributions/config.py +86 -0
- astrogwb-0.8.0/src/astrogwb/distributions/interpolated.py +118 -0
- astrogwb-0.8.0/src/astrogwb/distributions/mass.py +202 -0
- astrogwb-0.8.0/src/astrogwb/distributions/orientation.py +91 -0
- astrogwb-0.8.0/src/astrogwb/distributions/redshift/__init__.py +5 -0
- astrogwb-0.8.0/src/astrogwb/distributions/redshift/base.py +190 -0
- astrogwb-0.8.0/src/astrogwb/frequency.py +238 -0
- astrogwb-0.8.0/src/astrogwb/inference/__init__.py +13 -0
- astrogwb-0.8.0/src/astrogwb/inference/gaussian.py +654 -0
- astrogwb-0.8.0/src/astrogwb/inference/grid.py +126 -0
- astrogwb-0.8.0/src/astrogwb/inference/model.py +94 -0
- astrogwb-0.8.0/src/astrogwb/populations/__init__.py +15 -0
- astrogwb-0.8.0/src/astrogwb/populations/_types.py +12 -0
- astrogwb-0.8.0/src/astrogwb/populations/coba.py +84 -0
- astrogwb-0.8.0/src/astrogwb/populations/mass/__init__.py +0 -0
- astrogwb-0.8.0/src/astrogwb/populations/mass/gaussian_mass_pair.py +32 -0
- astrogwb-0.8.0/src/astrogwb/populations/mass/uniform_mass_pair.py +33 -0
- astrogwb-0.8.0/src/astrogwb/rates.py +130 -0
- astrogwb-0.8.0/src/astrogwb/runtime.py +51 -0
- astrogwb-0.8.0/src/astrogwb/statistics/__init__.py +15 -0
- astrogwb-0.8.0/src/astrogwb/statistics/amplitude.py +103 -0
- astrogwb-0.8.0/src/astrogwb/statistics/cross_correlation.py +63 -0
- astrogwb-0.8.0/src/astrogwb/utils/__init__.py +132 -0
- astrogwb-0.8.0/src/astrogwb/utils/io.py +202 -0
- astrogwb-0.8.0/src/astrogwb/utils/numpyro.py +292 -0
- astrogwb-0.8.0/src/astrogwb/waveform/__init__.py +33 -0
- astrogwb-0.8.0/src/astrogwb/waveform/_ripple.py +427 -0
- astrogwb-0.8.0/src/astrogwb/waveform/analytical.py +335 -0
- astrogwb-0.8.0/src/astrogwb/waveform/base.py +162 -0
- astrogwb-0.8.0/src/astrogwb/waveform/factory.py +19 -0
- astrogwb-0.8.0/src/astrogwb/waveform/intensity.py +121 -0
- astrogwb-0.8.0/src/astrogwb/waveform/metadata.py +80 -0
- astrogwb-0.8.0/src/astrogwb/waveform/ripple.py +224 -0
astrogwb-0.8.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bernardo Veronese
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
astrogwb-0.8.0/PKG-INFO
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: astrogwb
|
|
3
|
+
Version: 0.8.0
|
|
4
|
+
Summary: Bayesian inference for compact-binary stochastic gravitational-wave backgrounds
|
|
5
|
+
Author: Bernardo Veronese
|
|
6
|
+
Author-email: Bernardo Veronese <bernardopveronese@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
15
|
+
Requires-Dist: gwmock-noise>=0.10.1
|
|
16
|
+
Requires-Dist: gwmock-signal[jax]>=0.15.0
|
|
17
|
+
Requires-Dist: ripplegw>=0.3.1
|
|
18
|
+
Requires-Dist: jax>=0.10.2 ; sys_platform == 'linux'
|
|
19
|
+
Requires-Dist: jax[cpu]>=0.11.0 ; sys_platform != 'linux'
|
|
20
|
+
Requires-Dist: numpy>=2.1
|
|
21
|
+
Requires-Dist: numpyro>=0.21.0
|
|
22
|
+
Requires-Dist: pydantic>=2.14
|
|
23
|
+
Requires-Dist: pyknf>=0.6,<0.8
|
|
24
|
+
Requires-Dist: astrogwb[io] ; extra == 'cli'
|
|
25
|
+
Requires-Dist: gwmock-pop>=0.11.4 ; extra == 'cli'
|
|
26
|
+
Requires-Dist: typer>=0.16 ; extra == 'cli'
|
|
27
|
+
Requires-Dist: jax[cuda12]>=0.11.0 ; extra == 'cuda'
|
|
28
|
+
Requires-Dist: h5py>=3.15 ; extra == 'io'
|
|
29
|
+
Requires-Dist: gwmock-pop>=0.11.4 ; extra == 'simulation'
|
|
30
|
+
Requires-Dist: jax[tpu]>=0.11.0 ; extra == 'tpu'
|
|
31
|
+
Requires-Python: >=3.12
|
|
32
|
+
Project-URL: Homepage, https://github.com/binado/astrogwb
|
|
33
|
+
Project-URL: Repository, https://github.com/binado/astrogwb
|
|
34
|
+
Project-URL: Issues, https://github.com/binado/astrogwb/issues
|
|
35
|
+
Provides-Extra: cli
|
|
36
|
+
Provides-Extra: cuda
|
|
37
|
+
Provides-Extra: io
|
|
38
|
+
Provides-Extra: simulation
|
|
39
|
+
Provides-Extra: tpu
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# astrogwb
|
|
43
|
+
|
|
44
|
+
`astrogwb` provides reusable scientific modules for modelling the stochastic
|
|
45
|
+
gravitational-wave background from compact-binary populations and performing
|
|
46
|
+
Bayesian inference with detector networks.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install astrogwb
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Optional accelerator builds are available as `astrogwb[cuda]` and
|
|
55
|
+
`astrogwb[tpu]`. Direct HDF5 catalog serialization is opt-in:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install astrogwb[io]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Library modules
|
|
62
|
+
|
|
63
|
+
- `astrogwb.constants` holds the SI physical constants and unit conversions
|
|
64
|
+
every other module shares. The tabulated values are the LALSuite literals,
|
|
65
|
+
so results are bit-comparable with LALSimulation and ripple.
|
|
66
|
+
- `astrogwb.detector` loads bundled detector geometry and sensitivity data and
|
|
67
|
+
evaluates overlap-reduction functions and effective PSDs.
|
|
68
|
+
- `astrogwb.background` provides spectral-density, Omega-GW conversion, and SNR
|
|
69
|
+
calculations. `astrogwb.background.analytic` evaluates the inspiral-only
|
|
70
|
+
background in closed form, truncated on the same dimensionless `alpha` as
|
|
71
|
+
`astrogwb.waveform`.
|
|
72
|
+
- `astrogwb.populations` and `astrogwb.background.importance` provide BNS reference
|
|
73
|
+
catalog generation, including scrambled Sobol draws.
|
|
74
|
+
- `astrogwb.background.importance.model.CatalogModel` predicts the spectral density and
|
|
75
|
+
the intensity second moment from an explicit reference catalog, intrinsic
|
|
76
|
+
density and merger rate.
|
|
77
|
+
- `astrogwb.inference` provides the dense Gaussian detector-network likelihood
|
|
78
|
+
of any model implementing its `SpectralDensityModel` protocol.
|
|
79
|
+
- `astrogwb.background.simulation.simulate_background` draws segmented detector-pair spectra
|
|
80
|
+
from a supplied physical event pool and observer-frame rate, and
|
|
81
|
+
`astrogwb simulate` runs it on a gwmock-pop population catalogue. See the
|
|
82
|
+
[simulation API, command and normalization](docs/simulator-pipeline.md).
|
|
83
|
+
- `astrogwb.waveform` owns intensity generators, reduces raw
|
|
84
|
+
plus/cross polarizations to power, applies GW-distance corrections to plain
|
|
85
|
+
arrays, and provides a closed-form quadrupolar inspiral model. Persistence
|
|
86
|
+
and labelled-array policy stay with applications.
|
|
87
|
+
`astrogwb.waveform` gives the same power in closed form for a
|
|
88
|
+
quadrupolar, inspiral-only binary, truncated at `f = alpha / ((1 + z) M)`
|
|
89
|
+
for a caller-chosen dimensionless `alpha`.
|
|
90
|
+
|
|
91
|
+
For example:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from astrogwb.detector import load_detector, load_sensitivity
|
|
95
|
+
|
|
96
|
+
hanford = load_detector("H1")
|
|
97
|
+
sensitivity = load_sensitivity("H1")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
A reference catalog places caller-drawn intrinsic sources at one reference
|
|
101
|
+
redshift, face-on, and generates their intensities. The caller supplies the
|
|
102
|
+
source model, the proposal log density of the draws and the reference redshift:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import jax
|
|
106
|
+
import numpy as np
|
|
107
|
+
from numpyro import handlers
|
|
108
|
+
|
|
109
|
+
from astrogwb.background.importance.spectrum import REFERENCE_INCLINATION, reference_catalog
|
|
110
|
+
from astrogwb.populations import coba
|
|
111
|
+
from astrogwb.utils.numpyro import sample_model
|
|
112
|
+
from astrogwb.waveform import WaveformMetadata, waveform_generator
|
|
113
|
+
|
|
114
|
+
params = {
|
|
115
|
+
"H0": 67.66,
|
|
116
|
+
"Omega_m": 0.3096,
|
|
117
|
+
"gamma": 2.35,
|
|
118
|
+
"kappa": 4.4,
|
|
119
|
+
"z_peak": 2.14,
|
|
120
|
+
"local_merger_rate": 240.0,
|
|
121
|
+
"minimum_mass": 1.0,
|
|
122
|
+
"mass_width": 1.5,
|
|
123
|
+
}
|
|
124
|
+
waveform = WaveformMetadata(
|
|
125
|
+
approximant="AnalyticInspiral",
|
|
126
|
+
minimum_frequency=2.0,
|
|
127
|
+
maximum_frequency=2048.0,
|
|
128
|
+
reference_frequency=2.0,
|
|
129
|
+
sampling_frequency=4096.0,
|
|
130
|
+
frequency_resolution=1.0,
|
|
131
|
+
)
|
|
132
|
+
mass_sites = ("source_frame_mass_1", "source_frame_mass_2")
|
|
133
|
+
model = handlers.condition(
|
|
134
|
+
coba.source_model(params, mass_model="uniform"),
|
|
135
|
+
data={"inclination": REFERENCE_INCLINATION},
|
|
136
|
+
)
|
|
137
|
+
samples = sample_model(model, jax.random.key(42), 1024)
|
|
138
|
+
catalog = reference_catalog(
|
|
139
|
+
waveform_generator(waveform),
|
|
140
|
+
samples,
|
|
141
|
+
intrinsic_sites=mass_sites,
|
|
142
|
+
# Joint density of the ordered uniform mass pair.
|
|
143
|
+
proposal_log_prob=np.full(1024, np.log(2.0) - 2.0 * np.log(params["mass_width"])),
|
|
144
|
+
reference_redshift=0.01,
|
|
145
|
+
parameters=params,
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
A spectrum prediction uses the reference catalog, with every source placed at
|
|
150
|
+
a common reference redshift and face-on, so that
|
|
151
|
+
a source at any redshift is a rescaling of its reference power. Intrinsic
|
|
152
|
+
parameters are reweighted to a target population; redshift is integrated by
|
|
153
|
+
quadrature. The proposal and target log densities must use the same variables
|
|
154
|
+
and measure. Here the spin and tidal distributions are shared, so their
|
|
155
|
+
densities cancel and only the ordered mass pair enters the ratio.
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
import jax.numpy as jnp
|
|
159
|
+
import numpy as np
|
|
160
|
+
|
|
161
|
+
from astrogwb.background.importance.model import CatalogModel
|
|
162
|
+
from astrogwb.rates import madau_dickinson_rate
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def ordered_mass_log_prob(intrinsic, target):
|
|
166
|
+
primary, secondary = (intrinsic[name] for name in mass_sites)
|
|
167
|
+
low, width = target["minimum_mass"], target["mass_width"]
|
|
168
|
+
support = (low <= secondary) & (secondary <= primary) & (primary <= low + width)
|
|
169
|
+
return jnp.where(support, jnp.log(2.0) - 2.0 * jnp.log(width), -jnp.inf)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def merger_rate(redshift, target):
|
|
173
|
+
return madau_dickinson_rate(
|
|
174
|
+
redshift,
|
|
175
|
+
target["gamma"],
|
|
176
|
+
target["kappa"],
|
|
177
|
+
target["z_peak"],
|
|
178
|
+
target["local_merger_rate"],
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
model = CatalogModel.from_catalog(
|
|
183
|
+
catalog,
|
|
184
|
+
merger_rate=merger_rate,
|
|
185
|
+
log_prob=ordered_mass_log_prob,
|
|
186
|
+
frequencies=np.arange(10.0, 1000.0, 1.0),
|
|
187
|
+
num_redshift_nodes=32,
|
|
188
|
+
minimum_redshift=0.01,
|
|
189
|
+
maximum_redshift=20.0,
|
|
190
|
+
)
|
|
191
|
+
prediction = model(
|
|
192
|
+
{**params, "mass_width": 1.2, "H0": 70.0, "xi_0": 1.2, "xi_n": 1.91},
|
|
193
|
+
shot_noise=True,
|
|
194
|
+
)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
When the target intrinsic density matches the proposal throughout the analysis,
|
|
198
|
+
pass `target_matches_proposal=True` in place of `log_prob` to cache the
|
|
199
|
+
unit-weight moments.
|
|
200
|
+
|
|
201
|
+
`prediction.spectral_density` is the background's mean, $S_h = 2\mathcal R\langle I\rangle$,
|
|
202
|
+
and `prediction.intensity_second_moment` is $4\mathcal R\langle I I'\rangle$, the
|
|
203
|
+
raw second moment that sets the shot noise of a Poisson catalog. A detector
|
|
204
|
+
network's likelihood of its per-pair cross powers is the dense Gaussian with
|
|
205
|
+
covariance `Sigma + intensity_second_moment * connected_overlap / T`
|
|
206
|
+
(elementwise), with `Sigma` the detector noise, `connected_overlap` the
|
|
207
|
+
network's sky and polarization average
|
|
208
|
+
(`astrogwb.detector.connected_overlap`) and `T` the observation time. The
|
|
209
|
+
likelihood builds the network from the detectors; the data are keyed by the
|
|
210
|
+
sorted detector-name pair:
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from astrogwb.detector import load_detector
|
|
214
|
+
from astrogwb.inference import DenseGaussianLikelihood
|
|
215
|
+
|
|
216
|
+
likelihood = DenseGaussianLikelihood(
|
|
217
|
+
model,
|
|
218
|
+
[load_detector(name) for name in ("E1", "E2", "E3")], # or a network name
|
|
219
|
+
frequencies=frequencies,
|
|
220
|
+
observation_time=1.0, # years
|
|
221
|
+
observed={("E1", "E2"): c_12, ("E1", "E3"): c_13, ("E2", "E3"): c_23},
|
|
222
|
+
)
|
|
223
|
+
log_likelihood, extras = likelihood.log_likelihood(params)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Any pytree implementing `SpectralDensityModel` works in place of a catalog
|
|
227
|
+
model, for example a `jax.tree_util.Partial` of a module-level function
|
|
228
|
+
returning a `SpectralDensityPrediction`.
|
|
229
|
+
|
|
230
|
+
## Experiments
|
|
231
|
+
|
|
232
|
+
Paper notebooks, run configurations, plotting, and cluster workflows live in
|
|
233
|
+
the private [`experiments-astrogwb`](https://github.com/binado/experiments-astrogwb) repository. This distribution
|
|
234
|
+
contains the scientific library and the `astrogwb` CLI (`pip install
|
|
235
|
+
"astrogwb[cli]"`). `astrogwb simulate` takes waveform settings via
|
|
236
|
+
`--waveform-config` and detector layers via `--detector-config`.
|
astrogwb-0.8.0/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# astrogwb
|
|
2
|
+
|
|
3
|
+
`astrogwb` provides reusable scientific modules for modelling the stochastic
|
|
4
|
+
gravitational-wave background from compact-binary populations and performing
|
|
5
|
+
Bayesian inference with detector networks.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install astrogwb
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Optional accelerator builds are available as `astrogwb[cuda]` and
|
|
14
|
+
`astrogwb[tpu]`. Direct HDF5 catalog serialization is opt-in:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install astrogwb[io]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Library modules
|
|
21
|
+
|
|
22
|
+
- `astrogwb.constants` holds the SI physical constants and unit conversions
|
|
23
|
+
every other module shares. The tabulated values are the LALSuite literals,
|
|
24
|
+
so results are bit-comparable with LALSimulation and ripple.
|
|
25
|
+
- `astrogwb.detector` loads bundled detector geometry and sensitivity data and
|
|
26
|
+
evaluates overlap-reduction functions and effective PSDs.
|
|
27
|
+
- `astrogwb.background` provides spectral-density, Omega-GW conversion, and SNR
|
|
28
|
+
calculations. `astrogwb.background.analytic` evaluates the inspiral-only
|
|
29
|
+
background in closed form, truncated on the same dimensionless `alpha` as
|
|
30
|
+
`astrogwb.waveform`.
|
|
31
|
+
- `astrogwb.populations` and `astrogwb.background.importance` provide BNS reference
|
|
32
|
+
catalog generation, including scrambled Sobol draws.
|
|
33
|
+
- `astrogwb.background.importance.model.CatalogModel` predicts the spectral density and
|
|
34
|
+
the intensity second moment from an explicit reference catalog, intrinsic
|
|
35
|
+
density and merger rate.
|
|
36
|
+
- `astrogwb.inference` provides the dense Gaussian detector-network likelihood
|
|
37
|
+
of any model implementing its `SpectralDensityModel` protocol.
|
|
38
|
+
- `astrogwb.background.simulation.simulate_background` draws segmented detector-pair spectra
|
|
39
|
+
from a supplied physical event pool and observer-frame rate, and
|
|
40
|
+
`astrogwb simulate` runs it on a gwmock-pop population catalogue. See the
|
|
41
|
+
[simulation API, command and normalization](docs/simulator-pipeline.md).
|
|
42
|
+
- `astrogwb.waveform` owns intensity generators, reduces raw
|
|
43
|
+
plus/cross polarizations to power, applies GW-distance corrections to plain
|
|
44
|
+
arrays, and provides a closed-form quadrupolar inspiral model. Persistence
|
|
45
|
+
and labelled-array policy stay with applications.
|
|
46
|
+
`astrogwb.waveform` gives the same power in closed form for a
|
|
47
|
+
quadrupolar, inspiral-only binary, truncated at `f = alpha / ((1 + z) M)`
|
|
48
|
+
for a caller-chosen dimensionless `alpha`.
|
|
49
|
+
|
|
50
|
+
For example:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from astrogwb.detector import load_detector, load_sensitivity
|
|
54
|
+
|
|
55
|
+
hanford = load_detector("H1")
|
|
56
|
+
sensitivity = load_sensitivity("H1")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
A reference catalog places caller-drawn intrinsic sources at one reference
|
|
60
|
+
redshift, face-on, and generates their intensities. The caller supplies the
|
|
61
|
+
source model, the proposal log density of the draws and the reference redshift:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import jax
|
|
65
|
+
import numpy as np
|
|
66
|
+
from numpyro import handlers
|
|
67
|
+
|
|
68
|
+
from astrogwb.background.importance.spectrum import REFERENCE_INCLINATION, reference_catalog
|
|
69
|
+
from astrogwb.populations import coba
|
|
70
|
+
from astrogwb.utils.numpyro import sample_model
|
|
71
|
+
from astrogwb.waveform import WaveformMetadata, waveform_generator
|
|
72
|
+
|
|
73
|
+
params = {
|
|
74
|
+
"H0": 67.66,
|
|
75
|
+
"Omega_m": 0.3096,
|
|
76
|
+
"gamma": 2.35,
|
|
77
|
+
"kappa": 4.4,
|
|
78
|
+
"z_peak": 2.14,
|
|
79
|
+
"local_merger_rate": 240.0,
|
|
80
|
+
"minimum_mass": 1.0,
|
|
81
|
+
"mass_width": 1.5,
|
|
82
|
+
}
|
|
83
|
+
waveform = WaveformMetadata(
|
|
84
|
+
approximant="AnalyticInspiral",
|
|
85
|
+
minimum_frequency=2.0,
|
|
86
|
+
maximum_frequency=2048.0,
|
|
87
|
+
reference_frequency=2.0,
|
|
88
|
+
sampling_frequency=4096.0,
|
|
89
|
+
frequency_resolution=1.0,
|
|
90
|
+
)
|
|
91
|
+
mass_sites = ("source_frame_mass_1", "source_frame_mass_2")
|
|
92
|
+
model = handlers.condition(
|
|
93
|
+
coba.source_model(params, mass_model="uniform"),
|
|
94
|
+
data={"inclination": REFERENCE_INCLINATION},
|
|
95
|
+
)
|
|
96
|
+
samples = sample_model(model, jax.random.key(42), 1024)
|
|
97
|
+
catalog = reference_catalog(
|
|
98
|
+
waveform_generator(waveform),
|
|
99
|
+
samples,
|
|
100
|
+
intrinsic_sites=mass_sites,
|
|
101
|
+
# Joint density of the ordered uniform mass pair.
|
|
102
|
+
proposal_log_prob=np.full(1024, np.log(2.0) - 2.0 * np.log(params["mass_width"])),
|
|
103
|
+
reference_redshift=0.01,
|
|
104
|
+
parameters=params,
|
|
105
|
+
)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
A spectrum prediction uses the reference catalog, with every source placed at
|
|
109
|
+
a common reference redshift and face-on, so that
|
|
110
|
+
a source at any redshift is a rescaling of its reference power. Intrinsic
|
|
111
|
+
parameters are reweighted to a target population; redshift is integrated by
|
|
112
|
+
quadrature. The proposal and target log densities must use the same variables
|
|
113
|
+
and measure. Here the spin and tidal distributions are shared, so their
|
|
114
|
+
densities cancel and only the ordered mass pair enters the ratio.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import jax.numpy as jnp
|
|
118
|
+
import numpy as np
|
|
119
|
+
|
|
120
|
+
from astrogwb.background.importance.model import CatalogModel
|
|
121
|
+
from astrogwb.rates import madau_dickinson_rate
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def ordered_mass_log_prob(intrinsic, target):
|
|
125
|
+
primary, secondary = (intrinsic[name] for name in mass_sites)
|
|
126
|
+
low, width = target["minimum_mass"], target["mass_width"]
|
|
127
|
+
support = (low <= secondary) & (secondary <= primary) & (primary <= low + width)
|
|
128
|
+
return jnp.where(support, jnp.log(2.0) - 2.0 * jnp.log(width), -jnp.inf)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def merger_rate(redshift, target):
|
|
132
|
+
return madau_dickinson_rate(
|
|
133
|
+
redshift,
|
|
134
|
+
target["gamma"],
|
|
135
|
+
target["kappa"],
|
|
136
|
+
target["z_peak"],
|
|
137
|
+
target["local_merger_rate"],
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
model = CatalogModel.from_catalog(
|
|
142
|
+
catalog,
|
|
143
|
+
merger_rate=merger_rate,
|
|
144
|
+
log_prob=ordered_mass_log_prob,
|
|
145
|
+
frequencies=np.arange(10.0, 1000.0, 1.0),
|
|
146
|
+
num_redshift_nodes=32,
|
|
147
|
+
minimum_redshift=0.01,
|
|
148
|
+
maximum_redshift=20.0,
|
|
149
|
+
)
|
|
150
|
+
prediction = model(
|
|
151
|
+
{**params, "mass_width": 1.2, "H0": 70.0, "xi_0": 1.2, "xi_n": 1.91},
|
|
152
|
+
shot_noise=True,
|
|
153
|
+
)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
When the target intrinsic density matches the proposal throughout the analysis,
|
|
157
|
+
pass `target_matches_proposal=True` in place of `log_prob` to cache the
|
|
158
|
+
unit-weight moments.
|
|
159
|
+
|
|
160
|
+
`prediction.spectral_density` is the background's mean, $S_h = 2\mathcal R\langle I\rangle$,
|
|
161
|
+
and `prediction.intensity_second_moment` is $4\mathcal R\langle I I'\rangle$, the
|
|
162
|
+
raw second moment that sets the shot noise of a Poisson catalog. A detector
|
|
163
|
+
network's likelihood of its per-pair cross powers is the dense Gaussian with
|
|
164
|
+
covariance `Sigma + intensity_second_moment * connected_overlap / T`
|
|
165
|
+
(elementwise), with `Sigma` the detector noise, `connected_overlap` the
|
|
166
|
+
network's sky and polarization average
|
|
167
|
+
(`astrogwb.detector.connected_overlap`) and `T` the observation time. The
|
|
168
|
+
likelihood builds the network from the detectors; the data are keyed by the
|
|
169
|
+
sorted detector-name pair:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from astrogwb.detector import load_detector
|
|
173
|
+
from astrogwb.inference import DenseGaussianLikelihood
|
|
174
|
+
|
|
175
|
+
likelihood = DenseGaussianLikelihood(
|
|
176
|
+
model,
|
|
177
|
+
[load_detector(name) for name in ("E1", "E2", "E3")], # or a network name
|
|
178
|
+
frequencies=frequencies,
|
|
179
|
+
observation_time=1.0, # years
|
|
180
|
+
observed={("E1", "E2"): c_12, ("E1", "E3"): c_13, ("E2", "E3"): c_23},
|
|
181
|
+
)
|
|
182
|
+
log_likelihood, extras = likelihood.log_likelihood(params)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Any pytree implementing `SpectralDensityModel` works in place of a catalog
|
|
186
|
+
model, for example a `jax.tree_util.Partial` of a module-level function
|
|
187
|
+
returning a `SpectralDensityPrediction`.
|
|
188
|
+
|
|
189
|
+
## Experiments
|
|
190
|
+
|
|
191
|
+
Paper notebooks, run configurations, plotting, and cluster workflows live in
|
|
192
|
+
the private [`experiments-astrogwb`](https://github.com/binado/experiments-astrogwb) repository. This distribution
|
|
193
|
+
contains the scientific library and the `astrogwb` CLI (`pip install
|
|
194
|
+
"astrogwb[cli]"`). `astrogwb simulate` takes waveform settings via
|
|
195
|
+
`--waveform-config` and detector layers via `--detector-config`.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "astrogwb"
|
|
3
|
+
version = "0.8.0"
|
|
4
|
+
description = "Bayesian inference for compact-binary stochastic gravitational-wave backgrounds"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Intended Audience :: Science/Research",
|
|
12
|
+
"Operating System :: OS Independent",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.12",
|
|
15
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
16
|
+
]
|
|
17
|
+
dependencies = [
|
|
18
|
+
"gwmock-noise>=0.10.1",
|
|
19
|
+
"gwmock-signal[jax]>=0.15.0",
|
|
20
|
+
"ripplegw>=0.3.1",
|
|
21
|
+
"jax>=0.10.2; sys_platform == 'linux'",
|
|
22
|
+
"jax[cpu]>=0.11.0; sys_platform != 'linux'",
|
|
23
|
+
"numpy>=2.1",
|
|
24
|
+
"numpyro>=0.21.0",
|
|
25
|
+
"pydantic>=2.14",
|
|
26
|
+
"pyknf>=0.6,<0.8",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[[project.authors]]
|
|
30
|
+
name = "Bernardo Veronese"
|
|
31
|
+
email = "bernardopveronese@gmail.com"
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
astrogwb = "astrogwb.cli:app"
|
|
35
|
+
|
|
36
|
+
[project.optional-dependencies]
|
|
37
|
+
cuda = ["jax[cuda12]>=0.11.0"]
|
|
38
|
+
io = ["h5py>=3.15"]
|
|
39
|
+
cli = [
|
|
40
|
+
"astrogwb[io]",
|
|
41
|
+
"gwmock-pop>=0.11.4",
|
|
42
|
+
"typer>=0.16",
|
|
43
|
+
]
|
|
44
|
+
simulation = ["gwmock-pop>=0.11.4"]
|
|
45
|
+
tpu = ["jax[tpu]>=0.11.0"]
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
Homepage = "https://github.com/binado/astrogwb"
|
|
49
|
+
Repository = "https://github.com/binado/astrogwb"
|
|
50
|
+
Issues = "https://github.com/binado/astrogwb/issues"
|
|
51
|
+
|
|
52
|
+
[build-system]
|
|
53
|
+
requires = ["uv_build>=0.12.2,<0.13.0"]
|
|
54
|
+
build-backend = "uv_build"
|
|
55
|
+
|
|
56
|
+
[dependency-groups]
|
|
57
|
+
test = [
|
|
58
|
+
"pytest>=9.0.2",
|
|
59
|
+
"pytest-xdist>=3.8.0",
|
|
60
|
+
"tomli-w>=1.2",
|
|
61
|
+
]
|
|
62
|
+
parity = [
|
|
63
|
+
{ include-group = "test" },
|
|
64
|
+
"bilby>=2.8.2",
|
|
65
|
+
]
|
|
66
|
+
dev = [
|
|
67
|
+
{ include-group = "parity" },
|
|
68
|
+
"ruff>=0.16.1",
|
|
69
|
+
"ty>=0.0.69",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
[tool.uv]
|
|
73
|
+
default-groups = ["dev"]
|
|
74
|
+
|
|
75
|
+
[tool.ruff]
|
|
76
|
+
include = [
|
|
77
|
+
"src/**/*.py",
|
|
78
|
+
"tests/**/*.py",
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
[tool.ruff.lint]
|
|
82
|
+
extend-select = ["TID"]
|
|
83
|
+
|
|
84
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api.astrogwb_experiment]
|
|
85
|
+
msg = "The library must not depend on the experiment application."
|
|
86
|
+
|
|
87
|
+
[tool.ty.src]
|
|
88
|
+
include = [
|
|
89
|
+
"src",
|
|
90
|
+
"tests",
|
|
91
|
+
]
|
|
92
|
+
exclude = ["tests/parity/references/generate_pygwb.py"]
|
|
93
|
+
|
|
94
|
+
[tool.pytest.ini_options]
|
|
95
|
+
addopts = "-n auto --dist loadscope"
|
|
96
|
+
testpaths = ["tests/test_*.py"]
|
|
97
|
+
markers = ["integration: tests that call external libraries or services (deselect with -m 'not integration')"]
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "astrogwb"
|
|
3
|
+
version = "0.8.0"
|
|
4
|
+
description = "Bayesian inference for compact-binary stochastic gravitational-wave backgrounds"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Bernardo Veronese", email = "bernardopveronese@gmail.com" },
|
|
8
|
+
]
|
|
9
|
+
license = "MIT"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Intended Audience :: Science/Research",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"gwmock-noise>=0.10.1",
|
|
22
|
+
"gwmock-signal[jax]>=0.15.0",
|
|
23
|
+
# Direct, not transitive through gwmock-signal[jax]: the Ripple adapter in
|
|
24
|
+
# astrogwb.waveform.generator imports ripplegw itself.
|
|
25
|
+
"ripplegw>=0.3.1",
|
|
26
|
+
"jax>=0.10.2; sys_platform == 'linux'",
|
|
27
|
+
"jax[cpu]>=0.11.0; sys_platform != 'linux'",
|
|
28
|
+
"numpy>=2.1",
|
|
29
|
+
"numpyro>=0.21.0",
|
|
30
|
+
# Direct, though gwmock-noise already installs it and imports it at module
|
|
31
|
+
# scope: core owns the metadata models every persisted artifact carries, so
|
|
32
|
+
# the dependency is declared rather than borrowed from a transitive edge
|
|
33
|
+
# that gwmock-noise is free to drop.
|
|
34
|
+
"pydantic>=2.14",
|
|
35
|
+
"pyknf>=0.6,<0.8",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
astrogwb = "astrogwb.cli:app"
|
|
40
|
+
|
|
41
|
+
[project.optional-dependencies]
|
|
42
|
+
cuda = ["jax[cuda12]>=0.11.0"]
|
|
43
|
+
# HDF5 catalog serialization is opt-in and the published wheel stays lean.
|
|
44
|
+
io = ["h5py>=3.15"]
|
|
45
|
+
# The `astrogwb` command line: simulator stages written to disk.
|
|
46
|
+
cli = ["astrogwb[io]", "gwmock-pop>=0.11.4", "typer>=0.16"]
|
|
47
|
+
# Only the integration cosmology cross-check needs it now: populations are
|
|
48
|
+
# declared as NumPyro models here, so nothing in the library draws through a
|
|
49
|
+
# gwmock graph any more.
|
|
50
|
+
simulation = ["gwmock-pop>=0.11.4"]
|
|
51
|
+
tpu = ["jax[tpu]>=0.11.0"]
|
|
52
|
+
|
|
53
|
+
[project.urls]
|
|
54
|
+
Homepage = "https://github.com/binado/astrogwb"
|
|
55
|
+
Repository = "https://github.com/binado/astrogwb"
|
|
56
|
+
Issues = "https://github.com/binado/astrogwb/issues"
|
|
57
|
+
|
|
58
|
+
[build-system]
|
|
59
|
+
requires = ["uv_build>=0.12.2,<0.13.0"]
|
|
60
|
+
build-backend = "uv_build"
|
|
61
|
+
|
|
62
|
+
# Groups are tooling: never imported by shipped code, never part of a wheel.
|
|
63
|
+
[dependency-groups]
|
|
64
|
+
# tomli-w writes the TOML inputs of the CLI tests.
|
|
65
|
+
test = ["pytest>=9.0.2", "pytest-xdist>=3.8.0", "tomli-w>=1.2"]
|
|
66
|
+
# Reference packages the parity suite (tests/parity) calls directly. pygwb is
|
|
67
|
+
# not among them: it pins scipy<1.14, so its references are frozen arrays
|
|
68
|
+
# written by tests/parity/references/generate_pygwb.py in its own environment.
|
|
69
|
+
parity = [
|
|
70
|
+
{ include-group = "test" },
|
|
71
|
+
"bilby>=2.8.2",
|
|
72
|
+
]
|
|
73
|
+
dev = [
|
|
74
|
+
{ include-group = "parity" },
|
|
75
|
+
"ruff>=0.16.1",
|
|
76
|
+
"ty>=0.0.69",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[tool.uv]
|
|
80
|
+
default-groups = ["dev"]
|
|
81
|
+
|
|
82
|
+
[tool.ruff]
|
|
83
|
+
include = ["src/**/*.py", "tests/**/*.py"]
|
|
84
|
+
|
|
85
|
+
[tool.ruff.lint]
|
|
86
|
+
extend-select = ["TID"]
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
|
89
|
+
"astrogwb_experiment".msg = "The library must not depend on the experiment application."
|
|
90
|
+
|
|
91
|
+
[tool.ty.src]
|
|
92
|
+
include = ["src", "tests"]
|
|
93
|
+
# Runs in its own environment (inline script metadata), not this one.
|
|
94
|
+
exclude = ["tests/parity/references/generate_pygwb.py"]
|
|
95
|
+
|
|
96
|
+
[tool.pytest.ini_options]
|
|
97
|
+
addopts = "-n auto --dist loadscope"
|
|
98
|
+
# Parity needs its own environment (bilby), so it is run by `just test-parity`.
|
|
99
|
+
testpaths = ["tests/test_*.py"]
|
|
100
|
+
markers = [
|
|
101
|
+
"integration: tests that call external libraries or services (deselect with -m 'not integration')",
|
|
102
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Astrophysical stochastic gravitational-wave background utilities.
|
|
2
|
+
|
|
3
|
+
``__version__`` is read from the installed distribution, so ``pyproject.toml``
|
|
4
|
+
stays its single source. It is part of every catalog's cache key: bump it
|
|
5
|
+
whenever a change alters what a population draw or a waveform generator
|
|
6
|
+
produces, or a cached catalog built by the old code keeps being served.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
__version__ = version("astrogwb")
|
|
13
|
+
except PackageNotFoundError: # pragma: no cover - only in an uninstalled tree
|
|
14
|
+
__version__ = "0+unknown"
|
|
15
|
+
|
|
16
|
+
__all__ = ["__version__"]
|