profiley.helpers.lss
Helpers for Large-Scale Structure calculations
Module Contents
Functions
|
Load profiles created by |
|
Calculate the correlation function using the Hankel |
|
Save 2d grid of profiles into file |
|
Calculate the surface density from the correlation function |
|
Auxiliary function to calculate the surface density from |
- profiley.helpers.lss.load_profiles(filename, x=None, precision=2, force_match_all=True)
Load profiles created by
save_profilesParameters
- filenamestr
name of the file to be read. To ensure consistency, this file should have been created with
save_profiles; this is assumed but not checked- xiterable, optional
quantities for which the profiles are needed. Each dimension must correspond to the columns storing the variables in the file (e.g., z and logm). Each column in
xmust be a unique array.- precisionint or list of 2 ints, optional
number of decimal places with which to match
xto the columns read from the file.- force_match_allbool, optional
whether if
x is defined, all values of x must be present in the file, otherwise aValueErroris raised.
Returns
- profilesndarray, shape (M,N,P)
grid of profiles
- Rndarray, shape (P,)
radii at which the profiles were calculated
- x1, x2ndarray, shapes (M,) and (N,), respectively
coordinates over which the grid of profiles was calculated
- infotuple, len 5
- contains the following information:
-name of the profile -radial units -name of x1 -name of x2 -dictionary of cosmological parameters, or None
Raises
ValueError: if
xis not composed of unique arraysNotes
It is assumed but not check that the radial coordinates make sense. In particular, if any value in the radial coordinate is equal to -1, this function will raise an exception.
- profiley.helpers.lss.power2xi(lnPgm_lnk, R)
Calculate the correlation function using the Hankel transform of the power spectrum
Taken from the KiDS-GGL pipeline, credit Andrej Dvornik.
- Reference:
H. Ogata, A Numerical Integration Formula Based on the Bessel Functions, Publ. Res. Inst. Math. Sci. 41 (2005), 949-970. doi: 10.2977/prims/1145474602
Parameters
- lnPgm_lnkscipy.interpolate.interp1d object (or equivalent)
function to calculate the natural log of the power spectrum given the natural log of the wavenumber
- profiley.helpers.lss.save_profiles(file, x, y, R, profiles, xlabel='z', ylabel='logm', label='profile', R_units='Mpc', cosmo_params=None, verbose=True)
Save 2d grid of profiles into file
Parameters
- filestr
output file name
- x, yndarray, shapes (M,) and (N,)
variables over which the profiles have been calculated. Typically mass and redshift
- Rndarray, shape (P,)
radial coordinates
- profilesndarray, shape (M,N,P)
profiles to be saved
- xlabel, ylabelstr, optional
names of the x and y coordinates
- labelstr, optional
name of the profile being stored. Default ‘profile’.
- R_unitsstr, optional
units of the radial coordinates, annotated in the comments
- cosmodict, optional
cosmological parameters used to calculate the profiles, annotated as a comment
- verbosebool, optional
verbosity. If
Truewill only print the filename when finished.
-The first row contains to -1 entries in the first two columns, which are there only to make the contents of a file rectangular, and are ignored. Elements from the third on correspond to the radial coordinates. -Starting from the second row, the first two columns contain all combinations of the arrays x and y, and columns from the third on contain the profile for each combination. -The comments contain the units of the radial coordinates as well as the cosmological parameters used in the calculations. If cosmological parameters are not provided, the line says “# No cosmology provided”.
- profiley.helpers.lss.xi2sigma(R, r_xi, xi, rho_m, threads=1, full_output=False, verbose=2)
Calculate the surface density from the correlation function
Parameters
- Rnp.ndarray, shape ([M,[P,]]N)
projected distances at which to calculate the surface density, in Mpc. Can have up to two additional dimensions (typically mass and redshift)
- r_xinp.ndarray, shape ([M,P,]Q)
radii at which the correlation function has been calculated. Can have up to two additional dimensions (say, mass and redshift)
- xinp.ndarray, shape ([M,P,]Q)
correlation function, calculated at radii r_xi. Can have up to two additional dimensions (say, mass and redshift). Note that it is assumed that at least one of these additional dimensions is indeed present
- rho_mfloat
average comoving matter density
- threadsint, optional
number of threads to calculate the surface densities in parallel
- full_outputbool, optional
whether to return the radial coordinates as well as the surface density (default False)
- full_outputbool, optional
if
True, return the radii as well as the surface density, both with the same shapes- verbose{0,1,2}
verbosity. 0 is quiet, 2 is full verbose
Returns
- sigmanp.ndarray, shape ([M,[P,]]N)
surface density calculated at projected radii R
- Rsigmanp.ndarray, shape ([M,[P,]]N)
radial coordinate reshaped to have the same shape as
sigma. Returned only iffull_output==True
Notes
This function can take a long time to run, depending on the number of surface densities to be calculated. Be sure to store the results in a file.
In order to make it run faster, everything will be passed to a single pool (if threads>1); if you would like to keep track of progress it is advised to call this function for pieces of your data and do the progress printing when calling this function.
- profiley.helpers.lss._xi2sig_single(R, ln_rxi, ln_1plusxi, idx=None, verbose=True)
Auxiliary function to calculate the surface density from the correlation function for a single profile
The primary use of this function is as a helper for xi2sigma, which allows the calculation of multiple surface density profiles in parallel.
Parameters
- Rnp.ndarray, shape (N,)
distances at which to calculate the surface density
- ln_rxinp.ndarray, shape (M,)
natural log of the distances at which the correlation function has been calculated
- ln_1plusxinp.ndarray, shape (M,)
natural log of (1+xi) where xi is the correlation function, calculated at distances Rxi
- idxtype free, optional
pointers to the original array to map the results of the multiprocessing Pool used to loop through calls to this function
Returns
- sig_singlelist, len N
integral required for surface density calculated at locations R. Note that for convenience this is a list and not a np.ndarray, and more importantly note that this is NOT the surface density, which corresponds instead to sigma=2*rho_m*R*sig_single.
- idxthe argument idx is also returned only if specified
when calling this function