slsim.Halos package¶
Submodules
slsim.Halos.halo_population module¶
- slsim.Halos.halo_population.calc_vol(z, cosmo_col)[source]¶
Volume appeared in cosmological 3D integral.
- Parameters:
z (float) – redshift
cosmo_col (colossus.cosmology instance) – An instance of a colossus cosmology model
- Returns:
volume
- Return type:
float
- slsim.Halos.halo_population.concent_m_w_scatter(m, z, sig)[source]¶
Concentration parameter of halos in B. Diemer and A. V. Kravtsov, 2015 with updated parameters of Diemer & Joyce 2019 arXiv:1407.4730 [astro- ph.CO]. arXiv:1809.07326 [astro-ph.CO].
- Parameters:
m (nd.array) – halo mass
z (float) – redshift
sig (float) – intrinsic scatter of logarithmic concentration parameter
- Returns:
con_halo: ndarray, concentration parameter of halos
- slsim.Halos.halo_population.dNhalodzdlnM_lens(M, z, cosmo_col)[source]¶
Compute the differential number density of halos with respect to redshift and log halo mass, per a unit of solid angle [deg^2]
- Parameters:
M (ndarray, float) – The masses of the dark matter halos.
z (float) – The redshift at which to compute the differential number density.
cosmo_col (colossus.cosmology instance) – An instance of an colossus cosmology model
- Returns:
dNhalodzdlnM, The differential number density of halos per unit redshift per natural log mass interval per unit area in units of #/deg^2/dlnM[M_sol/h].
- slsim.Halos.halo_population.gene_ang(n)[source]¶
Position angle of the halo.
- Parameters:
n (int) – length of halo mass nd.array
- Returns:
position angle of halos in units of degree
slsim.Halos.halos_lens_base module¶
- class slsim.Halos.halos_lens_base.HalosLensBase(halos_list, mass_correction_list=None, cosmo=None, sky_area=0.012566370614359173, mass_sheet=True, z_source=5)[source]¶
Bases:
objectManages the lensing properties of halos and mass sheet, providing methods to compute and analyze their lensing effects such as convergence and shear.
- Parameters:
halos_list (astropy.Table): Table containing details of halos, including their redshifts and masses. mass_correction_list (astropy.Table, optional): Table for mass correction, containing details like redshifts and external convergences. Defaults to None. Ignored if mass_sheet is set to False. cosmo (astropy.Cosmology, optional): Cosmology used for lensing computations. If not provided, the default astropy cosmology is used. sky_area (float, optional): Total sky area in steradians over which halos are distributed. Defaults to a small sky patch (0.004 * pi steradians). samples_number (int, optional): Number of samples for statistical calculations. Defaults to 1000. mass_sheet (bool, optional): Flag to decide whether to use the mass_sheet correction. Defaults to True. z_source (float, optional): The redshift of the source being lensed. Defaults to 5.
- Attributes:
halos_list (astropy.Table): Table of halos. n_halos (int): Number of halos in halos_list. sky_area (float): Total sky area in steradians. halos_redshift_list (numpy.ndarray): Redshifts of the halos. mass_list (numpy.ndarray): Masses of the halos in solar masses. cosmo (astropy.Cosmology): Cosmology used for computations. param_lens_model (lenstronomy.LensModel.LensModel): LensModel with an NFW profile for each halo.
- Methods:
enhance_halos_table_random_pos(): Enhances the halos table with random positions. get_lens_model(): Creates a lens model using provided halos and optional mass sheet correction. random_position(): Generates and returns random positions in the sky using a uniform distribution. get_nfw_kwargs(): Returns the angle at scale radius and observed bending angle at the scale radius for NFW profile. get_halos_lens_kwargs(): Constructs and returns the list of keyword arguments for each halo in the lens model. filter_halos_by_redshift(): Filters halos and mass corrections by redshift conditions and constructs lens data. get_lens_data_by_redshift(): Retrieves lens data filtered by the specified redshift range. halos_get_convergence_shear(): Computes the convergence and shear at the origin due to all Halos. compute_halos_nonlinear_correction_kappa_gamma_values(): Compute the various convergence and shear values from the non-linear correction numbers. halos_get_kext_gext_values(): Compute the non-linear external convergence and shear values from the Halos. halos_compute_kappa(): Computes the convergence across the lensed sky area. plot_halos_convergence(): Compares and plots the convergence for different configurations of the mass sheet. enhance_halos_pos_to0(): Sets the positions of all halos to 0. halos_various_halos_data(): Computes various convergence (kappa) and shear (gamma) values for given deflector and source redshifts.
- compute_halos_nonlinear_correction_kappa_gamma_values(zd, zs)[source]¶
Compute various kappa and gamma values for the given lens data. This function retrieves the lens data based on the input redshifts and computes the convergence and shear for three categories: od, os, and ds. The gamma values are computed for both components, gamma1 and gamma2.
kappa_od, kappa_os, gamma_od1, gamma_od2, gamma_os1, gamma_os2, kappa_ds,r gamma_ds1, gamma_ds2,
- Parameters:
zd (float) – Deflector redshift.
zs (float) – Source redshift.
- Returns:
A tuple containing the convergence and shear values for od, os, and ds categories.
- Return type:
(float, float, float, float, float, float, float, float, float)
- filter_halos_by_redshift(zd, zs)[source]¶
Filters halos and mass corrections by redshift conditions and constructs lens data.
- Parameters:
zd (float) – Deflector redshift.
zs (float) – Source redshift. It should be greater than zd; otherwise, a ValueError is raised.
- Returns:
A tuple containing lens data for three different conditions: 1. Between deflector and source redshift (ds). 2. From zero to deflector redshift (od). 3. From zero to source redshift (os).
- Return type:
tuple
- Raises:
ValueError – If the source redshift (zs) is less than the deflector redshift (zd).
Note
Uses _filter_halos_by_condition to filter halos based on redshift conditions.
Uses _filter_mass_correction_by_condition to filter mass corrections based on redshift conditions.
Uses _build_lens_data to construct lens data for each condition.
- get_halos_lens_kwargs()[source]¶
Constructs and returns the list of keyword arguments for each halo to be used in the lens model for lenstronomy.
- Returns:
kwargs_halos – list of dicts. The list of dictionaries containing the keyword arguments for each halo.
- get_lens_data_by_redshift(zd, zs)[source]¶
Retrieves lens data filtered by the specified redshift range.
Given a range of redshifts defined by zd and zs, this function filters halos and returns the corresponding lens models, lens cosmologies, and lens keyword arguments for three categories: ds, od, and os. (‘ds` stands for deflector-source, od stands for observer-deflector, and os stands for observer-source.)
- Parameters:
zd (float) – The deflector redshift. It defines the lower bound of the redshift range.
zs (float) – The source redshift. It defines the upper bound of the redshift range.
- Returns:
A dictionary with three keys: ds, od, and os. Each key maps to a sub-dictionary containing: - param_lens_model: The lens model for the corresponding category. - param_lens_cosmo: The lens cosmology for the corresponding category. - kwargs_lens: The lens keyword arguments for the corresponding category.
- Return type:
dict
Note
lens_model_ds = lens_data['ds']['param_lens_model'] lens_cosmo_ds = lens_data['ds']['param_lens_cosmo'] kwargs_lens_ds = lens_data['ds']['kwargs_lens'] # ... and similarly for `od` and `os` data
- get_lens_model()[source]¶
Create a lens model using provided halos and optional mass sheet correction. This method constructs a lens model based on the halos and (if specified) the mass sheet correction. The halos are modeled with the NFW profile, and the mass sheet correction is modeled using the CONVERGENCE profile.
- Returns:
A lens model instance equipped with the parameters and configurations suitable for halo lensing studies. This model serves as the foundation for conducting lensing simulations, enabling the calculation of lensing effects such as deflection angles, shear, and magnification.
- Return type:
LensModel :note:
- get_nfw_kwargs(z=None, mass=None, n_halos=None, lens_cosmo=None, c=None)[source]¶
Returns the angle at scale radius, observed bending angle at the scale radius, and positions of the Halos in the lens plane from physical mass and concentration parameter of an NFW profile.
- Returns:
Rs_angle (numpy.ndarray) – Angle at scale radius (in units of arcsec).
alpha_Rs (numpy.ndarray) – Observed bending angle at the scale radius (in units of arcsec). Arrays containing Rs_angle, alpha_Rs of all the Halos.
- halos_compare_plot_convergence(diff=1e-07, diff_method='square')[source]¶
Compare the convergence plot with and without the mass sheet correction.
- Parameters:
diff (float, optional) – The differential used in the computation of the convergence. Defaults to 0.0000001.
diff_method (str, optional.) – The method used to compute the differential. Defaults to “square”.
Note
The method plots the convergence for two cases: with and without the mass sheet correction.
- halos_compute_kappa(diff=1e-07, num_points=500, diff_method='square', mass_sheet_bool=None, enhance_pos=False)[source]¶
Computes the convergence (kappa) values over a grid and returns both the 2D kappa image and the 1D array of kappa values.
- Parameters:
diff (float, optional) – The differential used in the computation of the convergence. Defaults to 0.0000001.
num_points (int, optional) – The number of points along each axis of the grid. Defaults to 500.
diff_method (str, optional) – The method used to compute the differential. Defaults to “square”.
mass_sheet_bool (bool, optional) – A boolean value indicating whether to include the mass sheet correction. Defaults to None.
enhance_pos (bool, optional) – A boolean value indicating whether to reshuffle the halo positions. Defaults to False.
- Returns:
A tuple containing the 2D kappa image and the 1D array of kappa values.
- Return type:
tuple(numpy.ndarray, numpy.ndarray)
- halos_get_convergence_shear(same_from_class=True, gamma12=False, diff=1.0, diff_method='square', kwargs=None, lens_model=None, zdzs=None)[source]¶
Computes the convergence and shear at the origin due to all Halos. return all 0 if no halos.
- Parameters:
gamma12 (bool, optional) – If True, returns gamma1 and gamma2 in addition to kappa. If False, returns total shear gamma along with kappa.
same_from_class (bool, optional) – If True and kwargs, lens_model is none uses the class’s lens model and lens kwargs. If False, uses the provided lens model and kwargs. Specify for the when the ‘None’ type kwargs
diff (float, optional) – The differential used in the computation of the Hessian matrix. Default is 1.0.
diff_method (str, optional) – The method used to compute the differential. Default is “square”.
kwargs (dict, optional) – Keyword arguments for the lens model. If None, uses the class method to generate them.
lens_model (LensModel, optional) – The lens model instance to use. If None, uses the class’s lens model.
zdzs (tuple, optional) – A tuple of deflector and source redshifts (zd, zs). If provided, uses hessian_z1z2 method of the lens model.
- Returns:
Depending on gamma12, either (kappa, gamma) or (kappa, gamma1, gamma2). Kappa is the convergence, gamma is the total shear, and gamma1 and gamma2 are the shear components.
- Return type:
tuple
- halos_get_kext_gext_values(zd, zs)[source]¶
Compute the kext and gext values for the given lens data.
- Parameters:
zd (float) – Deflector redshift.
zs (float) – Source redshift.
- Returns:
A tuple containing the computed external convergence value (kext) and the computed external shear magnitude (gext).
- Return type:
(float, float)
- halos_various_halos_data(zd, zs)[source]¶
Computes (kappa_od, kappa_os, gamma_od1, gamma_od2, gamma_os1, gamma_os2, kappa_ds, gamma_ds1, gamma_ds2, kappa_os2, gamma_os12, gamma_os22, kext, gext,), (kwargs_lens_os, lens_model_os) convergence (kappa) and shear (gamma) values for given deflector and source redshifts.
This function extracts the lens model and its keyword arguments for different redshift combinations (od, os, and ds). It then computes the convergence and shear values for each of these combinations.
- Parameters:
zd (float) – The deflector redshift.
zs (float) – The source redshift.
- Returns:
- A tuple containing:
A tuple of computed values for kappa and gamma for the different redshift combinations and the external convergence and shear.
A tuple containing the lens model and its keyword arguments for the os redshift combination.
- Return type:
tuple
\[1 - \kappa_{\text{ext}} = \frac{(1-\kappa_{\text{od}})(1-\kappa_{\text{os}})}{1-\kappa_{\text{ds}}}\]and
\[\gamma_{\text{ext}} = \sqrt{(\gamma_{\text{od}1}+\gamma_{\text{os}1} -\gamma_{\text{ds}1})^2 +(\gamma_{\text{od}2}+\gamma_{\text{os}2}-\gamma_{\text{ds}2})^2}\]
- property param_lens_cosmo¶
Lazy-load param_lens_cosmo.
Each instance of LensCosmo in the list is created with specific redshift parameters: - z_lens: the redshift of the lens, which is taken from the combined_redshift_list. - z_source: the source redshift, which is common for all instances and defined as self.z_source. - cosmo: the cosmological model being used, specified as self.cosmo.
This property ensures that the LensCosmo instances are created only once and stored for repeated access, enhancing performance by avoiding redundant calculations.
- Returns:
- list of LensCosmo: A list containing a LensCosmo instance for each combination of
halo and any additional corrections, up to self.n_halos + self.n_correction.
- property param_lens_model¶
Lazy-load param_lens_model.
This property ensures that the lens model is computed only once and stored for repeated access. This is achieved by checking if the _lens_model attribute is already set; if not, it calculates the lens model by calling self.get_lens_model().
- plot_halos_convergence(diff=1e-07, num_points=500, diff_method='square', mass_sheet=None, enhance_pos=True)[source]¶
Plots the convergence map for a field with the influence of halos using a specified lens model.
This method adjusts the mass sheet if provided, recalculates the lens model parameters, and uses these parameters to plot the convergence. It encapsulates handling of the lens model and temporary changes to instance attributes, ensuring they are reset after the plotting operation.
- Parameters:
diff (float, optional) – The differentiation value used for computing the Hessian matrix which influences how the convergence is calculated. Default is 1e-7.
num_points (int, optional) – Number of points along each axis for which convergence is computed. Default is 500.
diff_method (str, optional) – Method to use for differentiation when computing the Hessian. Default is “square”.
mass_sheet (float, optional) – A temporary adjustment to the mass sheet parameter of the lens model. If specified, this value is used during the convergence calculation and then reverted.
enhance_pos (bool, optional) – A flag to determine whether to enhance the positions of halos after plotting by adjusting their table positions randomly. Default is True.
- Returns:
None. This method directly plots the convergence map using matplotlib and manages internal state without returning data.
- Return type:
None
- Notes:
The method temporarily modifies the instance’s mass_sheet to a user-provided value, if given, and restores it afterward. This ensures that other operations are not affected by temporary changes made specifically for this plot. If enhance_pos is True, it also calls self.enhance_halos_table_random_pos() to adjust halo positions after plotting.
- slsim.Halos.halos_lens_base.concentration_from_mass(z, mass, A=75.4, d=-0.422, m=-0.089)[source]¶
Determine halo concentration from mass using Childs et al. 2018 model.
This function calculates the concentration parameter of dark matter halos based on their masses, employing the concentration-mass relation presented in Childs et al. 2018. This relation is applicable to both relaxed and unrelaxed halos, providing a broad utility for modeling halo properties across different cosmic structures.
- Parameters:
z (float) – Redshift of the halo, influencing the concentration-mass relation.
mass (or array_like) – Mass of the halo in solar masses, serving as the primary input for the concentration calculation.
A (float, optional) – Pre-factor in the concentration-mass relation, defaulting to 75.4 as per the reference study.
d (float, optional) – Exponent for the redshift term in the concentration-mass relation, with a default value of -0.422.
m (float, optional) – Exponent for the mass term in the concentration-mass relation, set to -0.089 by default.
- Returns:
The concentration parameter c_200 of the halo(s), providing a measure of the halo’s density profile steepness.
- Return type:
float or array_like :note: The concentration parameter, defined as c_200, is crucial for understanding the density distribution within halos. It is bounded to be at least 1, ensuring physical realism in halo models. :reference: Childs et al. 2018, arXiv:1804.10199, doi:10.3847/1538-4357/aabf95
slsim.Halos.halos_plus_glass module¶
- slsim.Halos.halos_plus_glass.generate_maps_kmean_zero_using_halos(skypy_config=None, skyarea=0.0001, cosmo=None, m_min=None, m_max=None, z_max=None, samples_number_for_one_halos=1000, renders_numbers=500)[source]¶
Given the specified parameters, this function repeatedly renders the same halo list (same z & m) for different positions (samples_number_for_one_halos) times and then ensures that the mean of the kappa values is zero. It then gets the kde of the weak- lensing distribution for this halo list and resamples renders_numbers sets of the corresponding convergence (kappa) and shear (gamma) values for this halo list.
- Parameters:
skypy_config (str or None) – Path to SkyPy configuration yaml file. If None, the default skypy configuration file is used.
skyarea (float, optional) – The sky area in square degrees. Default is 0.0001.
cosmo (astropy.cosmology.FlatLambdaCDM, optional) – The cosmological model. If None, a default FlatLambdaCDM model with H0=70 and Om0=0.3 is used.
m_min (float or None, optional) – Minimum halo mass for the pipeline. Default is None.
m_max (float or None, optional) – Maximum halo mass for the pipeline. Default is None.
z_max (float or None, optional) – Maximum redshift for the pipeline. Default is None.
samples_number_for_one_halos (int, optional) – The number of samples for each halo. Default is 1000.
renders_numbers (int, optional) – The number of random numbers to generate. Default is 500.
- Returns:
A tuple containing the randomly resampled kappa values and gamma values.
- Return type:
(numpy.ndarray, numpy.ndarray)
- slsim.Halos.halos_plus_glass.generate_meanzero_halos_multiple_times(n_times=20, skypy_config=None, skyarea=0.0001, cosmo=None, m_min=None, m_max=None, z_max=None, samples_number_for_one_halos=1000, renders_numbers=500)[source]¶
Given the specified parameters, this function repeatedly renders the same halo list (same z & m) for different positions (samples_number_for_one_halos) times and then ensures that the mean of the kappa values is zero. It then gets the kde of the weak- lensing distribution for this halo list and resamples renders_numbers sets of the corresponding convergence (kappa) and shear (gamma) values for this halo list. This process is repeated n_times to accumulate the results.
- Parameters:
n_times (int, optional) – The number of times to repeat the generation of kappa and gamma values. Default is 20.
skypy_config (string or None) – Path to SkyPy configuration yaml file. If None, the default skypy configuration file is used.
skyarea (float, optional) – The sky area in square degrees. Default is 0.0001.
cosmo (astropy.cosmology.FlatLambdaCDM, optional) – The cosmological model. If None, a default FlatLambdaCDM model with H0=70 and Om0=0.3 is used.
m_min (float or None, optional) – Minimum halo mass for the pipeline. Default is None.
m_max (float or None, optional) – Maximum halo mass for the pipeline. Default is None.
z_max (float or None, optional) – Maximum redshift for the pipeline. Default is None.
samples_number_for_one_halos (int, optional) – The number of samples for each halo. Default is 1000.
renders_numbers (int, optional) – The number of random numbers to generate. Default is 500.
- Returns:
A tuple containing the accumulated randomly resampled kappa values and gamma values.
- Return type:
(numpy.ndarray, numpy.ndarray)
- slsim.Halos.halos_plus_glass.generate_samples_from_glass(kappa_values, gamma_values, n=10000)[source]¶
This function fits a Gaussian Kernel Density Estimation (KDE) to the joint distribution of kappa and gamma values, and then generates a random sample from this distribution.
- Parameters:
kappa_values (numpy.ndarray) – The kappa values.
gamma_values (numpy.ndarray) – The gamma values.
n (int, optional) – The number of random numbers to generate. Defaults to 10000.
- Returns:
A tuple containing two numpy arrays for the randomly resampled kappa and gamma values.
- Return type:
tuple
- slsim.Halos.halos_plus_glass.halos_plus_glass(kappa_random_halos, gamma_random_halos, kappa_random_glass, gamma_random_glass)[source]¶
Combine the kappa and gamma values from Halos and Glass distributions, returning the combined values. For Halos kappa, it is suggested to use modified kappa values (i.e., direct kappa minus mean(kappa)).
- Parameters:
kappa_random_halos (numpy.ndarray) – The randomly resampled kappa values from the Halos.
gamma_random_halos (numpy.ndarray) – The randomly resampled gamma values from the Halos.
kappa_random_glass (numpy.ndarray) – The randomly resampled kappa values from Glass.
gamma_random_glass (numpy.ndarray) – The randomly resampled gamma values from Glass.
- Returns:
A tuple containing two numpy arrays for the combined kappa and gamma values.
- Return type:
tuple
Note
The total shear, \(\gamma_{\text{tot}}\), is computed based on the relationships:
\[\gamma_{\text{tot}} = \sqrt{(\gamma1_{\text{Halos}} + \gamma1_{\text{GLASS}})^2 + (\gamma2_{\text{ Halos}} + \gamma2_{\text{GLASS}})^2}\]and
\[\gamma_{\text{tot}} = \sqrt{\gamma_{\text{Halos}}^2 + \gamma_{\text{GLASS}}^2 + 2\gamma_{\text{ Halos}}\gamma_{\text{GLASS}} \times \cos(\alpha-\beta)}\]Given that \(\alpha\) and \(\beta\) are randomly distributed, and their difference, \(\alpha-\beta\), follows a normal distribution, the shear is given by:
\[\gamma_{\text{tot}}^2 = \gamma_{\text{halos}}^2 + \gamma_{\text{GLASS}}^2 + 2\gamma_{\text{ halos}}\gamma_{\text{GLASS}}\cdot \cos(\text{random angle})\]
- slsim.Halos.halos_plus_glass.read_glass_data(file_name='kgdata.npy')[source]¶
Loads a numpy data file and extracts the kappa and gamma values.
- Parameters:
file_name (str, optional) – The name of the file to load. Defaults to “kgdata.npy”.
- Returns:
A tuple containing two numpy arrays for kappa and gamma values, and nside of the data.
- Return type:
tuple
- slsim.Halos.halos_plus_glass.run_average_mass_by_multiprocessing(n_iterations=1, sky_area=0.0001, m_min=None, m_max=None, z_max=None)[source]¶
Calculate the average mass of halos over multiple iterations using multiprocessing. This method was built for verify the expected_mass_at_redshift in halos.py.
- Parameters:
n_iterations (int, optional) – Number of iterations to run, defaults to 1
sky_area (float, optional) – The sky area over which to calculate the halo mass, defaults to 0.0001
m_min (float, optional) – The minimum mass of halos to consider, defaults to None
m_max (float, optional) – The maximum mass of halos to consider, defaults to None
z_max (float, optional) – The maximum redshift to consider, defaults to None. If None, uses 5.0
- Returns:
A list of average mass values for each iteration
- Return type:
list
- slsim.Halos.halos_plus_glass.run_certain_redshift_lensext_kde_by_multiprocessing(n_iterations=1, sky_area=0.0001, samples_number=1, cosmo=None, m_min=None, m_max=None, z_max=None, mass_sheet_correction=True, zs=None, zd=None, listmean=False, sigma_8=0.81, omega_m=None)[source]¶
Generates distributions of kappa_ext and gamma_ext for a given redshift and cosmology.
- Parameters:
n_iterations (int) – Number of iterations for multiprocessing to run the simulation.
sky_area (float) – Sky area over which halos are sampled.
m_min (float) – Minimum halo mass.
m_max (float) – Maximum halo mass.
z_max (float) – Maximum redshift value.
cosmo – Cosmology used for the calculations.
samples_number (int) – Number of samples to generate.
mass_sheet_correction (bool) – Flag to apply mass sheet correction.
zs (float) – Source redshift.
zd (float) – Lens redshift.
listmean (bool) – Flag to return the mean of the list.
sigma_8 (float) – Sigma_8 parameter for the cosmology.
omega_m (float) – Omega matter parameter for the cosmology.
- Returns:
Distributions of kappa_ext and gamma_ext.
- Return type:
np.ndarray
- slsim.Halos.halos_plus_glass.run_certain_redshift_many_by_multiprocessing(n_iterations=1, sky_area=0.0001, samples_number=1, cosmo=None, m_min=None, m_max=None, z_max=None, mass_sheet_correction=True, zs=None, zd=None)[source]¶
Runs the simulation for a certain redshift range multiple times using multiprocessing.
- Parameters:
n_iterations (int, optional) – Number of iterations to run the simulation, defaults to 1
sky_area (float, optional) – The sky area over which to simulate, defaults to 0.0001
samples_number (int, optional) – Number of samples to generate, defaults to 1
cosmo (astropy.cosmology.FLRW, optional) – Cosmology used for the simulation, defaults to None. If None, uses FlatLambdaCDM with H0=70, Om0=0.3.
m_min (float, optional) – Minimum mass for the halos, defaults to None
m_max (float, optional) – Maximum mass for the halos, defaults to None
z_max (float, optional) – Maximum redshift for the halos, defaults to None. If None, uses 5.0.
mass_sheet_correction (bool, optional) – Flag to apply mass sheet correction, defaults to True
zs (float, optional) – Source redshift, defaults to None. If None, uses 1.5.
zd (float, optional) – Lens redshift, defaults to None. If None, uses 1.0.
- Returns:
A tuple containing two lists: kappaext_gammaext_values and lensinstance_values.
- Return type:
tuple(list, list)
- slsim.Halos.halos_plus_glass.run_halos_without_kde(n_iterations=1, sky_area=0.0001, samples_number=1500, cosmo=None, m_min=None, m_max=None, z_max=5.0, mass_sheet_correction=True, listmean=False)[source]¶
Under the specified sky_area, generate n_iterations sets of halo lists. For each set, simulate samples_number times to obtain the convergence (kappa) and shear (gamma) values at the origin. These values are directly appended without any additional processing (i.e., without KDE computation, resampling, or subtracting the mean kappa value).
- Parameters:
n_iterations (int, optional) – Number of iterations or halo lists to generate.
sky_area (float, optional) – Total sky area (in steradians) over which Halos are distributed.
samples_number (int, optional) – Number of samples for statistical calculations.
cosmo (astropy.cosmology instance, optional) – Cosmology used for the simulations. If not provided, the default astropy cosmology is used.
m_min (float, optional) – Minimum mass of the Halos to consider. If not provided, no lower limit is set.
m_max (float, optional) – Maximum mass of the Halos to consider. If not provided, no upper limit is set.
z_max (float, optional) – Maximum redshift of the Halos to consider. If not provided, no upper limit is set.
mass_sheet_correction (bool, optional) – Flag to apply mass sheet correction. Defaults to True.
listmean (bool, optional) – Flag to subtract the mean kappa value from the results. Defaults to False.
- Returns:
A tuple containing two lists; the first list contains the combined convergence (kappa) values from all iterations, and the second list contains the combined shear (gamma) values from all iterations.
- Return type:
(list, list)
Note
This function initializes a halo distribution pipeline for each iteration, simulates Halos, and then computes the lensing properties (kappa and gamma). The results from all iterations are concatenated to form the final output lists.
Warning
If no cosmology is provided, the function uses the default astropy cosmology, which is a flat Lambda-CDM model with H0=70 and Om0=0.3.
- slsim.Halos.halos_plus_glass.run_halos_without_kde_by_multiprocessing(n_iterations=1, sky_area=0.0001, samples_number=1500, cosmo=None, m_min=None, m_max=None, z_max=5.0, mass_sheet_correction=True, listmean=False, sigma_8=0.81, omega_m=None)[source]¶
Under the specified sky_area, generate n_iterations sets of halo lists. For each set, simulate samples_number times to obtain the convergence (kappa) and shear (gamma) values at the origin. These values are directly appended without any additional processing (i.e., without KDE computation, resampling, or subtracting the mean kappa value), the process procedure n_iterations generate with multiprocessing.
- Parameters:
n_iterations (int, optional) – Number of iterations or halo lists to generate. Defaults to 1.
sky_area (float, optional) – Total sky area (in steradians) over which Halos are distributed. Defaults to 0.0001 steradians.
samples_number (int, optional) – Number of samples for statistical calculations. Defaults to 1500.
cosmo (astropy.cosmology instance, optional) – Cosmology used for the simulations. If not provided, the default astropy cosmology is used.
m_min (float, optional) – Minimum mass of the Halos to consider. If not provided, no lower limit is set.
m_max (float, optional) – Maximum mass of the Halos to consider. If not provided, no upper limit is set.
z_max (float, optional) – Maximum redshift of the Halos to consider. If not provided, no upper limit is set.
mass_sheet_correction (bool, optional) – If True, apply mass sheet correction. Defaults to True.
listmean (bool, optional) – If True, subtract the mean kappa value from the results. Defaults to False.
sigma_8 (float, optional) – The value of sigma_8 for the cosmology. Defaults to 0.81.
omega_m (float, optional) – The value of omega_m for the cosmology. If None, the default value is used.
- Returns:
A tuple containing two lists; the first list contains the combined convergence (kappa) values from all iterations, and the second list contains the combined shear (gamma) values from all iterations.
- Return type:
(list, list)
Note
This function initializes a halo distribution pipeline for each iteration, simulates Halos, and then computes the lensing properties (kappa and gamma). The results from all iterations are concatenated to form the final output lists.
Warning
If no cosmology is provided, the function uses the default astropy cosmology, which is a flat Lambda-CDM model with H0=70 and Om0=0.3.
- slsim.Halos.halos_plus_glass.run_kappaext_gammaext_kde_by_multiprocessing(n_iterations=1, sky_area=0.0001, samples_number=1, cosmo=None, m_min=None, m_max=None, z_max=5.0, mass_sheet_correction=True, listmean=False, output_format='dict')[source]¶
Run the kappa-gamma external convergence distribution for a given number of iterations using multiprocessing.
This function generates kappa and gamma distributions using the provided parameters and a worker function (worker_kappaext_gammaext_kde). The distributions are generated in parallel over the specified number of iterations.
- Parameters:
n_iterations (int, optional) – The number of iterations to run the simulation. Defaults to 1.
sky_area (float, optional) – The area of the sky under consideration (in steradians). Defaults to 0.0001.
samples_number (int, optional) – The number of samples to be used. Defaults to 1.
cosmo (astropy.cosmology instance, optional) – The cosmology to be used. If not provided, it defaults to FlatLambdaCDM with H0=70 and Om0=0.3.
m_min (float, optional) – The minimum mass for the simulation. If None, it is decided by the worker function.
m_max (float, optional) – The maximum mass for the simulation. If None, it is decided by the worker function.
z_max (float, optional) – The maximum redshift for the simulation. If None, it is decided by the worker function.
mass_sheet_correction (bool, optional) – If True, apply mass sheet correction. Defaults to True.
output_format (str, optional) – The format in which the results should be returned, either as dict or vector. Defaults to dict.
- Returns:
A list of kappa and gamma values across all iterations.
- Return type:
list
Note
The function employs multiprocessing to run simulations in parallel, improving computational efficiency. The elapsed runtime for the simulations is printed to the console.
- slsim.Halos.halos_plus_glass.run_total_kappa_by_multiprocessing(n_iterations=1, sky_area=0.0001, diff=1e-07, num_points=500, diff_method='square', cosmo=None, m_min=None, m_max=None, z_max=None)[source]¶
Runs the total kappa computation in parallel using multiprocessing for a given number of iterations.
- Parameters:
n_iterations (int, optional) – The number of iterations to run the computation for.
sky_area (float, optional) – The sky area over which to compute the total kappa.
diff (float, optional) – The differential to use in the computation.
num_points (int, optional) – The number of points to use in the computation.
diff_method (str, optional) – The method to use for the differential computation.
cosmo (astropy.cosmology.FLRW, optional) – The cosmology model to use. If None, a default FlatLambdaCDM model is used.
m_min (float, optional) – The minimum mass to consider in the halo computation.
m_max (float, optional) – The maximum mass to consider in the halo computation.
z_max (float, optional) – The maximum redshift to consider. If None, a default value of 5.0 is used.
- Returns:
A list of average kappa values for each iteration.
- Return type:
list
- slsim.Halos.halos_plus_glass.run_total_mass_by_multiprocessing(n_iterations=1, sky_area=0.0001, cosmo=None, m_min=None, m_max=None, z_max=None)[source]¶
Calculate the total mass of halos over multiple iterations using multiprocessing.
- Parameters:
n_iterations (int, optional) – Number of iterations to run, defaults to 1
sky_area (float, optional) – The sky area over which to calculate the halo mass, defaults to 0.0001
cosmo (astropy.cosmology.FlatLambdaCDM, optional) – The cosmology model to use, defaults to None. If None, uses FlatLambdaCDM with H0=70, Om0=0.3
m_min (float, optional) – The minimum mass of halos to consider, defaults to None
m_max (float, optional) – The maximum mass of halos to consider, defaults to None
z_max (float, optional) – The maximum redshift to consider, defaults to None. If None, uses 5.0
- Returns:
A list of total mass values for each iteration.
- Return type:
list
- slsim.Halos.halos_plus_glass.skyarea_form_n(nside, deg2=True)[source]¶
This function calculates the sky area corresponding to each pixel when the sky is divided into 12 * nside ** 2 equal areas. 4*pi*(180/pi)^2=129600/pi deg^2; 4*pi*(180/pi)^2*(3600)^2=1679616000000/pi arcsec^2.
- Parameters:
nside (int) – The HEALPix resolution parameter. The total number of pixels is 12 * nside ** 2.
deg2 (bool, optional) – If True, the sky area is returned in square degrees. If False, the sky area is returned in square arcseconds. Defaults to True.
- Returns:
The sky area per pixel in either degree^2 or arcsecond^2, depending on the value of deg2.
- Return type:
float
- slsim.Halos.halos_plus_glass.worker_certain_redshift_lensext_kde(iter_num, sky_area, m_min, m_max, z_max, cosmo, samples_number, mass_sheet_correction, zs, zd, listmean, sigma_8, omega_m)[source]¶
Generates distributions of kappa_ext and gamma_ext for a given redshift and cosmology.
- Parameters:
iter_num (int) – Iteration number, used for multiprocessing.
sky_area (float) – Sky area over which halos are sampled.
m_min (float) – Minimum halo mass.
m_max (float) – Maximum halo mass.
z_max (float) – Maximum redshift value.
cosmo – Cosmology used for the calculations.
samples_number (int) – Number of samples to generate.
mass_sheet_correction (bool) – Flag to apply mass sheet correction.
zs (float) – Source redshift.
zd (float) – Lens redshift.
listmean (bool) – Flag to return the mean of the list.
sigma_8 (float) – Sigma_8 parameter for the cosmology.
omega_m (float) – Omega matter parameter for the cosmology.
- Returns:
Distributions of kappa_ext and gamma_ext.
- Return type:
np.ndarray
- slsim.Halos.halos_plus_glass.worker_certain_redshift_many(iter_num, sky_area, m_min, m_max, z_max, cosmo, samples_number, mass_sheet_correction, zs, zd)[source]¶
- Parameters:
iter_num (int) – The iteration number.
sky_area (float) – The area of the sky under consideration.
m_min (float) – The minimum mass of halos to consider.
m_max (float) – The maximum mass of halos to consider.
z_max (float) – The maximum redshift to consider.
cosmo (FlatLambdaCDM) – The cosmological model to use.
samples_number (int) – The number of samples to generate.
mass_sheet_correction (bool) – Flag to apply mass sheet correction.
zs (float) – The source redshift.
zd (float) – The lens redshift.
- Returns:
A tuple containing the distributions of parameters and the lens instance.
- Return type:
tuple
- slsim.Halos.halos_plus_glass.worker_kappaext_gammaext_kde(iter_num, sky_area, m_min, m_max, z_max, cosmo, samples_number, mass_sheet_correction, listmean, output_format)[source]¶
Worker function that generates kappa-gamma distributions for given parameters.
This function utilizes the HalosSkyPyPipeline to generate halos and, if necessary, mass sheet corrections. It then uses these halos (and corrections) to construct a HalosLens object and generate kappa-gamma distributions.
- Parameters:
iter_num (int) – The iteration number, mainly used for tracking in a parallel processing context.
sky_area (float) – The area of the sky under consideration (in steradians).
m_min (float) – The minimum mass for the simulation.
m_max (float) – The maximum mass for the simulation.
z_max (float) – The maximum redshift for the simulation.
cosmo (astropy.cosmology.FlatLambdaCDM) – The cosmology to be used.
samples_number (int) – The number of samples to be used.
mass_sheet_correction (bool) – If True, apply mass sheet correction.
output_format (str, optional) – The format in which the results should be returned, either as dict or vector. Defaults to dict.
listmean (bool) – If True, subtract the mean kappa value from the results.
- Returns:
A list of kappa and gamma values for the specified parameters.
- Return type:
list
This function is primarily intended to be used as a worker function in a parallel processing framework, where multiple instances of the function can be run simultaneously.
- slsim.Halos.halos_plus_glass.worker_run_average_mass_by_multiprocessing(iter_num, sky_area, m_min, m_max, z_max)[source]¶
Worker function for Calculate the average mass of halos for each redshift bin.
- Parameters:
iter_num (int) – The iteration number.
sky_area (float) – The sky area over which Halos are sampled.
m_min (float) – The minimum mass of the Halos to consider.
m_max (float) – The maximum mass of the Halos to consider.
z_max (float) – The maximum redshift of the Halos to consider.
- Returns:
The total mass of Halos for each redshift bin.
- Return type:
np.ndarray
- slsim.Halos.halos_plus_glass.worker_run_halos_without_kde(iter_num, sky_area, m_min, m_max, z_max, cosmo, samples_number, mass_sheet_correction, listmean, sigma_8, omega_m)[source]¶
- slsim.Halos.halos_plus_glass.worker_run_total_kappa_by_multiprocessing(iter_num, sky_area, diff, num_points, diff_method, m_min, m_max, z_max, cosmo)[source]¶
Computes the average kappa value for a given iteration, sky area, differential, number of points, differential method, minimum and maximum mass, maximum redshift, and cosmology.
- Parameters:
iter_num (int) – Iteration number.
sky_area (float) – Sky area over which Halos are sampled.
diff (float) – Differential to use in the computation.
num_points (int) – Number of points to use in the computation.
diff_method (str) – Method to use for the differential computation.
m_min (float) – Minimum halo mass.
m_max (float) – Maximum halo mass.
z_max (float) – Maximum redshift value in z_range.
cosmo (astropy.cosmology) – Cosmology model to use.
- Returns:
Average kappa value.
- Return type:
float
- slsim.Halos.halos_plus_glass.worker_run_total_mass_by_multiprocessing(iter_num, sky_area, m_min, m_max, z_max, cosmo)[source]¶
Calculate the total mass of halos for a given iteration, sky area, mass range, maximum redshift, and cosmology.
- Parameters:
iter_num (int) – Iteration number.
sky_area (~astropy.units.Quantity) – Sky area over which Halos are sampled. Must be in units of solid angle.
m_min (float) – Minimum halo mass.
m_max (float) – Maximum halo mass.
z_max (float) – Maximum redshift value in z_range.
cosmo (astropy.cosmology.FlatLambdaCDM) – Cosmology model to use.
- Returns:
Total mass of halos.
- Return type:
float
slsim.Halos.halos_ray_tracing module¶
- class slsim.Halos.halos_ray_tracing.HalosRayTracing(lens_kwargs, lens_model)[source]¶
Bases:
objectA class for performing ray tracing computations in gravitational lensing scenarios involving multiple halos.
This class provides methods to compute various lensing quantities such as convergence (kappa), shear (gamma), and their non-linear corrections across different redshifts and sky areas.
- Attributes:
ray_halo (list): A list to store halo-related data during computations. lens_kwargs (dict): Keyword arguments for the lens model that describe the lensing scenario. lens_model (LensModel): An instance of a lens model used for the ray tracing computations.
- Methods:
get_convergence_shear: Computes the convergence and shear at the origin due to all Halos. nonlinear_correction_kappa_gamma_values: Computes various kappa and gamma values for given deflector and source redshifts. get_kext_gext_values: Computes the external convergence and shear for given deflector and source redshifts. various_halos_data: Computes various convergence and shear values for given deflector and source redshifts. compute_kappa: Computes the convergence values over a grid and returns both the 2D kappa image and the 1D array of kappa values. plot_convergence: Plots the convergence across the lensed sky area.
- compute_kappa(sky_area, diff=1e-07, num_points=500, diff_method='square', kwargs=None, lens_model=None)[source]¶
Computes the convergence (kappa) values over a grid and returns both the 2D kappa image and the 1D array of kappa values.
- Parameters:
sky_area (float, optional) – Total sky area in steradians over which halos are distributed. Defaults to full sky (4π steradians).
diff (float, optional) – The differential used in the computation of the convergence. Defaults to 0.0000001.
num_points (int, optional) – The number of points along each axis of the grid. Defaults to 500.
diff_method (str, optional) – The method used to compute the differential. Defaults to “square”.
kwargs (dict, optional) – The keyword arguments for the lens model. If None, it will use the class method get_halos_lens_kwargs to generate them. Defaults to None.
lens_model (LensModel, optional) – The lens model to use. If None, it will use the class attribute param_lens_model. Defaults to None.
- Returns:
A tuple containing the 2D kappa image and the 1D array of kappa values.
- Return type:
tuple(numpy.ndarray, numpy.ndarray)
- get_convergence_shear(kwargs=None, lens_model=None, same_from_class=True, gamma12=False, diff=1.0, diff_method='square', zdzs=None)[source]¶
Computes the convergence and shear.
- Parameters:
gamma12 (bool, optional) – If True, returns gamma1 and gamma2 in addition to kappa. If False, returns total shear gamma along with kappa.
same_from_class (bool, optional) – If True and kwargs, lens_model is none uses the class’s lens model and lens kwargs. If False, uses the provided lens model and kwargs. Specify for the when the ‘None’ type kwargs
diff (float, optional) – The differential used in the computation of the Hessian matrix. Default is 1.0.
diff_method (str, optional) – The method used to compute the differential. Default is “square”.
kwargs (dict, optional) – Keyword arguments for the lens model. If None, uses the class method to generate them.
lens_model (LensModel, optional) – The lens model instance to use. If None, uses the class’s lens model.
zdzs (tuple, optional) – A tuple of deflector and source redshifts (zd, zs). If provided, uses hessian_z1z2 method of the lens model.
- Returns:
Depending on gamma12, either (kappa, gamma) or (kappa, gamma1, gamma2). Kappa is the convergence, gamma is the total shear, and gamma1 and gamma2 are the shear components.
- Return type:
tuple
- get_kext_gext_values(lens_data, zd, zs)[source]¶
Computes the external convergence (kappa_ext) and external shear (gamma_ext) for given deflector and source redshifts.
- Parameters:
lens_data (dict) – A dict containing lens data for three different conditions: 1. Between deflector and source redshift (ds). 2. From zero to deflector redshift (od). 3. From zero to source redshift (os).
zd (float) – The deflector redshift.
zs (float) – The source redshift.
- Returns:
A tuple containing the computed external convergence value (kext) and the computed external shear magnitude (gext).
- Return type:
(float, float)
Note
The function implements the following formula:
\[1 - \kappa_{\text{ext}} = \frac{(1-\kappa_{\text{od}})(1-\kappa_{\text{os}})}{1-\kappa_{\text{ds}}}\]and
\[\gamma_{\text{ext}} = \sqrt{(\gamma_{\text{od}1}+\gamma_{\text{os}1}-\gamma_{\text{ds}1})^2+(\gamma_{\text{od}2}+\gamma_{\text{os}2}-\gamma_{\text{ds}2})^2}\]
- nonlinear_correction_kappa_gamma_values(lens_data, zd, zs)[source]¶
Computes various kappa (convergence) and gamma (shear) values for given deflector and source redshifts.
This function retrieves the lens data based on the input redshifts and computes the convergence and shear for three categories: od, os, and ds. The gamma values are computed for both components, gamma1 and gamma2.
- Parameters:
lens_data (dict) – A tuple containing lens data for three different conditions: 1. Between deflector and source redshift (ds). 2. From zero to deflector redshift (od). 3. From zero to source redshift (os).
zd (float) – The deflector redshift.
zs (float) – The source redshift.
- Returns:
A tuple containing the convergence and shear values for od, os, and ds categories.
- Return type:
(float, float, float, float, float, float, float, float, float)
- plot_convergence(sky_area, diff=1e-07, num_points=500, diff_method='square', kwargs=None, lens_model=None)[source]¶
Plots the convegence (\(\kappa\)) across the lensed sky area.
- Parameters:
sky_area (float, optional) – Total sky area in steradians. Defaults to full sky (4π steradians).
diff (float, optional) – The differentiation value used for computing the hessian. Default is 1e-7.
num_points (int, optional) – Number of points along each axis for which convergence is computed. Default is 500.
diff_method (str, optional) – The method to use for differentiation when computing the hessian. Default is “square”.
kwargs (dict, optional) – Keyword arguments for the lens model. If not provided, the halos lens lens_kwargs of the instance are used.
lens_model (LensModel instance, optional) – The lens model to use. If not provided, the lens model from the class instance is utilized.
- Returns:
None. The function will display a plot of the computed convergence with plot.
- Return type:
None
Note
The function computes the convergence for a grid defined by num_points and plots the result using matplotlib. The computed sky area is determined by the instance’s sky area, converted from square degrees to arcseconds. Overlaying on the convergence plot are positions of halos represented by yellow x markers.
- various_halos_data(lens_data, zd, zs)[source]¶
Computes (kappa_od, kappa_os, gamma_od1, gamma_od2, gamma_os1, gamma_os2, kappa_ds, gamma_ds1, gamma_ds2, kappa_os2, gamma_os12, gamma_os22, kext, gext,), (kwargs_lens_os, lens_model_os) convergence (kappa) and shear (gamma) values for given deflector and source redshifts.
This function extracts the lens model and its keyword arguments for different redshift combinations (‘od`, os, and ds). It then computes the convergence and shear values for each of these combinations.
- Parameters:
lens_data (dict) – A dict tuple containing lens data for three different conditions: 1. Between deflector and source redshift (ds). 2. From zero to deflector redshift (od). 3. From zero to source redshift (os).
zd (float) – The deflector redshift.
zs (float) – The source redshift.
- Returns:
- A tuple containing:
A tuple of computed values for kappa and gamma for the different redshift combinations and the external convergence and shear.
A tuple containing the lens model and its keyword arguments for the os redshift combination.
- Return type:
tuple
Note
This function is utilized by the self.get_all_pars_distib() method. The mathematical formulations behind the calculations, especially for kext and gext, can be referenced from the documentation of get_kext_gext_values, is applied with the line of sight non-linear correction.
The function implements the following formulae for the external convergence and shear with LOS correction:
\[1 - \kappa_{\text{ext}} = \frac{(1-\kappa_{\text{od}})(1-\kappa_{\text{os}})}{1-\kappa_{\text{ds}}}\]and
\[\gamma_{\text{ext}} = \sqrt{(\gamma_{\text{od}1}+\gamma_{\text{os}1}-\gamma_{\text{ds}1})^2+(\gamma_{\text{od}2}+\gamma_{\text{os}2}-\gamma_{\text{ds}2})^2}\]
slsim.Halos.halos_statistics module¶
- class slsim.Halos.halos_statistics.HalosStatistics(halos_list, mass_correction_list=None, cosmo=None, sky_area=0.012566370614359173, samples_number=1000, mass_sheet=True, z_source=5)[source]¶
Bases:
HalosLensBaseA class for computing statistical distributions of lensing properties such as external convergence (kappa_ext) and external shear (gamma_ext) across multiple samples of halo configurations.
This class extends HalosLensBase to include statistical methods that allow for the computation of lensing effects over a range of redshifts and configurations, providing tools to analyze the statistical properties of lensing in cosmological simulations.
- Attributes:
samples_number (int): Number of samples for statistical calculations. halos_list (astropy.Table): Table containing details of halos, including their redshifts and masses. mass_correction_list (astropy.Table, optional): Table for mass correction, containing details like redshifts and external convergences. cosmo (astropy.Cosmology): Cosmology used for lensing computations. sky_area (float): Total sky area (in steradians) over which Halos are distributed. Defaults to full sky (4pi steradians). Optional. mass_sheet (bool): Flag to decide whether to use the mass_sheet correction.
- Methods:
get_kappaext_gammaext_distib_zdzs: Computes the distribution of external convergence and shear for given deflector and source redshifts. generate_distributions_0to5: Generates distributions of external convergence and shear for a range of deflector and source redshifts from 0 to 5. compute_various_k_g_lens_values: Computes various convergence and shear values for given deflector and source redshifts. get_all_pars_distib: Computes the distribution of various lensing parameters for given deflector and source redshifts. compute_kappa_in_bins: Computes the kappa values for each redshift bin for mass sheet correction. total_halo_mass: Calculates the total mass of all halos. total_critical_mass: Computes the total critical mass within a given sky area up to a redshift of 5. mass_divide_kcrit: Computes the external convergence by dividing the mass of each halo by the critical surface density. kappa_divergence: Calculates the divergence of kappa values across a specified sky area. compute_kappa_gamma: Compute the convergence and shear values for a given index, designed for use with multiprocessing. get_kappa_gamma_distib: Computes and returns the distribution of convergence and shear values using multiprocessing. get_kappa_gamma_distib_without_multiprocessing: Computes and returns the distribution of convergence and shear values without using multiprocessing.
- compute_kappa_gamma(i, gamma_tot, diff, diff_method)[source]¶
Compute the convergence and shear values for a given index.
This method is designed to be used with multiprocessing to speed up the process.
- Parameters:
i (int) – Index of the sample for which the computation will be done.
gamma_tot (bool) – If True, the function will return total shear gamma. If False, it will return gamma1 and gamma2.
diff (float) – Differential used in the computation of the Hessian matrix.
diff_method (str) – Method used to compute differential.
- Returns:
A list containing kappa and either gamma or gamma1 and gamma2, based on the value of gamma_tot.
- Return type:
list
Note
This function is designed to work in conjunction with get_kappa_gamma_distib which uses multiprocessing to compute the kappa and gamma values for multiple samples in parallel.
- compute_kappa_in_bins()[source]¶
For computing a mass sheet correction. Computes the kappa values for each redshift bin.
- Returns:
A list of kappa values for each redshift bin.
- Return type:
list[float]
- compute_various_k_g_lens_values(zd, zs)[source]¶
Computes various convergence (kappa) and shear (gamma) values for given deflector and source redshifts and the lens kwargs and lens model.
This function extracts the lens model and its keyword arguments for different redshift combinations (‘od`, os, and ds). It then computes the convergence and shear values for each of these combinations.
- Parameters:
zd (float) – The deflector redshift.
zs (float) – The source redshift.
- Returns:
- A tuple containing:
A tuple of computed values for kappa and gamma for the different redshift combinations and the external convergence and shear.
A tuple containing the lens model and its keyword arguments for the os redshift combination.
- Return type:
tuple
Note
This function is utilized by the self.get_all_pars_distib() method. The mathematical formulations behind the calculations, especially for kext and gext, can be referenced from the documentation of get_kext_gext_values, is applied with the line of sight non-linear correction.
The function implements the following formulae for the external convergence and shear with LOS correction:
\[1 - \kappa_{\text{ext}} = \frac{(1-\kappa_{\text{od}})(1-\kappa_{\text{os}})}{1-\kappa_{\text{ds}}}\]and
\[\gamma_{\text{ext}} = \sqrt{(\gamma_{\text{od}1}+\gamma_{\text{os}1}-\gamma_{\text{ds}1})^2+(\gamma_{\text{od}2}+\gamma_{\text{os}2}-\gamma_{\text{ds}2})^2}\]
- generate_distributions_0to5(output_format='dict', listmean=False)[source]¶
Generates distributions of external convergence (kappa_ext) and external shear (gamma_ext) for a range of deflector and source redshifts from 0 to 5.
- Parameters:
listmean (bool) – the boolean if average convergence (kappa) to 0
output_format (str, optional) – The format of the output data. Options are dict - A list of dictionaries, vector - A list of vectors [zd, zs, kappa, gamma]. Default is dict.
- Returns:
If output_format=’dict`, a list of dictionaries. Each dictionary contains: zd (float) - The deflector redshift, zs (float) - The source redshift, kappa (float) - The computed external convergence value for the given zd and zs, gamma (float) - The computed external shear magnitude for the given zd and zs. If output_format=’vector`, a list of vectors with elements [zd, zs, kappa, gamma].
- Return type:
list
Note
The function iterates through possible values of zs from 0 to 5 in steps of 0.1. For each zs, it considers zd values from 0 to zs-0.1 in steps of 0.1. For each zd, zs pair, it computes the kappa_ext and gamma_ext distributions and appends them to the result list.
- get_all_pars_distib(zd, zs)[source]¶
Computes the distribution of external convergence (kappa_ext) and external shear (gamma_ext) for given deflector and source redshifts.
- Parameters:
zd (float) – The deflector redshift.
zs (float) – The source redshift.
- Returns:
An array of shape (samples_number, 2) containing the computed kappa_ext and gamma_ext values for the given deflector and source redshifts. Each row corresponds to a sample, with the first column being kappa_ext and the second column being gamma_ext.
- Return type:
numpy.ndarray
Note
The total elapsed time for computing weak-lensing maps is printed at the end.
- get_kappa_gamma_distib(gamma_tot=False, diff=1.0, diff_method='square', listmean=False)[source]¶
Computes and returns the distribution of convergence and shear values.
This method uses multiprocessing to compute the convergence and shear values for multiple samples in parallel.
- Parameters:
listmean (bool) – The boolean if average convergence (kappa) to 0.
gamma_tot (bool, optional) – If True, the function will return total shear gamma values. If False, it will return gamma1 and gamma2 values. Default is False.
diff (float, optional) – Differential used in the computation of the Hessian matrix. Default is 0.0001.
diff_method (str, optional) – Method used to compute differential. Default is square.
- Returns:
A 2D array containing kappa and either gamma or gamma1 and gamma2 for each sample, based on the value of gamma_tot.
- Return type:
numpy.ndarray
Note
The method uses the compute_kappa_gamma static method to compute the values for each sample. If the number of samples exceeds 2000, a print statement will indicate the elapsed time for computation.
- get_kappa_gamma_distib_without_multiprocessing(gamma_tot=False, diff=1.0, diff_method='square', listmean=False)[source]¶
Runs the method get_convergence_shear() a specific number of times and stores the results for kappa, gamma1, and gamma2 in separate lists.
- Parameters:
listmean (bool) – the boolean if average convergence (kappa) to 0
diff_method (str, optional) – The method to compute differential. Default is square.
diff (float, optional) – Differential used in the computation of the Hessian matrix. Default is 1.0.
gamma_tot (bool, optional) – If True, the function will return gamma values in place of gamma1 and gamma2 values. Default is False.
- Returns:
If gamma_tot is False, the returned list contains three lists with kappa, gamma1, and gamma2 values for each sample, respectively. If gamma_tot is True, the returned list contains two lists with kappa and gamma values for each sample, respectively.
- Return type:
list of lists
- Notes:
This function assumes the method get_convergence_shear() is implemented, and it returns a 4-tuple: (kappa, gamma1, gamma2, gamma). If gamma_tot parameter is False, gamma1 and gamma2 are stored, otherwise gamma is stored. All returned values from get_convergence_shear() are assumed to be floats.
- get_kappaext_gammaext_distib_zdzs(zd, zs, listmean=False)[source]¶
Computes the distribution of external convergence (kappa_ext) and external shear (gamma_ext) for given deflector and source redshifts.
- Parameters:
zd (float) – The deflector redshift.
zs (float) – The source redshift.
listmean (bool) – the boolean if average convergence (kappa) to 0
- Returns:
An array of shape (samples_number, 2) containing the computed kappa_ext and gamma_ext values for the given deflector and source redshifts. Each row corresponds to a sample, with the first column being kappa_ext and the second column being gamma_ext.
- Return type:
numpy.ndarray
Note
The total elapsed time for computing weak-lensing maps is printed at the end.
- kappa_divergence(diff=1e-07, num_points=500, diff_method='square', kwargs=None, lens_model=None, mass_sheet=None)[source]¶
Calculates the divergence of kappa values across a specified sky area.
- Parameters:
diff (float, optional) – The differential used in the computation of kappa. Defaults to 0.0000001.
num_points (int, optional) – The number of points along each axis in the grid used for calculations. Defaults to 500.
diff_method (str, optional) – The method used to compute the differential. Defaults to “square”.
kwargs (dict, optional) – Keyword arguments for the lens model. If None, the method will use get_halos_lens_kwargs to generate them. Defaults to None.
lens_model (LensModel, optional) – The lens model to use for calculations. If None, the method will use the class’s lens model. Defaults to None.
mass_sheet (bool, optional) – Specifies whether to use the mass sheet correction. If not None, it will update the class’s mass_sheet attribute. Defaults to None.
- Returns:
The calculated two-sigma divergence of kappa values.
- Return type:
float
- mass_divide_kcrit()[source]¶
Computes the external convergence (kappa_ext) by dividing the mass of each halo by the critical surface density and the physical area corresponding to the cone opening angle at each halo’s redshift.
- Returns:
An array of kappa_ext values for each halo.
- Return type:
numpy.ndarray
- total_critical_mass(method='differential_comoving_volume')[source]¶
Computes the total critical mass within a given sky area up to a redshift of 5 using either the total comoving volume or differential comoving volume method.
The function computes the critical mass using either the comoving_volume method or the differential_comoving_volume method.
- Parameters:
method (str, optional) – The method to use for computing the critical mass. Options are: - comoving_volume: Computes the total critical mass using the comoving volume method. - differential_comoving_volume: Computes the total critical mass using the differential comoving volume method. Default is differential_comoving_volume.
- Returns:
The computed total critical mass up to redshift 5.
- Return type:
float
slsim.Halos.halos_util module¶
- slsim.Halos.halos_util.convergence_mean_0(kappa_data)[source]¶
Adjusts the input kappa data by subtracting the mean of non-zero elements from the non-zero values only (above a small threshold to handle floating-point precision). Keeps zeros as is. Returns the adjusted data in the same format (list or numpy array) as the input.
- Parameters:
kappa_data (list or numpy.ndarray) – The input kappa data to be adjusted.
- Returns:
The adjusted kappa data in the same format as the input.
- Return type:
list or numpy.ndarray
slsim.Halos.halos module¶
- slsim.Halos.halos.colossus_halo_expected_mass_sampler(m_min, m_max, resolution, z, cosmology, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Sample the average halo masses from a mass function within defined mass boundaries. (what the average mass of certain halo if it exists in redshift z)
Utilizes the Colossus library to compute a halo mass function, from which halo masses are sampled. The function calculates the mass function across a specified mass range and redshift, using given cosmological parameters and, optionally, values for sigma8 and ns for power spectrum normalization and spectral index, respectively.
- Parameters:
m_min (Quantity or float) – Minimum halo mass, in M_sol/h. Converted to value if specified as an astropy Quantity.
m_max (Quantity or float) – Maximum halo mass, in M_sol/h. Converted to value if specified as an astropy Quantity.
resolution (Quantity or int) – Number of mass bins for the mass function calculation, converted to value if specified as an astropy Quantity.
z (float) – Redshift for halo mass function computation.
cosmology (astropy.Cosmology instance) – Cosmology instance for calculating the halo mass function.
sigma8 (float, optional) – Sigma8 parameter, default is 0.81.
ns (float, optional) – Spectral index in Colossus cosmology settings, default is 0.96.
omega_m (float) – Omega_m in Cosmology, defaults to none which will lead to the same in Cosmology setting.
- Returns:
Sampled halo masses in M_sol, the number of samples is determined by the size parameter. Returns a single float if size is None.
- Return type:
ndarray or float
- Note:
The Colossus library’s bhattacharya11 model is used for the mass function. Cosmology parameters from the provided instance are temporarily applied to Colossus as “halo_cosmo”.
- slsim.Halos.halos.colossus_halo_expected_number(zmax, sky_area, m_min=None, m_max=None, resolution=None, cosmology=None, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Calculate the first moment of mass at given redshift(s) using specified or default cosmological parameters and mass range.
This function computes the first moment of mass within a given sky area and redshift range by integrating the halo mass function weighted by mass over the specified mass range. :param zmax: maximum-redshift :type zmax: float :param sky_area: Area of the sky in square degrees under consideration for the calculation. :type sky_area: ~astropy.units.Quantity :param m_min: Minimum halo mass, in M_sol/h. Converted to value if specified as an astropy Quantity. :param m_max: Maximum halo mass, in M_sol/h. Converted to value if specified as an astropy Quantity. :param resolution: Number of mass bins for the mass function calculation, converted to value if specified as an astropy Quantity. :param cosmology: Cosmology instance for calculating the halo mass function. :param sigma8: Sigma8 parameter, default is 0.81. :param ns: Spectral index in Colossus cosmology settings, default is 0.96. :param omega_m: Omega_m in Cosmology, defaults to none which will lead to the same in Cosmology setting. :type m_min: Quantity or float :type m_max: Quantity or float :type resolution: Quantity or int :type cosmology: astropy.Cosmology instance :type sigma8: float, optional :type ns: float, optional :type omega_m: float:return: first moment of number of halo in the bin :rtype: float
- slsim.Halos.halos.colossus_halo_expected_number_certain_bin(z_c, dz, sky_area, m_min=None, m_max=None, resolution=None, cosmology=None, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Calculate the first moment of mass at given redshift(s) using specified or default cosmological parameters and mass range.
This function computes the first moment of mass within a given sky area and redshift range by integrating the halo mass function weighted by mass over the specified mass range. :param z_c: center redshift for the bin :type z_c: float :param dz: redshift bin width :type dz: float :param sky_area: Area of the sky in square degrees under consideration for the calculation. :type sky_area: ~astropy.units.Quantity :param m_min: Minimum halo mass, in M_sol/h. Converted to value if specified as an astropy Quantity. :param m_max: Maximum halo mass, in M_sol/h. Converted to value if specified as an astropy Quantity. :param resolution: Number of mass bins for the mass function calculation, converted to value if specified as an astropy Quantity. :param cosmology: Cosmology instance for calculating the halo mass function. :param sigma8: Sigma8 parameter, default is 0.81. :param ns: Spectral index in Colossus cosmology settings, default is 0.96. :param omega_m: Omega_m in Cosmology, defaults to none which will lead to the same in Cosmology setting. :type m_min: Quantity or float :type m_max: Quantity or float :type resolution: Quantity or int :type cosmology: astropy.Cosmology instance :type sigma8: float, optional :type ns: float, optional :type omega_m: float:return: first moment of number of halo in the bin :rtype: float
- slsim.Halos.halos.colossus_halo_mass_function(m_200, cosmo, z, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Calculate the differential halo mass function per logarithmic mass interval at a given redshift.
This function leverages the Colossus library to determine the halo mass function based on a mass scale (m_200), a cosmological model (cosmo), and a redshift (z). The mass function, expressed as dn/dlnM, represents the number density of halos per log mass interval. Parameters sigma8 and ns can be specified to adjust the calculation.
- Parameters:
m_200 (ndarray) – Halo mass range, in solar mass units divided by the Hubble parameter (M_sun/h), shown as an array. For example, can be set as m_200 = np.geomspace(minh, maxh, resolution_value)
cosmo (astropy.Cosmology instance) – astropy.cosmology instance detailing the cosmological parameters.
z (float) – Redshift for evaluating the mass function.
sigma8 (float, optional) – Matter density fluctuations on a (8 h-1 Mpc), defaults to 0.81 if not specified.
ns (float, optional) – Spectral index, defaults to 0.96 if not specified.
omega_m (float, optional) – Omega_m in Cosmology, defaults to none which will lead to the same in Cosmology setting.
- Returns:
The differential halo mass function dn/dlnM, in units of Mpc^-3.
- Return type:
ndarray
- Note:
The bhattacharya11 model within the Colossus framework is used for the mass function.
- slsim.Halos.halos.colossus_halo_mass_sampler(m_min, m_max, resolution, z, cosmology, sigma8=0.81, ns=0.96, size=None, omega_m=None)[source]¶
Sample halo masses from a mass function within defined mass boundaries.
Utilizes the Colossus library to compute a halo mass function, from which halo masses are sampled. The function calculates the mass function across a specified mass range and redshift, using given cosmological parameters and, optionally, values for sigma8 and ns for power spectrum normalization and spectral index, respectively.
- Parameters:
m_min (Quantity or float) – Minimum halo mass, in M_sol/h. Converted to value if specified as an astropy Quantity.
m_max (Quantity or float) – Maximum halo mass, in M_sol/h. Converted to value if specified as an astropy Quantity.
resolution (Quantity or int) – Number of mass bins for the mass function calculation, converted to value if specified as an astropy Quantity.
z (float) – Redshift for halo mass function computation.
cosmology (astropy.Cosmology instance) – Cosmology instance for calculating the halo mass function.
sigma8 (float, optional) – Sigma8 parameter, default is 0.81.
ns (float, optional) – Spectral index in Colossus cosmology settings, default is 0.96.
size (int or None, optional) – Number of random samples to draw. Returns a single value if None.
omega_m (float) – Omega_m in Cosmology, defaults to none which will lead to the same in Cosmology setting.
- Returns:
Sampled halo masses in M_sol, the number of samples is determined by the size parameter. Returns a single float if size is None.
- Return type:
ndarray or float
- Note:
The Colossus library’s bhattacharya11 model is used for the mass function. Cosmology parameters from the provided instance are temporarily applied to Colossus as “halo_cosmo”.
- slsim.Halos.halos.dndz_to_N(dN_dz, redshift_list)[source]¶
Convert redshift distribution to total number of objects using Poisson statistics.
This function transforms a differential redshift distribution dN/dz into an estimate of the total number of objects N. It applies Poisson statistics to model the inherent stochastic nature of astronomical object distributions, using the integral of dN/dz over the redshift range to set the mean of the Poisson distribution.
- Parameters:
dN_dz (ndarray,) – Differential number of objects per redshift interval, serving as the rate of object occurrence as a function of redshift.
redshift_list (ndarray,) – Array of redshifts corresponding to the dN_dz values, outlining the span over which the distribution is defined.
- Returns:
The total number of objects expected within the given redshift distribution, determined by drawing from a Poisson distribution with the mean calculated from the integral of dN/dz.
- Return type:
int
- slsim.Halos.halos.dndz_to_redshifts(N, dN_dz, redshift_list)[source]¶
Generate a cumulative distribution function (CDF) of redshifts using the trapezoidal rule.
This function employs the cumulative trapezoidal rule to integrate a differential number distribution of objects dN/dz over redshift, producing a redshift cumulative distribution function (CDF). This CDF is then used to sample N redshifts, providing a statistical basis for modeling distributions of astronomical objects over redshift.
- Parameters:
N (int) – The number of redshifts to sample from the cumulative distribution, representing the size of the resultant redshift array.
dN_dz (ndarray,) – Differential number of objects per redshift interval, indicating the rate at which the number of objects changes with redshift.
redshift_list (ndarray,) – Array of redshifts corresponding to the dN_dz values, delineating the domain over which the distribution applies.
- Returns:
An array of N redshifts sampled according to the cumulative distribution derived from the differential redshift distribution dN/dz.
- Return type:
ndarray
- slsim.Halos.halos.dv_dz_to_dn_dz(dV_dz, redshift_list, m_min=None, m_max=None, resolution=None, cosmology=None, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Convert differential comoving volume element to differential number density per redshift interval.
This function transitions from the concept of a comoving volume element to the actual number density of objects within that volume per unit redshift. It achieves this by taking the differential comoving volume element dV/dz and multiplying it by the number density of objects within a comoving volume at each redshift point.
- Parameters:
dV_dz (ndarray) – Differential comoving volume element as a function of redshift, detailing how volume changes with redshift.
redshift_list (ndarray) – Array of redshifts corresponding to the dV_dz values, serving as the domain over which the function is defined.
m_min (float, optional) – Minimum mass threshold for halos included in the number density calculation, in solar masses (M_sol). This parameter is optional, with a default setting if not provided.
m_max (float, optional) – Maximum mass threshold for halos considered in the number density estimation, in solar masses (M_sol). This parameter is optional, with a default setting if not provided.
resolution (int, optional) – The granularity of the grid used in the underlying mass function calculation, with a higher resolution offering more detailed insights. This parameter is optional, with a default value if omitted.
cosmology (astropy.Cosmology instance, optional) – The astropy.cosmology model applied to the calculation, influencing the interpretation of redshifts and distances. This parameter is optional, with a default cosmology assumed if not specified.
sigma8 (float, optional) – Normalization parameter for the power spectrum, influencing the amplitude of mass density fluctuations. This parameter is optional, with a default value if not specified.
ns (float, optional) – The spectral index defining the tilt of the primordial power spectrum, a key parameter in cosmological models. This parameter is optional, with a default value if not specified.
omega_m (float, optional) – The matter density parameter of the universe, critical for understanding the evolution of structure. This parameter is optional and will default to the cosmology’s value if not provided.
- Returns:
An array representing the differential number density dn/dz, which quantifies the expected number of objects per redshift interval in a unit comoving volume.
- Return type:
ndarray
- Note:
While the halo mass range and cosmological parameters are optional, specifying them enhances the accuracy and relevance of the calculated number density.
- slsim.Halos.halos.expected_mass_at_redshift(z, sky_area, m_min=None, m_max=None, resolution=None, cosmology=None, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Calculate the first moment of mass at given redshift(s) using specified or default cosmological parameters and mass range.
This function computes the first moment of mass within a given sky area and redshift range by integrating the halo mass function weighted by mass over the specified mass range.
- Parameters:
z (float or iterable) – Redshift(s) at which to calculate the first moment of mass. Can be a single value or an iterable of values.
sky_area (~astropy.units.Quantity) – Area of the sky in square degrees under consideration for the calculation.
m_min (float, optional) – Minimum halo mass in solar masses for the integration range. Defaults to a predetermined value if not specified.
m_max (float, optional) – Maximum halo mass in solar masses for the integration range. Defaults to a predetermined value if not specified.
resolution (int, optional) – Resolution of the computational grid for the mass integration. Defaults to a predetermined value if not specified.
cosmology (astropy.cosmology instance, optional) – astropy.cosmology instance to be used in calculations. Defaults to a predetermined cosmology if not specified.
sigma8 (float, optional) – Sigma8. Defaults to 0.81 if not specified.
ns (float, optional) – Spectral index for the power spectrum. Defaults to 0.96 if not specified.
omega_m (float, optional) – Matter density parameter Omega_m. If not specified, the value from the cosmology instance is used.
- Returns:
List of first moments of mass for each provided redshift. Each element corresponds to the first moment of mass at the respective redshift in the input.
- Return type:
list
- slsim.Halos.halos.halo_mass_at_z(z, m_min=None, m_max=None, resolution=None, cosmology=None, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Sample halo masses at given redshift(s) using specified or default cosmological parameters and mass range.
- Parameters:
z (float or iterable) – Redshift(s) at which to sample halo masses. Can be a single value or an iterable of values.
m_min (float, optional) – Minimum halo mass in solar masses. Defaults to a predetermined value if not specified.
m_max (float, optional) – Maximum halo mass in solar masses. Defaults to a predetermined value if not specified.
resolution (int, optional) – Resolution of the computational grid. Defaults to a predetermined value if not specified.
cosmology (astropy.cosmology instance, optional) – astropy.cosmology instance to be used in calculations. Defaults to a predetermined cosmology if not specified.
sigma8 (float, optional) – Sigma8 parameter for the power spectrum normalization. Defaults to 0.81 if not specified.
ns (float, optional) – Spectral index for the power spectrum. Defaults to 0.96 if not specified.
omega_m (float, optional) – Matter density parameter Omega_m. If not specified, the value from the cosmology instance is used.
- Returns:
List of sampled halo masses for each provided redshift. Each element corresponds to the mass sampled at the respective redshift in the input.
- Return type:
list
- slsim.Halos.halos.kappa_ext_for_each_sheet(redshift_list, first_moment, sky_area, cosmology, z_sigma_crit_source=10.0)[source]¶
Calculate the external convergence (kappa_ext) for lensing sheets at given redshifts.
The function computes kappa_ext using the first moment of mass, the area under consideration, and the critical surface mass density.
- Parameters:
redshift_list (list or ndarray) – Redshifts of the lens planes for which kappa_ext is calculated.
first_moment (list or ndarray) – First moment (expected value) of mass for each redshift in the redshift_list.
sky_area (~astropy.units.Quantity) – Area of the sky in square degrees under consideration for the lensing calculation.
cosmology (astropy.cosmology instance) – astropy.Cosmology instance used for the calculation.
z_sigma_crit_source (float, optional) – Redshift of the source plane for the critical surface mass density calculation.
- Returns:
Array of kappa_ext values for each redshift in the redshift_list.
- Return type:
ndarray
- slsim.Halos.halos.number_density_at_redshift(z, m_min=None, m_max=None, resolution=None, cosmology=None, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Compute the number density of halos at various redshifts within a specific mass range.
This function integrates the halo mass function over a given mass range to find the number density of halos per unit comoving volume at different redshifts. It’s useful for understanding the distribution and evolution of halos across cosmic time.
- Parameters:
z (float or ndarray) – Redshift(s) at which to compute the number density, can be a single value or an array.
m_min (float, optional) – Minimum halo mass included in the density calculation, in solar masses (M_sol). Optional, with a default value if not provided.
m_max (float, optional) – Maximum halo mass for the density calculation, in solar masses (M_sol). Optional, with a default value if not provided.
resolution (int, optional) – Number of mass bins for integrating the mass function. Optional, defaults to a predetermined value.
cosmology (astropy.Cosmology instance, optional) – astropy.cosmology instance for the underlying cosmological model. Optional, defaults to a standard model if not provided.
sigma8 (float, optional) – Normalization of the power spectrum, optional, with a default value if not specified.
ns (float, optional) – Spectral index for the power spectrum, optional, with a default value if not specified.
omega_m (float, optional) – Matter density parameter, optional, will use the cosmology setting if not specified.
- Returns:
Number density of halos at each specified redshift, as a list (for scalar z) or ndarray (for array z).
- Return type:
list or ndarray :note: A warning is issued for NaN values in input redshifts, with a fallback to a default redshift of 0.0001.
- slsim.Halos.halos.number_density_for_massf(massf, m, dndlnM=False)[source]¶
Calculate the total number density of halos per cubic megaparsec (Mpc^3) at a certain redshift.
This function integrates the mass function (massf) over a given mass range (m) to compute the total number density of halos. It can operate in two modes depending on the dndlnM flag: when dndlnM is True, it assumes massf represents the differential number density dN/dlnM; otherwise, it treats massf as the differential number density dN/dM.
- Parameters:
massf (ndarray) – The halo mass function, representing either dN/dM or dN/dlnM, depending on the value of dndlnM. Units are Mpc^-3 Msun^-1.
m (ndarray) – Array of halo masses (M_sun) over which to integrate the mass function. Must be the same length as massf.
dndlnM (bool, optional) – Flag indicating whether massf is given as dN/dlnM (True) or dN/dM (False). Optional, defaults to False.
- Returns:
The total number density of halos per cubic megaparsec (Mpc^3) at the specified redshift.
- Return type:
float
- slsim.Halos.halos.optimize_min_mass_based_on_number(target_n_halos, zmax, sky_area, m_max=None, resolution=None, cosmology=None, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Calculate the excepted minimum mass based on the target number of halos.
- Parameters:
zmax (float) – maximum-redshift
target_n_halos (float) – target number of halos
sky_area (~astropy.units.Quantity) – Area of the sky in square degrees under consideration for the calculation.
m_max – Maximum halo mass, in M_sol/h. Converted to value if specified as an astropy Quantity.
resolution (Quantity or int) – Number of mass bins for the mass function calculation, converted to value if specified as an astropy Quantity.
cosmology (astropy.Cosmology instance) – Cosmology instance for calculating the halo mass function.
sigma8 (float, optional) – Sigma8 parameter, default is 0.81.
ns (float, optional) – Spectral index in Colossus cosmology settings, default is 0.96.
omega_m (float:return: first moment of number of halo in the bin) – Omega_m in Cosmology, defaults to none which will lead to the same in Cosmology setting.
- Return type:
float
- slsim.Halos.halos.redshift_halos_array_from_comoving_density(redshift_list, sky_area, cosmology=None, m_min=None, m_max=None, resolution=None, sigma8=0.81, ns=0.96, omega_m=None)[source]¶
Generate an array of halo redshifts based on a given comoving density.
This function predicts halo redshifts by considering the expected number of halos at different redshifts, calculated from the differential comoving volume and halo number density. It applies a Poisson distribution to these expectations to simulate the actual distribution of halos.
- Parameters:
redshift_list (array_like/ np.ndarray) – List of redshifts for which to calculate halo distributions.
sky_area (~astropy.units.Quantity) – Sky area under consideration, specified in square degrees.
cosmology (astropy.cosmology.Cosmology instance, optional) – Optional cosmology instance for the calculations. Defaults to a standard model if not provided.
m_min (float, optional) – Minimum halo mass for consideration in the calculation, in solar masses (M_sol). Optional.
m_max (float, optional) – Maximum halo mass for the calculation, in solar masses (M_sol). Optional.
resolution (int, optional) – Resolution of the mass grid for the calculations. Optional.
sigma8 (float) – Sigma 8 for cosmology, default is 0.81.
ns (float) – The spectral index defining the tilt of the primordial power spectrum, default is 0.96.
omega_m (float, optional) – The matter density parameter of the universe, optional.
- Returns:
Array of halo redshifts based on the calculated distributions.
- Return type:
array
- slsim.Halos.halos.redshift_mass_sheet_correction_array_from_comoving_density(redshift_list)[source]¶
Create an array of redshifts for mass sheet correction calculations.
This utility function generates a sequence of redshift values beginning at 0.025 and incrementing by 0.05, extending up to the maximum redshift found in the input redshift_list. The generated redshift array is particularly useful for computations related to mass sheet corrections in lensing studies, where discrete redshift values are needed across a specified range.
- Parameters:
redshift_list (ndarray:return: An array of redshift values starting from 0.025 and increasing in steps of 0.05, terminating at or just below the maximum value found in redshift_list. This structured approach ensures a consistent set of redshifts for subsequent analytical steps.) – Array of observed redshifts, the maximum of which determines the upper limit for the generated redshift sequence. This list provides the context or observational range within which the mass sheet correction calculations are relevant.
- Return type:
ndarray
- slsim.Halos.halos.set_defaults_halos(m_min=None, m_max=None, resolution=None, cosmology=None)[source]¶
Set default values for parameters if not explicitly provided.
Ensure all parameters have values, setting defaults for any that are unspecified. This utility function aids in initializing simulation or calculation setups where certain parameters might not be critical and can assume default values.
- Parameters:
m_min (float, optional) – The minimum halo mass, in solar mass units (M_sol). Defaults to a predetermined value if not specified.
m_max (float, optional) – The maximum halo mass, in solar mass units (M_sol). Defaults to a predetermined value if not specified.
resolution (int, optional) – Resolution of the computational grid. Assigned a default value if omitted.
cosmology (astropy.cosmology instance, optional) – Cosmology model instance to be used in calculations. If not provided, a default cosmology is used.
- Returns:
A tuple containing the parameters, with defaults applied where necessary.
- Return type:
tuple
- slsim.Halos.halos.v_per_redshift(redshift_list, cosmology, sky_area)[source]¶
Calculate comoving volume per unit redshift.
This function computes the comoving volume associated with each redshift in a given list of redshifts. The calculation considers the cosmological model specified and the area of the sky under consideration. This is crucial for understanding the volume over which astronomical surveys operate at different depths (redshifts).
- Parameters:
redshift_list (array_like) – Array of redshifts for which to calculate the corresponding comoving volumes, representing the depth of an astronomical survey or observation.
cosmology (astropy.Cosmology instance, optional) – The astropy.cosmology model to apply, which defines the universe’s geometry and expansion history, influencing the calculation of comoving volumes. This parameter is optional, with a default cosmology used if not specified.
sky_area (~astropy.units.Quantity) – The area of the sky over which the volume calculations are to be applied, expressed in square degrees or as a solid angle, framing the scope of the astronomical observation or survey.
- Returns:
An array detailing the comoving volume corresponding to each redshift in the input list, providing a spatial context for the distribution of astronomical objects.
- Return type:
array