utils

utils.py contains reference values and utility functions for array reshaping and other common operations used throughout the cosmoGW package.

https://github.com/cosmoGW/cosmoGW/ https://github.com/cosmoGW/cosmoGW/blob/main/src/cosmoGW/utils.py

Note

For full documentation, visit Read the Docs.

These functions are designed to be imported and reused in multiple modules (e.g., GW_models.py, GW_templates.py, hydro_bubbles.py, etc.) to keep code DRY and maintainable.

Example usage:

from cosmoGW.utils import reshape_output

Reference Values in cosmoGW.utils

The following reference values are defined in cosmoGW.utils and are used throughout the cosmoGW codebase for cosmological and gravitational wave calculations. These constants provide standard parameters for phase transitions, cosmology, turbulence, and source modeling.

Reference Values

Name

Value

Description

Tref

100 GeV

Electroweak phase transition temperature

gref

100

Effective degrees of freedom (EWPT)

Neff_ref

3

Reference effective neutrino number

T0K

2.72548 K

CMB temperature

H0_ref

100 km / s / Mpc (converted to Hz)

Hubble constant

OmL0_ref

0.6841

Cosmological constant density parameter

OmM0_ref

0.316

Matter density parameter

h0_ref

0.6732

Reduced Hubble constant

a_ref

5

Batchelor spectrum exponent

b_ref

2/3

Kolmogorov spectrum exponent

alp_ref

2

Smoothness of broken power-law transition

alp_turb

6/17

von Karman smoothness parameter

bPi_vort

3

Spectral slope in anisotropic stresses

alpPi

2.15

Smoothness for anisotropic fit

fPi

2.2

Break frequency of anisotropic stresses

tdecay_ref

‘eddy’

Decaying time in constant-in-time model

OmGW_sw_ref

1e-2

Normalized amplitude (sound waves)

a_sw_ref

3

Low frequency slope (\(f^3`\))

b_sw_ref

1

Intermediate frequency slope (f)

c_sw_ref

3

High frequency slope (\(f^{-3}\))

alp1_sw_ref

1.5

Used in RoperPol:2023bqa

alp2_sw_ref

0.5

Used in RoperPol:2023bqa

alp1_ssm

4

Used in Hindmarsh:2019phv

alp2_ssm

2.0

Used in Hindmarsh:2019phv

alp1_HL

3.6

Found in Caprini:2024gyk

alp2_HL

2.4

Found in Caprini:2024gyk

bs_HL_eff

20

Box-size L/vw for UV cutoff (Caprini:2024yk)

bs_k1HL

40

Box-size L/vw for IR cutoff (Caprini:2024gyk)

peak1_HL

0.4

First peak location in HL template (Caprini:2024gyk)

peak2_HL_weak

0.5

Second peak (weak regime, HL template)

peak2_HL_interm

1.0

Second peak (intermediate regime, HL template)

peak2_HL_str

0.5

Second peak (strong regime, HL template)

peak1_LISA

0.2

First peak location in LISA template (Caprini:2024hue)

peak2_LISA

0.5

Second peak location in LISA template (Caprini:2024hue)

alp1_LISA

2.0

Used in Caprini:2024hue

alp2_LISA

4.0

Used in Caprini:2024hue

Oms_ref

0.1

Source amplitude (fraction to radiation energy)

lf_ref

0.01

Source length scale (normalized by Hubble radius)

beta_ref

100

Nucleation rate beta/H_ast

N_turb

2

Source duration/eddy turnover time ratio

Nk_ref

1000

Wave number discretization

Nkconv_ref

1000

Wave number discretization for convolution

Np_ref

3000

Wave number discretization for convolution

NTT_ref

5000

Lifetimes discretization

dt0_ref

11

Numerical parameter for fit (Caprini:2024gyk)

tini_ref

1.0

Initial time of GW production (normalized)

tfin_ref

1e4

Final time of GW production in cit model

cs2_ref

1/3.

Speed of sound squared

Nxi_ref

10000

Discretization in xi

Nxi2_ref

10

Discretization in xi out of profiles

Nvws_ref

20

Discretization in vwall

tol_ref

1e-5

Tolerance on shooting algorithm

it_ref

30

Number of iterations

vw_def

0.5

Default wall velocity

alpha_def

0.263

Default alpha parameter

vw_hyb

0.7

Hybrid wall velocity

alpha_hyb

0.052

Hybrid alpha parameter

L_LISA

2.5e6 km

LISA arm length

P_LISA

15

LISA parameter P

A_LISA

3

LISA parameter A

L_Taiji

3e6 km

Taiji arm length

P_Taiji

8

Taiji parameter P

A_Taiji

3

Taiji parameter A

SNR_PLS

10

LISA SNR threshold

T_PLS

4

LISA observation time (years)

v_dipole

1.23e-3

Solar dipole velocity

Note

These values are available in cosmoGW.utils and can be imported for use in your own calculations and models.

Author

Dates

References

Used in cosmoGW scientific routines for output reshaping and general utilities.

cosmoGW.utils.Kron_delta(a, b)

Compute the Kronecker delta for two arguments.

Parameters

aint

First argument.

bint

Second argument.

Returns

int

1 if a == b, else 0.

cosmoGW.utils.check_Hubble_Hz(H, func='')

Check that the Hubble parameter H is in Hz units.

Parameters

Hfloat or astropy.units.Quantity

Hubble parameter value.

funcstr, optional

Name of the calling function (for error messages).

Returns

float

Hubble parameter in Hz.

cosmoGW.utils.check_temperature_MeV(T, func='')

Check that the temperature T is in MeV units.

Parameters

Tfloat or astropy.units.Quantity

Temperature value.

funcstr, optional

Name of the calling function (for error messages).

Returns

float

Temperature in MeV.

cosmoGW.utils.complete_beta(a, b)

Compute the complete beta function for given arguments.

Parameters

afloat

First argument.

bfloat

Second argument.

Returns

float

Value of the beta function.

cosmoGW.utils.read_csv(file, dir0='resources/detectors_sensitivity/', dir_HOME=None, a='f', b='Omega')

Read a CSV file and return a pandas DataFrame.

Parameters

filestr

Filename of the CSV file.

dir0str, optional

Default directory for sensitivity files.

dir_HOMEstr, optional

Home directory override.

a, bstr, optional

Column names to use for frequency and Omega.

Returns

dfpandas.DataFrame

DataFrame containing the CSV data.

cosmoGW.utils.reshape_output(arr, mult_a=True, mult_b=True, mult_c=True, mult_d=True, mult_e=True, skip=0)

Reshape a 2D output array to 1D or scalar depending on input flags.

Parameters

Omegasndarray

The array to reshape (2D).

mult_alpbool

True if the first dimension is multi-valued (array), False if scalar.

mult_vwbool

True if the second dimension is multi-valued (array), False if scalar.

Returns

ndarray or scalar

The reshaped output array or scalar.

cosmoGW.utils.safe_trapezoid(y, x, axis=-1)

Safely compute the trapezoidal integral of y with respect to x.

Parameters

yarray_like

Values to integrate.

xarray_like

Integration variable.

axisint, optional

Axis along which to integrate (default: -1).

Returns

float or ndarray

The integral result.