zeus21.z21_utilities

Helper functions to be used across zeus21.

Authors: zeus21 v2 collaboration - June 2026

Emily Bregou ; Hector Afonso G. Cruz ; Sarah Libanore ; Julian B. Muñoz ; Yonny Sklansky ; Emilie Thélie ; Alessandra Venditti

arXiv:2302.08506, arXiv:2306.09403, arXiv:2407.18294, Sklansky et al. (in prep)

Attributes

HAS_NUMBA

Functions

powerboxCtoR(pbobject[, mapkin])

Converts a complex field to real 3D (eg density, T21...) on the powerbox notation.

tophat_smooth(rr, ks, dk)

Top-hat smoothing.

Window(k, R[, WINDOWTYPE])

Window function.

find_nearest_idx(array, values)

Finds the nearest indices for some values inside another array.

print_timer(start_time[, text_before, text_after])

Prints the duration since an initial time.

v2r(v)

Computes the radius from a volume assuming a sphericity.

r2v(r)

Computes the volume of a sphere of radius r.

delete_class_attributes(class_instance)

Properly deallocates all the attributes of a class instance. Calls the garbage collector.

pdf_log_transform(y_values, pdf_y_values)

Get PDF of X = ln(Y) given Y values and their PDF values

lognormal_pdf(y, mu, sigma)

Vectorized lognormal PDF(y)

normal_pdf(y, mu, sigma[, dimy])

Vectorized normal PDF(y). dimy is the number of dimensions for mu and sigma.

pdf_fft_convolution(mu1, sigma1, mu2, sigma2[, highp])

FFT convolution method to compute the PDF of the sum of two lognormal distributions

sigma_log10(sigmaquantity, meanquantity)

Returns the sigma(log10) for a given quantity with mean and sigma in linear units

mean_log10(sigmaquantity, meanquantity)

Returns the mean(log10) for a given quantity with mean and sigma in linear units

get_Pk_from_xi(rsinput, xiinput)

Generic Fourier Transform, returns Pk from an input Corr Func xi. kPf should be the same as _klistCF

get_list_PS(CosmoParams, xi_list, zlisttoconvert)

Returns the power spectrum given a list of CFs (xi_list) evaluated at z=zlisttoconvert as input

smooth_box(box, Resolution, input_boxlength, ncells)

Smooth box

Module Contents

zeus21.z21_utilities.HAS_NUMBA = True[source]
zeus21.z21_utilities.powerboxCtoR(pbobject, mapkin=None)[source]

Converts a complex field to real 3D (eg density, T21…) on the powerbox notation.

Parameters:
  • pbobject (powerbox.PowerBox) – PowerBox object

  • mapkin (np.ndarray) – Map of the field in k space. Default is None. Otherwise assumes its pbobject.delta_k() (although in that case it should be directly pbobject.delta_x()).

Returns:

realmap – Real 3D field

Return type:

np.ndarray

zeus21.z21_utilities.tophat_smooth(rr, ks, dk)[source]

Top-hat smoothing.

Parameters:
  • rr (np.ndarray) – Array of radii.

  • ks (np.ndarray) – Array of wave numbers.

  • dk (np.ndarray) – Field to be smoothed in Fourier space.

Returns:

Smoothed field in real space.

Return type:

np.ndarray

zeus21.z21_utilities.Window(k, R, WINDOWTYPE='TOPHAT')[source]

Window function.

Parameters:
  • k (np.ndarray) – Array of wave numbers.

  • R (np.ndarray) – Array of radii.

  • WINDOWTYPE (str) – Which window function to return. Default is TOPHAT. Can also be GAUSS or TOPHAT1D.

Returns:

Window function.

Return type:

np.ndarray

zeus21.z21_utilities.find_nearest_idx(array, values)[source]

Finds the nearest indices for some values inside another array.

Parameters:
  • array (np.ndarray) – Array from which to find the indices.

  • values (np.ndarray) – Values for which we are searching the indices in array.

Returns:

Array of indices.

Return type:

np.ndarray

zeus21.z21_utilities.print_timer(start_time, text_before='', text_after='')[source]

Prints the duration since an initial time.

Parameters:
  • start_time (time.time()) – Initial time.

  • text_before (str) – Text to print in front of the timer. Default is “”.

  • text_after (str) – Text to print after the timer. Default is “”.

zeus21.z21_utilities.v2r(v)[source]

Computes the radius from a volume assuming a sphericity.

Parameters:

v (float | np.ndarray) – Volume of the object.

Returns:

Radius of the object.

Return type:

float | np.ndarray

zeus21.z21_utilities.r2v(r)[source]

Computes the volume of a sphere of radius r.

Parameters:

r (float | np.ndarray) – Radius.

Returns:

Volume.

Return type:

float | np.ndarray

zeus21.z21_utilities.delete_class_attributes(class_instance)[source]

Properly deallocates all the attributes of a class instance. Calls the garbage collector. Useful when we want to deallocate an instance (doing del cls will not deallocate the attributes instantly as long as the garbage collector hasn’t run).

Parameters:

class_instance (cls instance) – Class instance.

zeus21.z21_utilities.pdf_log_transform(y_values, pdf_y_values)[source]

Get PDF of X = ln(Y) given Y values and their PDF values

Uses the transformation rule: f_X(x) = f_Y(y) * |dy/dx| where x = ln(y), so dy/dx = y. So: f_X(x) = f_Y(y) * y

zeus21.z21_utilities.lognormal_pdf(y, mu, sigma)[source]

Vectorized lognormal PDF(y)

zeus21.z21_utilities.normal_pdf(y, mu, sigma, dimy=None)[source]

Vectorized normal PDF(y). dimy is the number of dimensions for mu and sigma.

zeus21.z21_utilities.pdf_fft_convolution(mu1, sigma1, mu2, sigma2, highp=0.99)[source]

FFT convolution method to compute the PDF of the sum of two lognormal distributions Uses the convolution theorem: convolution in real space = multiplication in Fourier space mu1, sigma1: parameters of the first lognormal distribution mu2, sigma2: parameters of the second lognormal distribution :returns: the range of y values for which the PDF is computed

pdf_values: the PDF values at those y values

Return type:

y_array

zeus21.z21_utilities.sigma_log10(sigmaquantity, meanquantity)[source]

Returns the sigma(log10) for a given quantity with mean and sigma in linear units

zeus21.z21_utilities.mean_log10(sigmaquantity, meanquantity)[source]

Returns the mean(log10) for a given quantity with mean and sigma in linear units

zeus21.z21_utilities.get_Pk_from_xi(rsinput, xiinput)[source]

Generic Fourier Transform, returns Pk from an input Corr Func xi. kPf should be the same as _klistCF

Parameters:
  • rsinput (array) – Array of Rs used to evaluate xiinput

  • xiinput (matrix) – Matrix of values you are Fourier Transforming. Dimension (z, R)

Returns:

  • kPf (list) – List of wavenumbers

  • Pf (matrix) – Resultant Fourier Transform of xiinput. Dimension (z, k)

zeus21.z21_utilities.get_list_PS(CosmoParams, xi_list, zlisttoconvert)[source]

Returns the power spectrum given a list of CFs (xi_list) evaluated at z=zlisttoconvert as input

Parameters:
  • xi_list (matrix) – list of correlation functions

  • zlisttoconvert (array) – which redshifts xi_list is evaluated at

Returns:

_Pk_list – Matrix of power spectra. Dimension (z, K)

Return type:

matrix

zeus21.z21_utilities.smooth_box(box, Resolution, input_boxlength, ncells)[source]

Smooth box

Parameters:
  • box (matrix) – Box

  • Resolution (float) – Resolution over which you want to smooth

  • input_boxlength (int) – Box size

  • ncells (int) – Number of cells per side

Returns:

box_smooth – Smoothed box

Return type:

matrix