Statistics¶
Statistics of the products, as mixins of the builders and catalogs: MapBuilder inherits
MapStatistics (tracers and predictions, power spectra, moments, Gaussian maps and
plots of the maps), and CatalogGenerator inherits
CatalogStatistics (Cls and two-point functions of the catalogs, their
predictions and plots). Their methods are called on the builders and catalogs, e.g. shell_builder.compute_cls().
Statistics of the products: power spectra and moments of the maps (maps), and
two-point statistics of the catalogs (catalogs), with their predictions and plots.
Their classes are mixins, inherited by MapBuilder and
CatalogGenerator: the statistics are methods of the builders and catalogs.
Maps¶
Statistics of the maps (MapStatistics, inherited by MapBuilder).
Tracers and theory of the maps, power spectra with NaMaster and their predictions, moments, Gaussian maps, and plots.
- class pollux.statistics.maps.MapStatistics[source]¶
Bases:
TwoPointStatisticsStatistics of the maps of a builder: tracers and predictions, power spectra, moments and plots.
Mixin of
MapBuilder, using its maps, a_lm, footprint and binning options. Subclasses implement_create_tracers(), and_noise_cls()for noise-aware predictions.- property tracers: list[source]¶
Return (and lazily create) the tracers describing the maps.
- Returns:
One tracer per map, from which CCL and SACC tracers are derived (
pollux.cosmo.Tracer.ccl(),pollux.cosmo.Tracer.sacc()).- Return type:
- compute_cls(imaps=None, *, auto_only=False, pairs=None, save=True, use_precomputed_alms=True)[source]¶
Compute binned pseudo-C_ell bandpowers for requested map pairs.
- Parameters:
imaps (int or array_like of int or None, optional) – Map indices. If None, uses all maps.
auto_only (bool, optional) – If True, compute only auto-spectra.
pairs (list of tuple of int or None, optional) – If given, only these
(i, j)map pairs (overridesimapsandauto_only).save (bool, optional) – If True, save spectra to SACC FITS (
what='cls').use_precomputed_alms (bool, optional) – If True, reads a_lm from disk and uses Healpy
healpy.alm2cl()followed by NaMaster decoupling. If False, computes NaMaster fields from masked maps and runs full MASTER withpymaster.compute_full_master().
- Returns:
ell (ndarray) – Effective multipoles of the bandpowers.
cl (dict) – Dictionary keyed by (i, j) containing decoupled bandpowers.
- Return type:
- property b: pymaster.NmtBin[source]¶
Return (and lazily create) the NaMaster binning scheme.
- Returns:
Bandpower binning used for
compute_cls()andpredict_cls(): that given to the builder, or 20 logarithmic bands from ell = 8 to2 * nside, dividing out the pixel window withpixel_window.- Return type:
pymaster.NmtBin
Notes
Lazy, so that the builder stays light to pickle: the
NmtBinis not constructed until first accessed (unless given at construction).
- property wsp: pymaster.NmtWorkspace[source]¶
Return (and lazily create) the NaMaster workspace.
The workspace stores the mode-coupling matrix and bandpower windows for the current mask and binning, and is cached on disk with the footprint products (
pollux.footprint.Footprint.path()).- Returns:
Workspace containing the coupling matrix and bandpower windows.
- Return type:
pymaster.NmtWorkspace
Notes
Lazy, so that the builder stays light to pickle: the
NmtWorkspaceis not constructed until first accessed.
- property bpws: ndarray[source]¶
Return the bandpower windows of the workspace (see
wsp).They are saved apart, next to the workspace, so that predictions do not load the coupling matrix (several GB at high resolution), only once to save them.
- Returns:
Shape
(n_cl, n_bands, n_cl, lmax + 1).- Return type:
ndarray
- read_cls(return_dict=False, return_errors=False)[source]¶
Read saved angular power spectra.
- Parameters:
- Returns:
If
return_dict=False, returns the loaded SACC object. Ifreturn_dict=True, returns(ell, cls_dict)whereellis the ell array for each spectrum andcls_dictis keyed by (i, j).- Return type:
- Raises:
FileNotFoundError – If the SACC file does not exist.
- predict_cls(imaps=None, *, auto_only=False, pairs=None, binning='wsp', error_bars=False, stacked=False, ell=None, non_limber=False)[source]¶
Predict theory angular power spectra using CCL.
- Parameters:
imaps (int or array_like of int or None, optional) – Map indices. If None, uses all maps.
auto_only (bool, optional) – If True, compute only auto-spectra.
pairs (list of tuple of int or None, optional) – If given, only these
(i, j)map pairs (overridesimapsandauto_only).binning ({'wsp', 'average', 'unbinned'}, optional) –
'wsp'(default): bandpowers binned with the bandpower windows ofwsp, like the measured spectra.'average': bandpowers averaged over each bandpower.'unbinned': spectra atell.error_bars (bool, optional) – If True, compute Gaussian (diagonal-in-ell) error bars, with
C_ell + N_ellfor auto-spectra (noise from_noise_cls()).stacked (bool, optional) – If True, also return spectra stacked into a single vector (and, when
error_bars=True, a diagonal covariance matrix).ell (ndarray or None, optional) – Multipoles at which to evaluate CCL when
binning='unbinned'. If None, uses the effective bandpower ells from the binning scheme.non_limber (bool, optional) – Correct the Limber approximation of the spectra of density maps, e.g. shells, which are thin (
pollux.cosmo.Theory.angular_cl()): 10-25% at ell ~ 30-100 and a few percent at ell ~ 200 for the shells of a lightcone, but minutes per pair. Default is False.
- Returns:
ell (ndarray) – Ell values (effective bandpower ells or explicit
ellinput).cl (dict) – Dictionary keyed by (i, j) with spectra arrays.
dcl (dict) – Only with
error_bars: Gaussian error bars, keyed likecl.cl_stacked (ndarray) – Only with
stacked: spectra stacked into one vector.cov (ndarray) – Only with
stackedanderror_bars: covariance ofcl_stacked(diagonal in ell).
- Return type:
Notes
Wraps
pollux.cosmo.Theory.predict_cls()with the builder’s tracers, matter power spectrum, workspace bandpower windows, pixel window (pixel_window), noise model (_noise_cls()) and sky fraction.
- property theory: Theory[source]¶
Return the theory predictor of the maps.
- Returns:
With the builder’s cosmology and
matter_power_spectrum().- Return type:
- matter_power_spectrum()[source]¶
Return the matter power spectrum consistent with the maps, for predictions.
- Returns:
None (CCL’s nonlinear matter power spectrum) by default; overridden by builders whose maps follow another one (e.g.
BaryonifiedShellBuilder, or lensing builders using their shell builder’s).- Return type:
pyccl.Pk2D or None
- reference_scales(smooth_Mpc=None)[source]¶
Return the angular scales of the simulation box, of the map resolution, and of a smoothing, per map.
- Parameters:
smooth_Mpc (float or None, optional) – Comoving Gaussian smoothing scale in Mpc.
- Returns:
theta_box(arcmin) andell_box, andtheta_smooth,ell_smoothwithsmooth_Mpc(at least the pixel size, seepollux.cosmo.Tracer.effective_smooth_Mpc()), one value per map, at the redshift where its signal comes from (pollux.cosmo.Tracer.mean_redshift_kernel(), e.g. the lenses for lensing maps);theta_res(arcmin) andell_res, the pixel size ofnside, the same for all maps.- Return type:
- plot_cls(plot_dir=None, *, modes=('values', 'ratio'), ell_factor=1, logy=False, error_bars=False, **predict_kwargs)[source]¶
Plot the saved angular power spectra against their prediction (
predict_cls()), one panel per map pair.- Parameters:
plot_dir (str or None, optional) – Output directory. Default is
{save_dir}/plots.modes (tuple of str, optional) – Plots to make, see
pollux.statistics.plotting.plot_pairs()('values','ratio','diff_over_error'). Default is('values', 'ratio').ell_factor ({0, 1, 2}, optional) – In
'values'mode, plotC_ell(0),ell C_ell(1, default) orell (ell + 1) C_ell / 2 pi(2).logy (bool, optional) – If True, use a log y-scale in
'values'mode.error_bars (bool, optional) – If True, draw Gaussian errors of the prediction as bands (always used by
'diff_over_error').**predict_kwargs – Options of
predict_cls(), e.g.auto_only,pairsorbinning: the predicted pairs are plotted.
- Return type:
None
Notes
Saves
{map_name}_cls, with suffix_{mode}for modes other than'values'.
- compute_map_moments(theta_smooth, nside_small=512, save=True)[source]¶
Compute 2nd/3rd/4th moments of smoothed maps.
- Parameters:
- Returns:
theta_smooth (ndarray) – Smoothing scales (arcmin).
second_moment (dict) – Covariance matrices keyed by smoothing scale (theta -> (nmaps,nmaps)).
third_moment (dict) – Third-order moments keyed by smoothing scale (theta -> (nmaps,nmaps,nmaps)).
fourth_moment (dict) – Fourth-order moments keyed by smoothing scale (theta -> (nmaps,nmaps,nmaps,nmaps)).
- Raises:
FileNotFoundError – If the a_lm of a map are not saved (
compute_alms()first).- Return type:
Notes
This method: 1) loads the saved a_lm of each map (
compute_alms()), 2) resizes them tolmax_out = 2*nside_small, 3) makes smoothed maps for eachtheta, 4) computes raw moments on the masked pixels, 5) saves results towhat='2nd_3rd_4th_moments', format='npy'ifsave=True.
- read_map_moments()[source]¶
Read previously saved 2nd/3rd/4th moments of smoothed maps.
- Returns:
theta_smooth (ndarray) – Smoothing scales (arcmin).
second_moment (dict) – Covariance matrices keyed by smoothing scale (theta -> (nmaps,nmaps)).
third_moment (dict) – Third-order moments keyed by smoothing scale (theta -> (nmaps,nmaps,nmaps)).
fourth_moment (dict) – Fourth-order moments keyed by smoothing scale (theta -> (nmaps,nmaps,nmaps,nmaps)).
- Raises:
FileNotFoundError – If the moments file does not exist.
- Return type:
- generate_gaussian_maps(imaps=None, *, auto_only=False, seed=-1)[source]¶
Generate Gaussian random maps consistent with predicted spectra.
- Parameters:
imaps (int or array_like of int or None, optional) – Map indices to generate. If None, generates all maps.
auto_only (bool, optional) – If True, generate each map independently using its auto-spectrum. If False, generate a correlated set of maps from all cross-spectra.
seed (int, optional) – Random seed passed to NaMaster synfast routines. Default is -1.
- Return type:
None
Notes
Maps are generated full-sky and then restricted to the padded footprint (like the maps they stand for) before writing (in the builder’s
map_format).
Catalogs¶
Two-point statistics of the catalogs (CatalogStatistics, inherited by CatalogGenerator).
Cls with NaMaster (catalog fields), two-point functions with TreeCorr, their predictions with the same tracers, binning, pixel window and smoothing, and plots against them.
- class pollux.statistics.catalogs.Shapes(name, terms, columns, tracers, shape_noise)[source]¶
Bases:
NamedTupleShapes of the shear legs of the statistics of a catalog: what they measure and predict (
of()).- Parameters:
- TERMS = {'ia': ('ia',), 'observed': ('shear', 'ia'), 'shear': ('shear',), 'shear_plus_ia': ('shear', 'ia')}¶
- property column_key: tuple[str, str]¶
The columns of each component joined by
'+', as in file names and options.
- classmethod of(catalog, shapes='shear', shear_cols=('gamma1', 'gamma2'))[source]¶
Return what the shapes
shapesof the shear legs measure and predict.- Parameters:
catalog (CatalogStatistics) – Catalog (its augmentors and tracers).
shapes ({'shear', 'ia', 'shear_plus_ia', 'observed'}, optional) – Shapes: the lensing shear (
shear_cols), the intrinsic alignments (e1_ia_*,e2_ia_*of theCatalogAugmentorIA), their sum without shape noise, or the observed ellipticities (e1_obs,e2_obsof theCatalogAugmentorShear), with shape noise, predicted as the sum of the lensing shear and of the intrinsic alignments they include.shear_cols (tuple of str, optional) – Columns of the lensing shear.
- Returns:
Fields summed, catalog columns summed into each component, tracers (sums of tracers for several fields,
TracerSum) and shape noise.- Return type:
- class pollux.statistics.catalogs.CatalogStatistics[source]¶
Bases:
TwoPointStatisticsTwo-point statistics of a catalog: measurements, predictions and plots.
Mixin of
CatalogGenerator, using its lensing builder (lensing), tomographic bins, galaxy densities (nbar), augmentors and directories.- property density_tracers: list[Tracer]¶
each bin’s n(z) and linear bias.
- Returns:
'density'tracers nameddensity_{i}, with the n(z) of the lensing tracers (the galaxies are both lenses and sources), and the smoothing of the density used to place them ('positions'smoothing, at least the pixel size).- Return type:
- Type:
Density tracers of the catalog
- property lensing_tracers: list[Tracer]¶
Lensing tracers of the catalog, those of the lensing builder (
tracers).- Returns:
Shear tracers (one per bin) with the n(z) of the catalog’s galaxies.
- Return type:
- property ia_tracers: list[Tracer] | None¶
Intrinsic-alignment tracers of the catalog, from its
CatalogAugmentorIAaugmentor.- Returns:
'ia'tracers namedia_{i}, with the n(z) of the lensing tracers, the amplitudes of the augmentor (tracer_amplitudes(), with the bias of each bin) and the smoothing of the tidal field; None without intrinsic alignments.- Return type:
list of pollux.cosmo.Tracer or None
- reference_scales(roles, shapes='shear')[source]¶
Return the reference scales of a statistic: of the lensing maps, and the smoothing of the fields of its legs.
- Parameters:
roles (tuple of str) – Roles of the two legs (
'density'or'shear'), as in_SACC_TYPE_LEGS_2PT.shapes (str, optional) – Shapes of the shear legs (see
compute_2pt()): for'ia', their smoothing is that of the tidal field (the lensing shear is not smoothed).
- Returns:
reference_scales()of the lensing builder, with, if a leg is smoothed,theta_smooth(arcmin) andell_smoothper bin pair: the smoothing of the density placing the galaxies of a density leg, or of the tidal field of an IA leg (shapes='ia') (effective_smooth_Mpc(), at the mean redshift of the bin’s n(z)), the geometric mean of the two legs if both are smoothed.- Return type:
- compute_alms(ibins=None, what='all', *, shapes='shear', shear_cols=('gamma1', 'gamma2'), subsample=None, remove_mean=True, randoms=False, randoms_per_galaxy=5, randoms_shared=True, seed=None, save=True)[source]¶
Compute the NaMaster catalog fields of tomographic bins, used by
compute_cls().Each field (its a_lm and those of its mask) is the costly part of the catalog Cls: it is computed once per bin and saved as an intermediate file, in a folder named by an identifier of what the field depends on (the multipoles of the field and mask, and the options that apply to its kind), read by later calls instead of loading the catalog again.
- Parameters:
ibins (int or array_like of int or None, optional) – Tomographic bins. If None, all bins.
what ({'shear', 'clustering', 'shear_clustering', 'all'} or list of str, optional) – Statistics to compute (see
compute_cls()), which set the fields needed: density fields for'clustering'and'shear_clustering', shear fields for'shear'and'shear_clustering'.shapes (optional) – See
compute_cls().shear_cols (optional) – See
compute_cls().subsample (optional) – See
compute_cls().remove_mean (optional) – See
compute_cls().randoms (optional) – See
compute_cls().randoms_per_galaxy (optional) – See
compute_cls().randoms_shared (optional) – See
compute_cls().seed (optional) – See
compute_cls().save (bool, optional) – If True (default), read the fields saved, and save those computed. If False, compute them without saving.
- Returns:
f_dens, f_shear – Density (
NmtFieldCatalogClustering) and spin-2 shear (NmtFieldCatalog) fields keyed by bin, if needed bywhat. Each field has amask_amplitudeattribute, the ratio of its mask to footprint of the maps (pollux.footprint.Footprint.mask()) (its weighted number of galaxies or randoms per steradian of footprint, or 1 for density fields with the footprint mask). Fields read from disk have their a_lm, not their catalog values or mask map.- Return type:
- property b: pymaster.NmtBin[source]¶
Return (and lazily create) the NaMaster binning of
compute_cls()andpredict_cls().- Returns:
cls_b, or else the shell builder’s binning (MapBuilder.b) without its pixel-window deconvolution: the pixel window is in the predictions instead (seepredict_cls()).- Return type:
pymaster.NmtBin
- property lmax_mask: int¶
Maximum multipole of the masks of the catalog fields and of the footprint (
cls_lmax_mask, at least that of the binning).- Return type:
- wsp(stat, pair=None, fields=None, read_unbinned_MCM=True, **field_kwargs)[source]¶
Return (and lazily create) the workspace of one statistic and bin pair.
The workspace stores the mode-coupling matrix and bandpower windows. It is either specific to a bin pair, computed from the masks of the pair’s catalog fields (the weighted galaxy positions, and the footprint or randoms for density), or shared by all bin pairs (
pair=None), computed from footprint of the maps (pollux.footprint.Footprint.mask()). The shared workspace is exact in expectation for galaxies uniformly distributed over the footprint once pseudo-spectra are divided by the fields’mask_amplitude(seecompute_cls()); with clustered sources, it misses the coupling from the clustering of galaxy positions.Workspaces are cached on disk (
_path_wsp()), with their bandpower windows when computed; shared workspaces are also cached in memory.- Parameters:
stat ({'clustering', 'shear', 'shear_clustering'}) – Statistic.
pair (tuple of int or None, optional) – Bin pair, or None (default) for the shared workspace.
fields (tuple or None, optional) – For a bin pair, the two fields to compute the workspace from, if not on disk. By default, the fields of the pair.
read_unbinned_MCM (bool, optional) – When reading from disk, also read the unbinned mode-coupling matrix, needed for bandpower windows but not to decouple spectra, and large. Default is True.
**field_kwargs – Field options for a bin pair (
shapes,shear_cols,randoms,randoms_per_galaxy,seed,subsample,randoms_shared,remove_mean), seecompute_cls().
- Return type:
pymaster.NmtWorkspace
- bpws(stat, pair=None, randoms=False)[source]¶
Return the bandpower windows of a workspace (see
wsp()).Read from the file saved with the workspace, else from the workspace (and saved). The shared workspace is computed if missing.
- Parameters:
stat ({'clustering', 'shear', 'shear_clustering'}) – Statistic.
pair (tuple of int or None, optional) – Bin pair, or None (default) for the shared workspace.
randoms (bool, optional) – For a bin pair, whether density fields are masked by randoms (see
compute_cls()).
- Returns:
Shape
(n_cl, n_bands, n_cl, lmax + 1).- Return type:
ndarray
- Raises:
FileNotFoundError – If the workspace of a bin pair has not been computed (see
compute_cls()).
- compute_cls(ibins=None, what='all', *, auto_only=False, pairs=None, shared_wsp=False, randoms=False, shapes='shear', shear_cols=('gamma1', 'gamma2'), subsample=None, remove_mean=True, randoms_per_galaxy=5, randoms_shared=True, seed=None, save=True, use_precomputed_alms=True)[source]¶
Measure angular power spectra directly from the generated catalog(s), including all cross-tomographic-bin combinations.
Uses NaMaster’s catalog-based pseudo-C_ell estimators (
NmtFieldCatalogfor shear,NmtFieldCatalogClusteringfor clustering), binned with the shell builder’s own NmtBin (ShellBuilder.b) so that the resultingellmatches other C_ell products in the codebase for direct comparability. The pixel-window deconvolution folded into the shell builder’s binning (appropriate for map-based estimators) is stripped out, since catalog fields are sampled at exact positions and have no pixel window to correct for.- Parameters:
ibins (int or array_like of int or None, optional) – Tomographic bin indices to process. If None, uses all bins.
what ({'shear', 'clustering', 'shear_clustering', 'all'} or list of str, optional) –
Which spectra to compute:
’clustering’: galaxy density auto/cross-spectra (dd), symmetric i>=j pairs.
’shear’: shear E/B-mode auto/cross-spectra (ee, bb), symmetric i>=j pairs.
’shear_clustering’: density-shear cross-spectrum (de, db), all (i, j) ordered pairs since lens-bin i / source-bin j is not symmetric.
’all’: compute all three. Default.
auto_only (bool, optional) – If True, restrict to same-bin pairs (i, i) only, skipping cross-bin spectra. Default is False (compute all cross-bin combinations).
pairs (list of tuple of int or None, optional) – If given, only compute these
(i, j)bin pairs, for every statistic inwhat(overridesibinsandauto_only). Only the catalogs of the bins involved are loaded.shared_wsp (bool, optional) – If True, use one mode-coupling matrix per statistic (dd, shear-shear, density-shear) for all bin pairs, computed from the footprint, with pseudo-spectra divided by the fields’ mask amplitudes (see
wsp()). This is exact in expectation for galaxies uniformly distributed over the footprint, but misses the coupling from the clustering of galaxy positions. If False (default), use one workspace per pair, computed from the masks of its fields (exact, slower). Workspaces are cached on disk and reused by later calls and bypredict_cls(); delete them if the catalogs or settings change.randoms (bool, optional) – If False (default), the mask of density fields is the footprint of the maps (
pollux.footprint.Footprint.mask()). If True, it is a random catalog (seerandoms_per_galaxyandrandoms_shared).shapes ({'shear', 'ia', 'shear_plus_ia', 'observed'}, optional) – Shapes of the shear legs, as in
compute_2pt(): the lensing shear (shear_cols, default), the intrinsic alignments, their sum without shape noise, or the observed ellipticities, with shape noise. The fields sum the columns of the shapes (Shapes.of()).shear_cols (tuple of str, optional) – Names of the two catalog columns of the lensing shear in the shapes, e.g.
('gamma1', 'gamma2')(default) or('g1', 'g2')(reduced shear). Must be present in the loaded catalog (see the augmentors used at generation time, e.g.CatalogAugmentorShear,CatalogAugmentorIA).subsample (float or None, optional) – If not None, randomly draw (without replacement, seeded by
seed + ibin) this fraction of galaxies from each loaded catalog before building fields, with0 < subsample < 1. A random draw is used rather than a fixed stride, since galaxies are stored in a fixed (non-random) order and a stride would sample a specific, non-representative pattern. Default is None (no subsampling).remove_mean (bool, optional) – If True (default), subtract the mean of the shear columns over each bin before the measurement.
randoms_per_galaxy (int, optional) – With
randoms, ratio of random points to galaxies for each bin’s clustering random catalog. Default is 5.randoms_shared (bool, optional) – With
randoms, if True (default), draw a single random-point realization (sized from the galaxies of the first bin, whatever the bins computed) and reuse it for every bin’s density field, rather than drawing independent randoms per bin. This matches the fact that all bins share the same survey footprint, and is cheaper since randoms are only drawn once. If False, each bin gets its own randoms, seeded byseed + ibin.seed (int or None, optional) – Seed for the random catalogs’ RNG. Default is the shell builder’s seed.
save (bool, optional) – If True (default), save the spectra to a SACC FITS file via
_write_cls(), atcat_cls[_{shapes}].fitsof the catalogs.use_precomputed_alms (bool, optional) – If True (default), the fields of each bin come from
compute_alms(): read from their intermediate files, or computed and saved. If False, they are computed and not saved.
- Returns:
ell (ndarray) – Effective multipoles of the bandpowers (shared with other C_ell products via the same underlying binning, minus pixel-window deconvolution).
cl (dict) – Keyed by SACC data type (e.g.
'galaxy_density_cl','galaxy_shear_cl_ee','galaxy_shear_cl_bb','galaxy_shearDensity_cl_e','galaxy_shearDensity_cl_b', depending onwhat), each mapping to a dict keyed by(i, j).
- Return type:
- read_cls(return_dict=False, return_errors=False, shapes='shear')[source]¶
Read catalog-based angular power spectra previously saved by
_write_cls().- Parameters:
return_dict (bool, optional) – If True, return
(ell, cl). Otherwise, return the SACC object.return_errors (bool, optional) – With
return_dict, also return the error bars of the saved covariance, with the same structure ascl(empty without covariance).shapes (str, optional) – Shapes of the shear legs of the measurement (see
compute_cls()).
- Returns:
If
return_dict=False, returns the loaded SACC object. Ifreturn_dict=True, returns(ell, cl)whereellis the multipole array andclis a dict keyed by SACC data type, each mapping to a dict keyed by(i, j)(same structure as returned bycompute_cls()). Reads only the data types and tracer pairs actually present in the file (compute_cls()may not have computed all of them), with no dependency onself.lensingbeyond the file path.- Return type:
- predict_cls(ibins=None, what='all', *, auto_only=False, pairs=None, binning='wsp', shared_wsp=False, randoms=False, shapes='shear', shear_cols=('gamma1', 'gamma2'), subsample=None, error_bars=False, stacked=False, ell=None, pixel_window=True)[source]¶
Predict the catalog angular power spectra.
Predictions use the lensing builder’s
theory, i.e. the matter power spectrum of the catalog’s shells (CCL’s nonlinear P(k) for dark-matter-only shells, S19-corrected for baryonified shells). Predicted spectra are noise-free, like the measured ones (NaMaster subtracts the noise bias of catalog auto-spectra).- Parameters:
ibins (int or array_like of int or None, optional) – Tomographic bins. If None, all bins.
what ({'shear', 'clustering', 'shear_clustering', 'all'} or list of str, optional) – Statistics to predict (see
compute_cls()).auto_only (bool, optional) – If True, only same-bin pairs
(i, i).pairs (list of tuple of int or None, optional) – If given, only these
(i, j)bin pairs, for every statistic inwhat(overridesibinsandauto_only).binning ({'wsp', 'average', 'unbinned'}, optional) –
'wsp'(default): bandpowers binned with the bandpower windows of the workspaces ofcompute_cls()(seeshared_wspandbpws()).'average': bandpowers averaged over each bandpower.'unbinned': spectra atell.shared_wsp (bool, optional) – With
binning='wsp', as incompute_cls(): use the workspace shared by all pairs of each statistic if True, else that of each pair (default).randoms (bool, optional) – With per-pair workspaces, as in
compute_cls().shapes ({'shear', 'ia', 'shear_plus_ia', 'observed'}, optional) – Shapes of the shear legs (see
compute_cls()): their tracers are sums of those of their terms (Shapes.of()), e.g. GG + GI + IG + II for'shear_plus_ia', so that the error bars are those of the summed field.shear_cols (optional) – As in
compute_cls(), setting the noise (see_noise_cls()).subsample (optional) – As in
compute_cls(), setting the noise (see_noise_cls()).error_bars (bool, optional) – If True, also return Gaussian error bars (E-mode and density spectra), with
C_ell + N_ellfor auto-spectra (_noise_cls()) and the lensing builder’s sky fraction.stacked (bool, optional) – If True, also return the E-mode and density spectra of all statistics stacked into one vector (in the order of
what, then of the pairs), and witherror_barstheir joint covariance.ell (ndarray or None, optional) – Multipoles for
binning='unbinned'. Default is the effective bandpower multipoles.pixel_window (bool, optional) – If True (default), multiply the spectra by the pixel window of the maps (one per field): galaxies are placed in the pixels of the density maps, and the fields are interpolated from pixelized maps.
- Returns:
ell (ndarray) – Multipoles.
cl (dict) – Keyed by SACC data type, then by
(i, j)(same structure ascompute_cls()).dcl (dict) – Only with
error_bars, keyed likecl(E-mode and density types).cl_stacked, cov (ndarray) – Only with
stacked(covonly witherror_barstoo).
- Return type:
Notes
Wraps
pollux.cosmo.Theory.predict_cls()(one call for all statistics, so that the covariance includes cross-statistic blocks).
- plot_cls(plot_dir=None, *, modes=('values', 'ratio'), ell_factor=1, logy=False, error_bars=False, shapes='shear', **predict_kwargs)[source]¶
Plot the saved angular power spectra against their prediction (
predict_cls()), one panel per bin pair.- Parameters:
plot_dir (str or None, optional) – Output directory. Default is
{catalog_dir}/plots.modes (tuple of str, optional) – Plots to make, see
pollux.statistics.plotting.plot_pairs()('values','ratio','diff_over_error'). Default is('values', 'ratio').ell_factor ({0, 1, 2}, optional) – In
'values'mode, plotC_ell(0),ell C_ell(1, default) orell (ell + 1) C_ell / 2 pi(2).logy (bool, optional) – If True, use a log y-scale in
'values'mode.error_bars (bool, optional) – If True, draw Gaussian errors of the prediction as bands (always used by
'diff_over_error').shapes ({'shear', 'ia', 'shear_plus_ia', 'observed'}, optional) – Shapes of the shear legs of the measurement (see
compute_cls()).**predict_kwargs – Options of
predict_cls(), e.g.auto_only,pairs, orshared_wspandrandomsas used bycompute_cls(): the predicted pairs are plotted.
- Return type:
None
Notes
Saves
cl_{shapes}_ee,cl_{shapes}_x_densityand, for the lensing shear,cl_density, with suffix_{mode}for modes other than'values'.
- compute_2pt(ibins=None, what='all', *, auto_only=False, pairs=None, theta_min=1.0, theta_max=100.0, ntheta=20, sep_units='arcmin', bin_slop=None, angle_slop=None, shear_cols=('gamma1', 'gamma2'), shapes='shear', subsample=None, remove_mean=True, randoms_per_galaxy=5, randoms_shared=True, seed=None, error_bars=False, theta_per_pair=False, save=True)[source]¶
Measure real-space two-point correlation functions directly from the generated catalog(s), including all cross-tomographic-bin combinations.
Uses TreeCorr’s angular correlation estimators (
NNCorrelationfor clustering,GGCorrelationfor shear,NGCorrelationfor the shear-density cross-correlation), binned in angular separation betweentheta_minandtheta_max. This is the real-space analog ofcompute_cls();ibins,what,auto_only,shear_cols,randoms_per_galaxy,seedandsubsamplehave the same meaning there.- Parameters:
ibins (int or array_like of int or None, optional) – Tomographic bin indices to process. If None, uses all bins.
what ({'shear', 'clustering', 'shear_clustering', 'all'} or list of str, optional) –
Which correlations to compute:
’clustering’: galaxy density autocorrelation
w(theta), symmetric i>=j pairs.’shear’: shear autocorrelation
xi_+/-(theta), symmetric i>=j pairs.’shear_clustering’: density-shear cross-correlation
gamma_t/x(theta), all (i, j) ordered pairs since lens-bin i / source-bin j is not symmetric.’all’: compute all three. Default.
auto_only (bool, optional) – If True, restrict to same-bin pairs (i, i) only, skipping cross-bin correlations. Default is False.
pairs (list of tuple of int or None, optional) – If given, only compute these
(i, j)bin pairs, for every statistic inwhat(overridesibinsandauto_only). Only the catalogs of the bins involved are loaded.theta_min (float, optional) – Angular separation range, in
sep_units. Defaults are 1 and 100 arcmin.theta_max (float, optional) – Angular separation range, in
sep_units. Defaults are 1 and 100 arcmin.ntheta (int, optional) – Number of log-spaced angular bins. Default is 20.
sep_units (str, optional) – Units of
theta_min/theta_maxand of the returnedtheta. Default is ‘arcmin’.bin_slop (float or None, optional) – TreeCorr
bin_slop(binning approximation tolerance). If None, uses TreeCorr’s own default.angle_slop (float or None, optional) – TreeCorr
angle_slop(TreeCorr 5 and later): tolerance in radians on the projection angle of the pairs of the shear correlations, approximated by that of the centers of their cells. If None, uses TreeCorr’s own default (0.1).shear_cols (tuple of str, optional) – Names of the two catalog columns to use as the spin-2 shear field. See
compute_cls().shapes ({'shear', 'ia', 'shear_plus_ia', 'observed'}, optional) – Shapes of the shear legs, as in
predict_2pt(): the lensing shear (shear_cols, default), the intrinsic alignments (II and gI), their sum without shape noise (GG + GI + IG + II and gG + gI), or the observed ellipticities, with shape noise. The same galaxies are used for all (samesubsampleandseed), so that GI is exactly the difference of the first three.subsample (float or None, optional) – If not None, randomly draw (without replacement, seeded by
seed + ibin) this fraction of galaxies from each loaded catalog before building fields, with0 < subsample < 1. A random draw is used rather than a fixed stride, since galaxies are stored in a fixed (non-random) order and a stride would sample a specific, non-representative pattern. Default is None (no subsampling).remove_mean (bool, optional) – If True (default), subtract the mean of the shear columns over each bin before the measurement.
randoms_per_galaxy (int, optional) – Ratio of random points to galaxies for each bin’s random catalog, used for the Landy-Szalay
w(theta)estimator and for subtracting additive bias ingamma_t/x(theta). Default is 5.randoms_shared (bool, optional) – If True (default), draw a single random-point realization (sized from the galaxies of the first bin, whatever the bins computed) and reuse it for every bin’s random catalog (used both for the
w(theta)estimator and for thegamma_t/x(theta)random-lens subtraction), rather than drawing independent randoms per bin. This matches the fact that all bins share the same survey footprint, and is cheaper since randoms (and their TreeCorr catalog/tree) are only built once. If False, each bin gets its own randoms, seeded byseed + ibin.seed (int or None, optional) – Seed for the random catalogs’ RNG. Default is the shell builder’s seed.
error_bars (bool, optional) – If True, also return
dxi: standard deviations (shot-noise error bars from TreeCorr), with the same structure asxi. Default is False.theta_per_pair (bool, optional) – If True, return
thetaas a dict with the same structure asxi(each pair’s own mean separation from its correlation object’smeanlogr) instead of a single shared array. The exact mean separation is catalog-dependent and can differ slightly from one pair to another; this is always what gets written to the SACC file regardless of this flag. Default is False (return a single array, taken from the first pair computed).save (bool, optional) – If True (default), save the correlation functions to a SACC FITS file via
_write_2pt(), atcat_2pt[_{shapes}].fitsof the catalogs (cat_2pt_{shapes}.fitsfor shapes other than'shear').
- Returns:
theta (ndarray or dict) – Mean angular separation, in
sep_units. A single shared array, or a dict keyed likexiiftheta_per_pair=True.xi (dict) – Keyed by SACC data type (e.g.
'galaxy_density_xi','galaxy_shear_xi_plus','galaxy_shear_xi_minus','galaxy_shearDensity_xi_t','galaxy_shearDensity_xi_x', depending onwhat), each mapping to a dict keyed by(i, j).dxi (dict) – Only with
error_bars: shot-noise error bars, keyed likexi.
- Return type:
- read_2pt(return_dict=False, return_errors=False, shapes='shear')[source]¶
Read catalog-based two-point functions previously saved by
_write_2pt().- Parameters:
return_dict (bool, optional) – If True, return
(theta, xi). Otherwise, return the SACC object.return_errors (bool, optional) – With
return_dict, also return the error bars (square root of the diagonal of the saved covariance), with the same structure asxi.shapes (str, optional) – Shapes of the shear legs of the measurement (see
compute_2pt()).
- Returns:
If
return_dict=False, returns the loaded SACC object. Ifreturn_dict=True, returns(theta, xi), both dicts keyed by SACC data type then by(i, j)(same structure astheta_pairs/xiincompute_2pt(); each pair’s own mean separation is preserved, since it is catalog-dependent). Reads only the data types and tracer pairs actually present in the file (compute_2pt()may not have computed all of them), with no dependency onself.lensingbeyond the file path.- Return type:
- predict_2pt(theta, nell=500, *, shapes='shear', pixel_window=True)[source]¶
Predict the catalog two-point correlation functions.
Predictions use the matter power spectrum of the catalog’s shells (see
predict_cls()).- Parameters:
theta (dict) – Angular separations in arcmin keyed by SACC data type, then by
(i, j)(as returned byread_2pt()orcompute_2pt()withtheta_per_pair=True).nell (int, optional) – Number of log-spaced multipoles up to the bandpower
lmaxused for the Hankel transforms.shapes ({'shear', 'ia', 'shear_plus_ia', 'observed'}, optional) – Shapes of the shear legs:
'shear'(default), the lensing shear (columnsgamma1,gamma2);'ia', the intrinsic alignments alone (II, gI; columnse1_ia_*,e2_ia_*);'shear_plus_ia', their sum without shape noise (GG + GI + IG + II for cosmic shear, gG + gI for galaxy-galaxy lensing);'observed', the observed ellipticitiese1_obs,e2_obs(with shape noise, of zero mean), predicted as'shear_plus_ia', or as'shear'without intrinsic alignments (include_iaofCatalogAugmentorShear). Seeia_tracers.pixel_window (bool, optional) – If True (default), multiply the spectra by the pixel window of the maps (one per field), as
predict_cls(): galaxies are placed in the pixels of the density maps, and the fields are interpolated from pixelized maps.
- Returns:
Same structure as
theta;galaxy_shearDensity_xi_xis zero.- Return type:
- plot_2pt(plot_dir=None, *, modes=('values', 'ratio'), reference=None, xlim=None, shapes='shear')[source]¶
Plot the saved two-point functions against their prediction (
predict_2pt()), one panel per bin pair.- Parameters:
plot_dir (str or None, optional) – Output directory. Default is
{catalog_dir}/plots.modes (tuple of str, optional) – Plots to make, see
pollux.statistics.plotting.plot_pairs()('values','ratio','diff_over_error', with the measurement errors). Default is('values', 'ratio'). Values are multiplied bytheta.reference (CatalogGenerator or None, optional) – Catalog with saved two-point functions (e.g. dark-matter-only, for a baryonified catalog): adds the
'ratio_to_reference'mode, the ratio of the two catalogs’ functions against the ratio of their predictions.xlim (tuple of float or None, optional) – Limits of the x axis, e.g. the edges of the binning,
(theta_min, theta_max)ofcompute_2pt(). Default is the range of the measuredtheta.shapes ({'shear', 'ia', 'shear_plus_ia', 'observed'}, optional) – Shapes of the shear legs of the measurement (see
compute_2pt()).
- Return type:
None
Notes
Saves, with suffix
_{mode}for modes other than'values', auto-correlations named after their field and cross-correlations{field}_x_{field}:xi_shear,xi_shear_x_densityandxi_densityfor the lensing shear;xi_ia(II) andxi_ia_x_density(gI) for the intrinsic alignments, andxi_shear_x_ia(GI: shear plus IA, minus shear, minus IA, when the three are measured);xi_shear_plus_iaandxi_shear_plus_ia_x_densityfor the sum of the shear and IA (without shape noise);xi_observedandxi_observed_x_densityfor the observed ellipticities (with shape noise).
Plots¶
Plots of two-point statistics of bin pairs against their predictions (plot_pairs()), for the maps and catalogs.
- pollux.statistics.plotting.ell_factor_of(x, ell_factor)[source]¶
Return the factor multiplying spectra or correlation functions in plots.
- Parameters:
x (ndarray) – Multipoles or angular separations.
ell_factor ({0, 1, 2}) – 0: 1, 1:
x, 2:x (x + 1) / 2 pi.
- Return type:
float or ndarray
- pollux.statistics.plotting.plot_pairs(x, data=None, theory=None, data_errors=None, theory_errors=None, data_ref=None, theory_ref=None, mode='values', nbins=None, auto_only=False, ell_factor=0, scales=None, color_scales='0.2', color='dodgerblue', color_theory=None, label=None, logx=True, logy=False, xlim=None, ylim=None, xlabel='$\\ell$', ylabel=None, title='bins {i} {j}', sharey='row', figaxes=None, fname=None)[source]¶
Plot two-point statistics of bin pairs, one panel per pair.
Panels are laid out on a
nbins x nbinsgrid, with pair(i, j)in rowiand columnj(or, withauto_only, auto-pairs in order on a near-square grid); panels without any pair are hidden. Data are plotted as points and theory as lines.- Parameters:
x (ndarray or dict) – Multipoles or angular separations, shared by all pairs or keyed by
(i, j).data (dict or None, optional) – Measured and predicted statistics keyed by
(i, j).theory (dict or None, optional) – Measured and predicted statistics keyed by
(i, j).data_errors (dict or None, optional) – Error bars on the data (plotted as error bars) and on the theory (plotted as bands).
theory_errors (dict or None, optional) – Error bars on the data (plotted as error bars) and on the theory (plotted as bands).
data_ref (dict or None, optional) – Reference data and theory for
mode='ratio_to_reference'.theory_ref (dict or None, optional) – Reference data and theory for
mode='ratio_to_reference'.mode ({'values', 'ratio', 'diff_over_error', 'ratio_to_reference'}, optional) –
'values'(default): data and theory, multiplied by theell_factor;'ratio':data / theory - 1(with the relative theory errors as a band), with values beyond +-1 shown at +-1 as arrows (bounds), also in'ratio_to_reference';'diff_over_error':(data - theory) / sigma, withsigmathe theory errors if given, else the data errors;'ratio_to_reference':data / data_ref - 1andtheory / theory_ref - 1.
nbins (int or None, optional) – Number of bins. Default is one more than the largest bin index.
auto_only (bool, optional) – If True, only plot auto-pairs
(i, i).ell_factor ({0, 1, 2}, optional) – Factor of the values in
'values'mode, seeell_factor_of().scales (dict or None, optional) – Reference scales (e.g.
pollux.statistics.maps.MapStatistics.reference_scales()), per bin:ell_smooth/ell_box/ell_res(ortheta_smooth/theta_box/theta_resifxlabeldoes not containell), marked at the geometric mean of the two bins (or per pair, for a dict keyed by(i, j)) with dotted, dashed and dash-dotted lines, named in a legend below the figure when within the x range.color_scales (str, optional) – Color of the reference-scale lines (e.g. that of the data, when overplotting several sets).
color (str, optional) – Colors of the data and theory.
color_theorydefaults tocolor.color_theory (str, optional) – Colors of the data and theory.
color_theorydefaults tocolor.label (str or None, optional) – Name of the statistic in the legend below the figure (e.g. to tell apart statistics overplotted by several calls with
figaxes), with its color.logx (bool, optional) – Logarithmic axes.
logyonly applies to'values'mode.logy (bool, optional) – Logarithmic axes.
logyonly applies to'values'mode.xlim (tuple or None, optional) – Limits of the x and y axes.
xlimdefaults to the range ofx.ylim (tuple or None, optional) – Limits of the x and y axes.
xlimdefaults to the range ofx.xlabel (str or None, optional) – Axis labels.
ylabeldefaults to a label of the mode (ofC_elland theell_factorin'values'mode).ylabel (str or None, optional) – Axis labels.
ylabeldefaults to a label of the mode (ofC_elland theell_factorin'values'mode).title (str, optional) – Panel titles, formatted with
iandj.sharey (bool or str, optional) – Passed to
matplotlib.pyplot.subplots(). Default is'row'.figaxes (tuple or None, optional) – Existing
(fig, axes)from a previous call to draw into (e.g. another statistic in another color).fname (str or None, optional) – If given, save the figure to this file and close it.
- Return type:
fig, axes