models_utils (gluon's conflicted copy 2024-04-05)
Module providing physical constants and useful cosmological functions.
All the constants are expressed in GeV, unless differently stated. The values are taken from the Particle Data Group (PDG).
ATTRIBUTE | DESCRIPTION |
---|---|
G |
Newton constant (GeV\(^{-2}\))
TYPE:
|
M_pl |
Reduced Planck mass (GeV)
TYPE:
|
T_0 |
Present day temperature of the Universe (GeV)
TYPE:
|
z_eq |
Redshift of matter-radiation equality
TYPE:
|
T_eq |
Temperature of matter-radiation equality (GeV)
TYPE:
|
h |
Reduced Hubble parameter
TYPE:
|
H_0 |
Hubble constant (GeV)
TYPE:
|
H_0_Hz |
Hubble constant (Hz)
TYPE:
|
omega_v |
Dark energy density today (Planck 2018)
TYPE:
|
omega_m |
Matter density today (Planck 2018)
TYPE:
|
omega_r |
Radiation density today (Planck 2018)
TYPE:
|
A_s |
Planck 2018 amplitude of primordial scalar power spectrum
TYPE:
|
f_cmb |
CMB pivot scale (Hz)
TYPE:
|
gev_to_hz |
Conversion from GeV to Hz
TYPE:
|
g_rho_0 |
Relativistic degrees of freedom today
TYPE:
|
g_s_0 |
Entropic relativistic degrees of freedom today
TYPE:
|
priors_type |
Type for parameter priors.
TYPE:
|
Classes¶
ParamDict ¶
Bases: UserDict
UserDict child class that instantiates common or uncommon parameter priors.
Examples:
>>> import numpy as np
>>> from ptarcade.models_utils import ParamDict, prior
>>> from pprint import pprint
>>> parameters = ParamDict(
... {
... "log10_A_dm" : prior("Uniform", -9, -4),
... "log10_f_dm" : prior("Uniform", pmin=-10, pmax=-5.5), # kwargs also work
... "gamma_p" : prior("Uniform", 0, 2 * np.pi, common=False),
... "gamma_e" : prior("Uniform", 0, 2 * np.pi),
... "phi_hat_sq_e" : prior("Gamma", a=1, loc=0, scale=1, common=False),
... }
... )
>>> pprint(parameters, sort_dicts=False)
{'log10_A_dm': log10_A_dm:Uniform(pmin=-9, pmax=-4),
'log10_f_dm': log10_f_dm:Uniform(pmin=-10, pmax=-5.5),
'gamma_p': <class 'enterprise.signals.parameter.Uniform.<locals>.Uniform'>,
'gamma_e': gamma_e:Uniform(pmin=0, pmax=6.283185307179586),
'phi_hat_sq_e': <class 'ptarcade.models_utils.Gamma.<locals>.Gamma'>}
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
Functions¶
g_rho ¶
Return the number of relativistic degrees of freedom as a function of T/GeV or f/Hz.
PARAMETER | DESCRIPTION |
---|---|
x |
The temperature(s) [GeV] or frequency/frequencies [Hz].
TYPE:
|
is_freq |
True if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dof
|
The relativistic degrees of freedom at
TYPE:
|
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
g_rho_jax ¶
Return the number of relativistic degrees of freedom as a function of T/GeV or f/Hz.
PARAMETER | DESCRIPTION |
---|---|
x |
The temperature(s) [GeV] or frequency/frequencies [Hz].
TYPE:
|
is_freq |
True if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dof
|
The relativistic degrees of freedom at
TYPE:
|
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
g_s ¶
Return the number of entropic relativistic degrees of freedom as a function of T/GeV or f/Hz.
PARAMETER | DESCRIPTION |
---|---|
x |
The temperature(s) [GeV] or frequency/frequencies [Hz].
TYPE:
|
is_freq |
True if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dof
|
The entropic relativistic degrees of freedom at
TYPE:
|
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
g_s_jax ¶
Return the number of entropic relativistic degrees of freedom as a function of T/GeV or f/Hz.
PARAMETER | DESCRIPTION |
---|---|
x |
The temperature(s) [GeV] or frequency/frequencies [Hz].
TYPE:
|
is_freq |
True if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dof
|
The entropic relativistic degrees of freedom at
TYPE:
|
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
__g_s_0
cached
¶
Calculate the entropic relativistic degrees of freedom today.
This function is cached because it only needs to be ran once. It is a function instead of a constant so that
if the g_star.dat
file changes, this value will update as well.
PARAMETER | DESCRIPTION |
---|---|
T_0 |
The universe's temperature today [GeV].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The entropic relativistic degrees of freedom today. |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
__g_rho_0
cached
¶
Calculate the relativistic degrees of freedom today.
This function is cached because it only needs to be ran once. It is a function instead of a constant so that
if the g_star.dat
file changes, this value will update as well.
PARAMETER | DESCRIPTION |
---|---|
T_0 |
The universe's temperature today [GeV].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The relativistic degrees of freedom today. |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
GammaPrior ¶
Prior function for Gamma parameters.
PARAMETER | DESCRIPTION |
---|---|
value |
The value of the parameter.
TYPE:
|
a |
The shape parameter of the Gamma distribution.
TYPE:
|
loc |
The location parameter of the Gamma distribution.
TYPE:
|
scale |
The scale parameter of the Gamma distribution.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The probability density of the Gamma distribution at |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
GammaSampler ¶
Sampling function for Gamma parameters.
PARAMETER | DESCRIPTION |
---|---|
a |
The shape parameter of the Gamma distribution.
TYPE:
|
loc |
The location parameter of the Gamma distribution.
TYPE:
|
scale |
The scale parameter of the Gamma distribution.
TYPE:
|
size |
The number of samples to draw.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray
|
A NumPy array of size |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
Gamma ¶
Class factory for Gamma parameters.
PARAMETER | DESCRIPTION |
---|---|
a |
The shape parameter of the Gamma distribution.
TYPE:
|
loc |
The location parameter of the Gamma distribution.
TYPE:
|
scale |
The scale parameter of the Gamma distribution.
TYPE:
|
size |
The number of samples to draw.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Gamma
|
Child class of [enterprise.signals.parameter.Parameter][] for Gamma distribution
TYPE:
|
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
omega2cross ¶
Convert GW energy density.
Converts the GW energy density as a fraction of the closure density into the cross-power spectral density as a function of the frequency in Hz. This is intended to be used as a decorator on a function that returns the GW energy density as a fraction of the closure density.
PARAMETER | DESCRIPTION |
---|---|
omega_hh |
The function that returns the GW energy density as a fraction of the closure density. |
ceffyl: bool If set to tru use a version compatible with ceffyl, if set to false a version compatible with ENTERPRISE
RETURNS | DESCRIPTION |
---|---|
Callable[..., NDArray]
|
A function that returns the cross-power spectral density as a function of the frequency in Hz. |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
prep_data ¶
Shape tabulated data into a form that can be handled by interpn
.
PARAMETER | DESCRIPTION |
---|---|
path |
Path to the tabulated data file.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
grids
|
The grids of the tabulated data. |
omega_grid
|
The omega grid of the tabulated data.
TYPE:
|
par_names
|
The names of the parameters in the tabulated data.
TYPE:
|
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
spec_importer ¶
Import data and create a fast interpolation function.
Interpolate the GWB power spectrum from tabulated data. Return a function that interpolates over frequency.
PARAMETER | DESCRIPTION |
---|---|
path |
Path to the tabulated data file.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable[[NDArray, P], NDArray]
|
A callable object that interpolates the GWB power spectrum at a given frequency |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
freq_at_temp ¶
Find frequency today as function of temperature when GW was horizon size.
Calculates the GW frequency [Hz] today as a function of the universe temperature [GeV] when the GW was of horizon size.
PARAMETER | DESCRIPTION |
---|---|
T |
The universe temperature [GeV] at the time when the GW was of horizon size.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray
|
The GW frequency [Hz] today that was of horizon size when the universe was at temperature |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
freq_at_temp_jax ¶
Find frequency today as function of temperature when GW was horizon size.
Calculates the GW frequency [Hz] today as a function of the universe temperature [GeV] when the GW was of horizon size.
PARAMETER | DESCRIPTION |
---|---|
T |
The universe temperature [GeV] at the time when the GW was of horizon size.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray
|
The GW frequency [Hz] today that was of horizon size when the universe was at temperature |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
temp_at_freq ¶
Get the temperature [GeV] of the universe when a gravitational wave of a certain frequency [Hz] today was of horizon size.
PARAMETER | DESCRIPTION |
---|---|
f |
The frequency in Hz today.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray
|
The temperature [GeV] when the GW at frequency |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
temp_at_freq_jax ¶
Get the temperature [GeV] of the universe when a gravitational wave of a certain frequency [Hz] today was of horizon size.
PARAMETER | DESCRIPTION |
---|---|
f |
The frequency in Hz today.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray
|
The temperature [GeV] when the GW at frequency |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
prior ¶
Wrap enterprise prior creation.
This function wraps the class factories in [enterprise.signals.parameter][].
It functions exactly the same as the original, except that it accepts additional
kwargs
and sets an additional attribute common
. This attribute refers to
whether the parameter this prior corresponds to is common to all pulsars. In the
original implementation in enterprise, the way that this works is ambiguous. With
this function, it is explicit. If the user does not pass common=False
as a kwarg
,
then common
defaults to True
. This attribute will be used by
ptarcade.models_utils.ParamDict objects in the model files.
PARAMETER | DESCRIPTION |
---|---|
name |
The prior to use.
TYPE:
|
*args |
Positional arguments passed to the prior factory.
TYPE:
|
**kwargs |
kwargs passed to the prior factory.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
prior
|
The configured prior.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
SystemExit
|
If the prior name passed does not exist within [enterprise.signals.parameter] |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
signal_to_noise ¶
signal_to_noise(
signal: Callable[[NDArray, ...], NDArray],
signal_args: dict,
sens: NDArray,
Tspan: float,
interp: bool = False,
) -> array_like
Calculate the SNR of a signal given a sensitivity curve.
PARAMETER | DESCRIPTION |
---|---|
signal |
Callable signal function with frequency as the first argument |
signal_args |
Dictionary of kwargs to pass to
TYPE:
|
sens |
Sensitivity curve stored as a 2D NumPy array with dimensions (Hz, h**2*Omega_GW)
TYPE:
|
Tspan |
Timespan of the observation
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float64
|
SNR ratio |
Source code in src/ptarcade/models_utils (gluon's conflicted copy 2024-04-05).py
signal_to_noise_jax ¶
signal_to_noise_jax(
signal: Callable[[jax_array, ...], jax_array],
signal_args: dict,
sens: jax_array,
Tspan: float,
) -> jax_array_like
Calculate the signal-to-noise ratio (SNR) of a signal given a sensitivity curve.
PARAMETER | DESCRIPTION |
---|---|
signal |
Callable function that takes frequency as the first argument and returns the signal waveform as a NumPy array.
TYPE:
|
signal_args |
Additional keyword arguments to be passed to the
TYPE:
|
f |
Frequency array in Hz.
TYPE:
|
sensitivity |
Sensitivity curve as a 2D NumPy array with dimensions (Hz, h**2*Omega_GW).
TYPE:
|
Tspan |
Observation timespan in seconds.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ArrayLike
|
The calculated signal-to-noise ratio. |
Notes¶
This function uses JAX for numerical integration.