moments module

Contains functions relating to skewness and kurtosis.

moments.ex_std_moment(x, pdf, order)

Numerically calculate the excess standard moment of a distribution for a given order, i.e. for order n, <((x - μ)/σ)^n> minus the Gaussian equivalent, where μ is the mean and σ the standard deviation.

Parameters
  • x (1D numpy array) – Values of the variable whose moments are required.

  • pdf (1D numpy array) – Normalised probability density values at each value of x.

  • order (int) – Order of the required moment, e.g. 3 for skewness.

Returns

Excess standard moment of the required order.

Return type

float

moments.exkurt_fullsky(l)

Returns the excess kurtosis of the full-sky marginal likelihood for a given l.

Parameters

l (int) – The l to return the excess kurtosis for.

Returns

Excess kurtosis of the full-sky marginal likelihood for this l.

Return type

float

moments.explain_mapping(cut_sky_pdf_path, lmax, save_path=None)

Produce a pictorial aid for the l-mapping process using skewness.

Parameters
  • cut_sky_pdf_path (str) – Path to marginal pseudo-Cl likelihood distributions produced by pcl_like.marginal_cl_likes.

  • lmax (int) – Maximum l to calculate skewness for.

  • plot_save_path (str, optional) – Path to save figure to, if supplied. If not supplied, figure is displayed.

moments.get_all_moments(cut_sky_pdf_path, lmax, plot=None, plot_save_path=None, data_save_path=None)

Calculate full-sky and cut-sky skewness and excess kurtosis for all l.

Parameters
  • cut_sky_pdf_path (str) – Path to marginal pseudo-Cl likelihood distributions produced by pcl_like.marginal_cl_likes.

  • lmax (int) – Maximum l to calculate moments for.

  • plot (str, optional) – ‘skew’ to plot skewness, ‘exkurt’ to plot excess kurtosis.

  • plot_save_path (str, optional) – Path to save figure to, if supplied. If not supplied, figure is displayed.

  • data_save_path (str, optional) – Path to save calculated moments to as a text file, if supplied.

moments.get_leff_map(data_path, fit_lmax, lmax, grid_vals=None, plot_save_path=None, map_save_path_kurt=None, map_save_path_skew=None)

Calculate l-leff mapping from full-sky and cut-sky moments calculated in get_all_moments.

Parameters
  • data_path (str) – Path to moments produced by get_all_moments.

  • fit_lmax (int) – Maximum l to use for the linear fit used for the extrapolation.

  • lmax (int) – Maximum l to extrapolate to.

  • grid_vals (list, optional) – List of x values at which to draw grid lines, which extend from the x axis to the mapping line and then left to the y axis.

  • plot_save_path (str, optional) – Path to save figure to, if supplied. If not supplied, figure is displayed.

  • map_save_path_kurt (str, optional) – Path to save l-leff mapping calculated using kurtosis.

  • map_save_path_skew (str, optional) – Path to save l-leff mapping calculated using skewness.

moments.get_sim_moments(input_files, data_id, batch_size, n_ell, whiten=False)

Extract sample skewness and excess kurtosis from a list of input files produced by simulation.sim_singlespec.

Parameters
  • input_files (list) – List of input files to combine before measuring skewness and excess kurtosis.

  • data_id (str) – Data label within input npz files.

  • batch_size (int) – Number of realisations per batch.

  • n_ell (int) – Number of ells.

  • whiten (bool, optional) – If True, whiten the data before measuring moments (default False).

Returns

Skewness for each l, excess kurtosis for each l.

Return type

(1D numpy array, 1D numpy array)

moments.plot_leff_map(data_path, fit_lmax, lmax, plot_save_path=None)

Plot exact and extrapolated l-leff mapping side-by-side.

Parameters
  • data_path (str) – Path to moments produced by get_all_moments.

  • fit_lmax (int) – Maximum l to use for the linear fit used for the extrapolation.

  • lmax (int) – Maximum l to extrapolate to.

  • plot_save_path (str, optional) – Path to save figure to, if supplied. If not supplied, figure is displayed.

moments.plot_sim_moments(sim_path, kurt_leff_map_path, skew_leff_map_path, save_path=None)

Plot simulated moments calculated with save_sim_moments compared to moments predicted by l-leff mapping produced with get_leff_map.

Parameters
  • sim_path (str) – Path to simulated moments produced by save_sim_moments.

  • kurt_leff_map_path (str) – Path to kurtosis l-leff mapping produced by get_leff_map.

  • skew_leff_map_path (str) – Path to skewness l-leff mapping produced by get_leff_map.

  • save_path (str, optional) – Path to save figure to, if supplied. If not supplied, figure is displayed.

moments.plot_skew_slics_gauss(slics_filemask, gauss_path, n_zbin, save_path=None)

Plot skewness against l for SLICS compared to Gaussian field simulations.

Parameters
  • slics_filemask (str) – Path to SLICS bandpowers output by simulation.combine_slics, with {tomo} as a placeholder for tomographic bin.

  • gauss_path (str) – Path to Gaussian field bandpowers output by simulation.sim_flat.

  • n_zbin (int) – Number of redshift bins.

  • save_path (str, optional) – Path to save figure to, if supplied. If not supplied, figure is displayed.

moments.save_sim_moments(input_filemask, batch_size, lmax, lmin, save_path, whiten=False)

Calculate full-sky and cut-sky skewness and kurtosis for all l from simulations produced with simulation.sim_singlespec, and save the results to a text file.

Parameters
  • input_filemask (str) – glob filemask matching all simulation batches produced with simulation.sim_singlespec.

  • batch_size (int) – Number of realisations per batch.

  • lmax (int) – Maximum l of simulations.

  • lmin (int) – Minimum l of simulations.

  • save_path (str) – Path to save output text file to.

  • whiten (bool, optional) – If True, whiten data prior to measuring moments (default False).

moments.skew_fullsky(l)

Returns the skewness of the full-sky marginal likelihood for a given l.

Parameters

l (int) – The l to return the skewness for.

Returns

Skewness of the full-sky marginal likelihood for this l.

Return type

float