astropaint.lib package

Submodules

astropaint.lib.log module

library for logging functions and classes

exception astropaint.lib.log.CMBAlreadyAdded

Bases: Exception

exception astropaint.lib.log.NoiseAlreadyAdded

Bases: Exception

exception astropaint.lib.log.ParameterNotFound

Bases: KeyError

astropaint.lib.plot_configs module

astropaint.lib.transform module

library for transforming halo properties and coordinates

astropaint.lib.transform.D_c_to_D_a(D_c, redshift)

calculate the angular diameter distance (D_a) from comoving distance (D_c) and redshift ( redshift)

astropaint.lib.transform.D_c_to_redshift(D_c, units=Unit("Mpc"))

calculate the redshift from comoving distance (D_c)

astropaint.lib.transform.M_200c_to_R_200c(M_200c, redshift)

calculate R_200c from M_200c at the given redshift see Eq. 1 in Huang et al 1701.04001

astropaint.lib.transform.M_200c_to_c_200c(M_200c, redshift)

calculate the concentration parameter from M_200c at the given redshift use fitting formula in Eq 19 of Child et al 2018 (1804.10199)

astropaint.lib.transform.M_200c_to_rho_s(M_200c, redshift, R_200c=None, c_200c=None)

calculate the NFW rho_s parameter from M_200c at the given redshift if R_200c and c_200c are not given, calculate them

astropaint.lib.transform.M_to_tau(M)
astropaint.lib.transform.arcmin2rad(angle)

convert arcmins to radians

astropaint.lib.transform.convert_velocity_cart2sph(th, ph, v_x, v_y, v_z)
astropaint.lib.transform.convert_velocity_sph2cart(th, ph, v_r, v_th, v_ph)

Calculate the cartesian velocity components from the spherical ones

astropaint.lib.transform.fwhm2sigma(fwhm, arcmin=True)

Convert fwhm to sigma

Parameters:
  • fwhm (float) – Full Width Half Maximum (fwhm)
  • arcmin (bool) – if True, fwhm will be converted from arcmin to rad
Returns:

sigma – fwhm ** 2 / 8 / np.log(2)

Return type:

float [rad]

astropaint.lib.transform.get_cart2sph_jacobian(th, ph)

calculate the transformation matrix (jacobian) for spherical to cartesian coordinates at line of sight (th, ph) [radians]

see https://en.wikipedia.org/wiki/Vector_fields_in_cylindrical_and_spherical_coordinates

th is the polar angle with respect to z and ph is the azimuthal angle with respect to x

example:

th_rad = np.deg2rad(df[‘th’].values) ph_rad = np.deg2rad(df[‘ph’].values)

v_cart = np.array([df[‘vx’],df[‘vy’],df[‘vz’]])

thph_grid = np.array([th_rad,ph_rad])

J_cart2sph = cart2sph2(th_rad,ph_rad) v_cart2sph = np.einsum(‘ij…,i…->j…’,J_cart2sph,v_cart)

astropaint.lib.transform.get_sph2cart_jacobian(th, ph)

calculate the transformation matrix (jacobian) for spherical to cartesian coordinates at line of sight (th, ph) [radians]

see https://en.wikipedia.org/wiki/Vector_fields_in_cylindrical_and_spherical_coordinates

th is the polar angle with respect to z and ph is the azimuthal angle with respect to x

example: see cart2sph2

astropaint.lib.transform.rad2arcmin(angle)

convert radians to arcmins

astropaint.lib.transform.radius_to_angsize(radius, D_a, arcmin=True)

calculate the angular radius (theta) of the halo from its radius and angular diameter distance (D_a).

if arcmin == True: return the value in arcmin

*NOTE: radius and D_a must have the same units

astropaint.lib.transform.rotate_patch(patch, angle)

Rotate input patch by angle [deg]

astropaint.lib.transform.taper_patch(patch)

taper the patch to smooth out the edges

astropaint.lib.utils module

astropaint.lib.utils.LOS_integrate(profile_3D, *args, **kwargs)

integrate along the line of sight for all 3D r’s that correspond to the 2D R

astropaint.lib.utils.combine_Nl(Nls)

combine the input noise power spectra

Parameters:Nls (list) – list of noise power spectra
Returns:
  • combined noise power spectrum
  • 1/N_tot = 1/N1 + 1/N2 + …
astropaint.lib.utils.get_CMB_Cl(lmax, lmin=0, mode='TT', return_ell=False, uK=False)

load Cl from camb generated Dl file

Parameters:
  • lmax (int) – max ell number
  • lmin (int) – min ell number
  • mode (str) – CMB mode to return (e.g. “TT”, “EE”, etc)
  • return_ell (bool) – if True, returns the corresponding ell array as well
Returns:

  • Cl [K^2]
  • or
  • ell, Cl [K^2]
  • available keys in Cls (L, TT, EE, BB, TE)

astropaint.lib.utils.get_custom_B2l(fwhm, lmax, lmin=0, arcmin=True, return_ell=False)

Compute the instrumental Beam power spectrum

After smoothing the map with a beam of size fwhm, the power spectrum would be suppressed by a factor

B2l= np.exp(-ell * (ell + 1) * sigma_b)

where sigma_b = fwhm ** 2 / 8 / np.log(2)

Parameters:
  • [arcmin] (fwhm) – beam fwhm in arcmins (or radians if arcmin=False)
  • lmax – maximum ell mode in the power spectrum
  • lmin – minimum ell mode in the power spectrum
  • arcmin (bool) – set to True if fwhm is in arcmin
  • return_ell (bool) – if True, returns the corresponding ell array as well
Returns:

  • Bl^2
  • or
  • ell, Bl^2

astropaint.lib.utils.get_custom_Nl(sigma_n, lmax, fwhm=None, frequency=[217], lmin=0, apply_beam=False, uK=False, return_ell=False)

get temperature and polarization noise power spectra for a custom experiment

Parameters:
  • [uK-arcmin] (sigma_n) – noise level in uK-arcmin can a scalar or an array for multiple channels the length must match that of fwhm
  • lmax (scalar) – maximum ell mode of the power spectrum
  • [arcmin] (fwhm) – beam fwhm in arcmins can be scalar or an array for multiple channels
  • lmin (scalar) – minimum ell mode of the power spectrum
  • apply_beam – if True, deconvolves the noise with beam
  • return_ell (bool) – if True, returns the corresponding ell array as well
Returns:

  • Nl [K^2]
  • or
  • ell, Nl [K^2]

astropaint.lib.utils.get_experiment_Nl(lmax, lmin=0, name='Planck', frequency=[217], apply_beam=False, uK=False, return_ell=False)

get temperature and polarization noise power spectra for various experiments

Parameters:
  • lmax (scalar) – maximum ell mode of the power spectrum
  • lmin (scalar) – minimum ell mode of the power spectrum
  • name – name of the experiment string in [“Planck” , “SO” , “S4”]
  • apply_beam – if True, deconvolves the noise with beam
  • return_ell (bool) – if True, returns the corresponding ell array as well
Returns:

  • Nl_TT [K^2]
  • or
  • ell, Nl_TT [K^2]

astropaint.lib.utils.interpolate(profile, n_samples=20, min_frac=None, sampling_method='linspace', k=3, interpolator=<class 'scipy.interpolate.fitpack2.InterpolatedUnivariateSpline'>, *args, **kwargs)

interpolate the profile function instead of calculating it at every given R

Parameters:
  • profile – wrapped profile to be interpolated (implicit)
  • n_samples (int) – number of points to sample in R
  • min_frac (float) –

    fraction of points in R to sample, unless n_sample is larger if min_frac: n_samples = max(n_samples, min_frac * len(R))

    e.g. for n_sample=10, min_frac=0.1 if len(R)=200, 20 (0.1*200) points will be sampled, but if len(R)=50 10 points will be sampled

  • sampling_method (str in ["linspace", "logspace", "random"]) – determines how the points are sampled
  • k (int) – interpolation order
  • interpolator (func) – interpolating function
Returns:

Return type:

Interpolated profile

astropaint.lib.utils.load_Cl_Planck2018(lmin=0)

load Cl from camb generated Dl file

Parameters:
  • lmax (max ell number) –
  • lmin (min ell number) –
Returns:

  • Cls
  • available keys in Cls (L, TT, EE, BB, TE)

astropaint.lib.utils.load_noise_yaml()
astropaint.lib.utils.sample_array(array, n_samples, method='linspace', eps=0.001)

sample an input array

astropaint.lib.utils.timeit(process_name='Process')

Time the code in mins

Module contents