zeus21.z21_utilities ==================== .. py:module:: zeus21.z21_utilities .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: zeus21.z21_utilities.HAS_NUMBA Functions --------- .. autoapisummary:: zeus21.z21_utilities.powerboxCtoR zeus21.z21_utilities.tophat_smooth zeus21.z21_utilities.Window zeus21.z21_utilities.find_nearest_idx zeus21.z21_utilities.print_timer zeus21.z21_utilities.v2r zeus21.z21_utilities.r2v zeus21.z21_utilities.delete_class_attributes zeus21.z21_utilities.pdf_log_transform zeus21.z21_utilities.lognormal_pdf zeus21.z21_utilities.normal_pdf zeus21.z21_utilities.pdf_fft_convolution zeus21.z21_utilities.sigma_log10 zeus21.z21_utilities.mean_log10 zeus21.z21_utilities.get_Pk_from_xi zeus21.z21_utilities.get_list_PS zeus21.z21_utilities.smooth_box Module Contents --------------- .. py:data:: HAS_NUMBA :value: True .. py:function:: powerboxCtoR(pbobject, mapkin=None) Converts a complex field to real 3D (eg density, T21...) on the powerbox notation. :param pbobject: PowerBox object :type pbobject: powerbox.PowerBox :param mapkin: 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()). :type mapkin: np.ndarray :returns: **realmap** -- Real 3D field :rtype: np.ndarray .. py:function:: tophat_smooth(rr, ks, dk) Top-hat smoothing. :param rr: Array of radii. :type rr: np.ndarray :param ks: Array of wave numbers. :type ks: np.ndarray :param dk: Field to be smoothed in Fourier space. :type dk: np.ndarray :returns: Smoothed field in real space. :rtype: np.ndarray .. py:function:: Window(k, R, WINDOWTYPE='TOPHAT') Window function. :param k: Array of wave numbers. :type k: np.ndarray :param R: Array of radii. :type R: np.ndarray :param WINDOWTYPE: Which window function to return. Default is TOPHAT. Can also be GAUSS or TOPHAT1D. :type WINDOWTYPE: str :returns: Window function. :rtype: np.ndarray .. py:function:: find_nearest_idx(array, values) Finds the nearest indices for some values inside another array. :param array: Array from which to find the indices. :type array: np.ndarray :param values: Values for which we are searching the indices in array. :type values: np.ndarray :returns: Array of indices. :rtype: np.ndarray .. py:function:: print_timer(start_time, text_before='', text_after='') Prints the duration since an initial time. :param start_time: Initial time. :type start_time: time.time() :param text_before: Text to print in front of the timer. Default is "". :type text_before: str :param text_after: Text to print after the timer. Default is "". :type text_after: str .. py:function:: v2r(v) Computes the radius from a volume assuming a sphericity. :param v: Volume of the object. :type v: float | np.ndarray :returns: Radius of the object. :rtype: float | np.ndarray .. py:function:: r2v(r) Computes the volume of a sphere of radius r. :param r: Radius. :type r: float | np.ndarray :returns: Volume. :rtype: float | np.ndarray .. py:function:: delete_class_attributes(class_instance) 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). :param class_instance: Class instance. :type class_instance: cls instance .. py:function:: pdf_log_transform(y_values, pdf_y_values) 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 .. py:function:: lognormal_pdf(y, mu, sigma) Vectorized lognormal PDF(y) .. py:function:: normal_pdf(y, mu, sigma, dimy=None) Vectorized normal PDF(y). dimy is the number of dimensions for mu and sigma. .. py:function:: pdf_fft_convolution(mu1, sigma1, mu2, sigma2, highp=0.99) 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 :rtype: y_array .. py:function:: sigma_log10(sigmaquantity, meanquantity) Returns the sigma(log10) for a given quantity with mean and sigma in linear units .. py:function:: mean_log10(sigmaquantity, meanquantity) Returns the mean(log10) for a given quantity with mean and sigma in linear units .. py:function:: get_Pk_from_xi(rsinput, xiinput) Generic Fourier Transform, returns Pk from an input Corr Func xi. kPf should be the same as _klistCF :param rsinput: Array of Rs used to evaluate xiinput :type rsinput: array :param xiinput: Matrix of values you are Fourier Transforming. Dimension (z, R) :type xiinput: matrix :returns: * **kPf** (*list*) -- List of wavenumbers * **Pf** (*matrix*) -- Resultant Fourier Transform of xiinput. Dimension (z, k) .. py:function:: get_list_PS(CosmoParams, xi_list, zlisttoconvert) Returns the power spectrum given a list of CFs (xi_list) evaluated at z=zlisttoconvert as input :param xi_list: list of correlation functions :type xi_list: matrix :param zlisttoconvert: which redshifts xi_list is evaluated at :type zlisttoconvert: array :returns: **_Pk_list** -- Matrix of power spectra. Dimension (z, K) :rtype: matrix .. py:function:: smooth_box(box, Resolution, input_boxlength, ncells) Smooth box :param box: Box :type box: matrix :param Resolution: Resolution over which you want to smooth :type Resolution: float :param input_boxlength: Box size :type input_boxlength: int :param ncells: Number of cells per side :type ncells: int :returns: **box_smooth** -- Smoothed box :rtype: matrix