Catalog

Generates tomographic galaxy catalogs from lightcone shells using uniform or clustered sampling methods, with augmentors adding columns to them (e.g. reduced shear and observed ellipticities). Their statistics are in Statistics.

Tomographic source catalogs from the shells and lensing maps, by uniform or clustered sampling of the galaxies.

Their two-point statistics (Cls with NaMaster, two-point functions with TreeCorr) and predictions are methods inherited from CatalogStatistics.

class pollux.catalog.CatalogGenerator(lensing, tag=None, *, nbar_input, interp_fields=('kappa', 'gamma1', 'gamma2'), interp_method='bilinear', smooth_fields=('positions', 'density', 't11', 't22', 't12'), smooth_Mpc=None, augmentors=None, cls_b=None, cls_lmax_mask=None, catalog_format='hdf5')[source]

Bases: CatalogStatistics, ABC

Generic generator for mock source-galaxy catalogs for lensing analyses.

This class generates positions and redshifts for galaxies in each tomographic bin and interpolates lensing quantities (e.g. kappa/gamma) from maps produced by a lensing builder.

Parameters:
  • lensing (LensingBuilder) – Lensing map builder used to define tomographic bins and provide maps to interpolate.

  • tag (str or None, optional) – Tag of the catalogs: they go to catalogs/{nz}/{tag}/ next to the maps (see pollux.io.files.PolluxIO), default if None.

  • nbar_input (float or array-like) – Galaxy surface density in gal/arcmin^2 (required, keyword only). If a float, the same surface density is used for all tomographic bins; if an array-like, it must have length lensing.nmaps and provide a per-bin value.

  • interp_fields (tuple of str, optional) – Fields interpolated at the galaxies, among FIELDS ('kappa', 'gamma1', 'gamma2', 'density', 't11', 't22', 't12'); the fields required by the augmentors are added. Default is ('kappa', 'gamma1', 'gamma2').

  • interp_method ({'bilinear', 'nearest'}, optional) – Interpolation of the maps at the galaxy positions: bilinear across pixels (default), or the value of the nearest pixel.

  • smooth_fields (tuple of str, optional) – Fields read from their maps smoothed by smooth_Mpc, among FIELDS and 'positions' (the density contrast used to place galaxies). Default is ('positions', 'density', 't11', 't22', 't12'). The smoothed maps are made by the builders (compute_maps_from_alms(), compute_tidal_tensor_maps(), compute_shear_maps()).

  • smooth_Mpc (float, array-like, dict or None, optional) – Comoving Gaussian smoothing scale in Mpc of smooth_fields, or one scale per shell (e.g. lognormal_smoothing()), or a dict of either per field (then smooth_fields is ignored, and fields not in the dict are not smoothed). None (default) means no smoothing. Fields made together (t11, t22, t12; gamma1, gamma2) must share their scale.

  • augmentors (list, optional) – List of catalog augmentors. Default is empty list.

  • cls_b (pymaster.NmtBin or None, optional) – Binning of compute_cls() and predict_cls(), whose lmax is the maximum multipole of the catalog fields and workspaces. Default is the shell builder’s binning (see b).

  • cls_lmax_mask (int or None, optional) – Maximum multipole of the fields’ masks (at least the lmax of b). Default is that lmax.

  • catalog_format ({'hdf5', 'fits'}, optional) – Format of the catalog files (pollux.io.files.PolluxIO.write_columns()). 'hdf5' (default): the columns in a catalog group, with each bin also laid out as a bin of TXPipe’s binned shear and lens catalogs (shear/bin_{b}, lens/bin_{b}, linking the columns without copying them), gathered in binned_catalog.hdf5, the binned_shear_catalog and binned_lens_catalog of TXPipe. 'fits': a FITS table per bin.

Variables:
  • Ngal (ndarray of int) – Number of galaxies drawn per tomographic bin over the footprint (nbar times its area).

  • nbar_per_pix (ndarray) – Mean expected counts per pixel per tomographic bin.

  • metadata (dict) – Metadata stored in the catalog files (FITS header keywords, or HDF5 attributes): galaxy densities and bias, and the code version, POLLUXV (git commit) and DIRTY (uncommitted changes).

FIELDS = ('kappa', 'gamma1', 'gamma2', 'density', 't11', 't22', 't12')
SHELL_FIELDS = ('density', 't11', 't22', 't12')
CATALOG_FORMATS = ('hdf5', 'fits')
config()[source]

Return the configuration of the catalogs, for their config.yaml (pollux.io.config.write_config()).

Returns:

product ('catalogs'), parameters (generator, galaxy densities and bias, interpolated fields and their smoothing, augmentors: their CatalogAugmentor.config()) and inputs (the convergence maps of the n(z) and per shell, shells and smoothed maps).

Return type:

dict

property columns: list[str]

positions, redshift and distance, interpolated fields, and those of the augmentors.

Type:

Columns of the catalogs

path(ibin, ext=None, ishell=None)[source]

Return the path for the saved catalog of one tomographic bin.

Parameters:
  • ibin (int) – Tomographic-bin index.

  • ext (str or None, optional) – File extension without the leading dot. Default is that of catalog_format ('hdf5' or 'fits').

  • ishell (int or None, optional) – If given, path of the catalog of shell ishell (generate() with ishell).

Returns:

{catalog_dir}/cat_bin{ibin}.{ext}, with catalog_dir the catalogs/{nz}/{tag} directory of the maps’ products (see pollux.io.files), or {intermediate}/shells/cat_bin{ibin}_{ishell:03d}.{ext} for the catalog of one shell.

Return type:

str

property path_txpipe: str

File gathering the bins as TXPipe’s binned shear and lens catalogs (HDF5 catalogs, see catalog_format).

property path_nzs: str

File of the redshift distributions of the bins (nzs) in qp’s format, the shear_photoz_stack and lens_photoz_stack inputs of TXPipe (HDF5 catalogs).

property nzs: tuple[ndarray, ndarray]

those of the lensing builder up to the far edge of the last shell, normalized, on the union of their grids (piecewise linear).

Returns:

  • z (ndarray) – Redshift grid.

  • nzs (ndarray) – Distributions, shape (nbins, len(z)).

Type:

Redshift distributions of the galaxies of the bins, as they are drawn

classmethod smoothing_scales(smooth_fields, smooth_Mpc, nshells)[source]

Return the smoothing scale of every field and shell (see smooth_fields and smooth_Mpc).

Parameters:
  • smooth_fields (tuple of str) – Fields smoothed by smooth_Mpc.

  • smooth_Mpc (float, array-like, dict or None) – Smoothing scale, one scale per shell, or either per field.

  • nshells (int) – Number of shells.

Returns:

Tuple of the scales (Mpc, or None if not smoothed) of the shells, for each of FIELDS and 'positions', e.g. to schedule the smoothed maps needed by a catalog.

Return type:

dict

generate(ibins=None, ishell=None)[source]

Generate mock catalogs and interpolate requested map quantities.

Parameters:
  • ibins (int or array_like of int or None, optional) – Tomographic-bin indices to generate. If None, generate for all bins.

  • ishell (int or None, optional) – If given, only generate the galaxies of shell ishell and save them as the catalogs of the shell (one per bin), to be merged with merge_shell_catalogs(). Only supported by subclasses drawing galaxies shell by shell (CatalogClusteredPoisson).

Return type:

None

Notes

The generation proceeds in four steps: 1) draw galaxies (positions/redshifts and shell membership), 2) interpolate requested fields from maps, 3) apply the augmentors, 4) write one file per tomographic bin (catalog_format).

merge_shell_catalogs(ibins=None)[source]

Merge the catalogs of the shells (generate() with ishell, saved in shells/) into one catalog per bin.

Parameters:

ibins (int or array_like of int or None, optional) – Tomographic-bin indices to merge. If None, merge all bins.

Return type:

None

Notes

Partial catalogs are produced by generate() with ishell and are concatenated in shell order, which gives the same catalog as generating all shells at once.

read_catalogs(ibins=None, return_metadata=False, subsample=None, seed=None, columns=None, remove_mean=None)[source]

Read the catalogs of one or more tomographic bins, in either format.

Parameters:
  • ibins (int or array_like of int or None, optional) – Tomographic-bin indices to load. If None, loads all bins.

  • return_metadata (bool, optional) – If True, also return the metadata of the files (pollux.io.files.PolluxIO.read_columns_info()).

  • subsample (float or None, optional) – If not None, randomly draw (without replacement, seeded by seed + ibin) this fraction of galaxies from each loaded catalog, with 0 < 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).

  • seed (int or None, optional) – Seed for the subsampling RNG. Only used when subsample is not None. Default is the shell builder’s seed.

  • columns (list of str or None, optional) – Columns to read. If None (default), all columns.

  • remove_mean (list of str or None, optional) – Columns whose mean over each loaded catalog is subtracted.

Returns:

  • metadata (dict, optional) – Only if return_metadata=True: of the bin if ibins is a single int, otherwise a dict keyed by bin index.

  • catalog (dict) – Arrays by column name if ibins is a single int, otherwise a dict of them keyed by bin index.

Return type:

dict | tuple[dict, dict]

class pollux.catalog.CatalogUniform(lensing, tag=None, *, nbar_input, interp_fields=('kappa', 'gamma1', 'gamma2'), interp_method='bilinear', smooth_fields=('positions', 'density', 't11', 't22', 't12'), smooth_Mpc=None, augmentors=None, cls_b=None, cls_lmax_mask=None, catalog_format='hdf5')[source]

Bases: CatalogGenerator

Generate source galaxies uniformly over the footprint.

Redshifts are drawn from the tomographic tracer distributions. Angular positions are drawn uniformly over the footprint of the maps.

Parameters:
  • lensing (LensingBuilder) – Lensing map builder.

  • tag (str or None, optional) – Tag of the catalogs: they go to catalogs/{nz}/{tag}/ next to the maps (see pollux.io.files.PolluxIO), default if None.

  • nbar_input (float or array-like) – Galaxy surface density in gal/arcmin^2, per bin or for all (required, keyword only).

  • interp_fields (tuple[str, ...]) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • interp_method (str) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • smooth_fields (tuple[str, ...]) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • smooth_Mpc (float | dict[str, float] | None) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • augmentors (list, optional) – List of augmentors. Default is empty list.

  • cls_b (nmt.NmtBin | None)

  • cls_lmax_mask (int | None)

  • catalog_format (str)

class pollux.catalog.CatalogClustered(lensing, tag=None, *, nbar_input, bias=None, bias_model='linear', interp_fields=('kappa', 'gamma1', 'gamma2'), interp_method='bilinear', smooth_fields=('positions', 'density', 't11', 't22', 't12'), smooth_Mpc=None, augmentors=None, cls_b=None, cls_lmax_mask=None, catalog_format='hdf5')[source]

Bases: CatalogGenerator

Base class for clustered source galaxy catalogs.

This class provides common functionality for generating clustered catalogs where galaxy positions are biased by a density field.

Parameters:
  • lensing (LensingBuilder) – Lensing map builder.

  • tag (str or None, optional) – Tag of the catalogs: they go to catalogs/{nz}/{tag}/ next to the maps (see pollux.io.files.PolluxIO), default if None.

  • nbar_input (float or array-like) – Galaxy surface density in gal/arcmin^2, per bin or for all (required, keyword only).

  • bias (float or array-like, optional) – Galaxy bias per tomographic bin. If a float, the same bias is used for all tomographic bins; if an array-like, it must have length lensing.nmaps and provide a per-bin value.

  • bias_model ({'linear', 'power_law'}, optional) –

    Relative galaxy density per pixel, given the density contrast delta (see _density_weight()):

    • 'linear' (default): 1 + b * delta, clipped at zero where negative (underdense pixels with b > 1);

    • 'power_law': (1 + delta)**b / <(1 + delta)**b>, the mean over the footprint pixels of the shell, positive everywhere (no clipping), and with linear bias b on large scales.

  • interp_fields (optional) – Interpolation and smoothing of the fields (including the density used to place galaxies, 'positions'), see CatalogGenerator.

  • interp_method (optional) – Interpolation and smoothing of the fields (including the density used to place galaxies, 'positions'), see CatalogGenerator.

  • smooth_fields (optional) – Interpolation and smoothing of the fields (including the density used to place galaxies, 'positions'), see CatalogGenerator.

  • smooth_Mpc (optional) – Interpolation and smoothing of the fields (including the density used to place galaxies, 'positions'), see CatalogGenerator.

  • augmentors (list, optional) – List of augmentors applied after map interpolation. Default is empty list.

  • cls_b (optional) – Binning of the catalog angular power spectra, see CatalogGenerator.

  • cls_lmax_mask (optional) – Binning of the catalog angular power spectra, see CatalogGenerator.

  • catalog_format ({'hdf5', 'fits'}, optional) – Format of the catalog files, see CatalogGenerator.

BIAS_MODELS = ('linear', 'power_law')
class pollux.catalog.CatalogClusteredMultinomial(lensing, tag=None, *, nbar_input, bias=None, bias_model='linear', interp_fields=('kappa', 'gamma1', 'gamma2'), interp_method='bilinear', smooth_fields=('positions', 'density', 't11', 't22', 't12'), smooth_Mpc=None, augmentors=None, cls_b=None, cls_lmax_mask=None, catalog_format='hdf5')[source]

Bases: CatalogClustered

Generate clustered source galaxies using multinomial sampling.

The total number of galaxies per tomographic bin is fixed, and positions are drawn per shell from a multinomial distribution over pixels, proportional to the relative density of the bias model (1 + b * delta by default, where delta is the density contrast field, see CatalogClustered).

Parameters:
  • lensing (LensingBuilder) – Lensing map builder.

  • tag (str or None, optional) – Tag of the catalogs: they go to catalogs/{nz}/{tag}/ next to the maps (see pollux.io.files.PolluxIO), default if None.

  • nbar_input (float or array-like) – Galaxy surface density in gal/arcmin^2, per bin or for all (required, keyword only).

  • bias (optional) – Galaxy bias per tomographic bin, and bias model, see CatalogClustered.

  • bias_model (optional) – Galaxy bias per tomographic bin, and bias model, see CatalogClustered.

  • interp_fields (tuple[str, ...]) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • interp_method (str) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • smooth_fields (tuple[str, ...]) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • smooth_Mpc (float | dict[str, float] | None) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • augmentors (list, optional) – List of augmentors. Default is empty list.

  • cls_b (nmt.NmtBin | None)

  • cls_lmax_mask (int | None)

  • catalog_format (str)

class pollux.catalog.CatalogClusteredPoisson(lensing, tag=None, *, nbar_input, bias=None, bias_model='linear', interp_fields=('kappa', 'gamma1', 'gamma2'), interp_method='bilinear', smooth_fields=('positions', 'density', 't11', 't22', 't12'), smooth_Mpc=None, augmentors=None, cls_b=None, cls_lmax_mask=None, catalog_format='hdf5')[source]

Bases: CatalogClustered

Generate clustered source galaxies using Poisson sampling.

In each shell and tomographic bin, the number of galaxies per pixel is drawn as a Poisson random variable with mean <nbar> times the relative density of the bias model (1 + b * delta by default, see CatalogClustered). The total number of galaxies therefore fluctuates.

Parameters:
  • lensing (LensingBuilder) – Lensing map builder.

  • tag (str or None, optional) – Tag of the catalogs: they go to catalogs/{nz}/{tag}/ next to the maps (see pollux.io.files.PolluxIO), default if None.

  • nbar_input (float or array-like) – Galaxy surface density in gal/arcmin^2, per bin or for all (required, keyword only).

  • bias (optional) – Galaxy bias per tomographic bin, and bias model, see CatalogClustered.

  • bias_model (optional) – Galaxy bias per tomographic bin, and bias model, see CatalogClustered.

  • interp_fields (tuple[str, ...]) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • interp_method (str) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • smooth_fields (tuple[str, ...]) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • smooth_Mpc (float | dict[str, float] | None) – Interpolation and smoothing of the fields, see CatalogGenerator.

  • augmentors (list, optional) – List of augmentors. Default is empty list.

  • cls_b (nmt.NmtBin | None)

  • cls_lmax_mask (int | None)

  • catalog_format (str)

Notes

In shell \(i\) and bin \(j\), pixel \(p\) gets

\[N_p \sim \mathrm{Poisson}\left(\bar N_{ij}\, w(\delta_p)\right), \qquad \bar N_{ij} = \bar n_j\, \Omega_{\rm pix} \frac{\int_{z_i}^{z_{i+1}} n_j(z)\, dz}{\sum_k \int_{z_k}^{z_{k+1}} n_j(z)\, dz},\]

with \(\bar n_j\) the density of the bin (nbar_input), \(w\) the relative density of _density_weight(), and \(\delta_p\) the density contrast smoothed for the positions. Galaxies are placed uniformly within their pixel, at redshifts drawn from \(n_j(z)\) within the shell.

class pollux.catalog.CatalogAugmentor[source]

Bases: ABC

Base class for catalog augmentors that add fields to existing catalogs.

Subclasses must implement the augment_catalog method and set self.name, self.required_interp_fields, and self.new_columns in their __init__.

kind: str | None = None
config()[source]

Return the type and parameters of the augmentor, for the config.yaml of the catalogs.

Returns:

type (the class of the augmentor), extended by subclasses with their parameters.

Return type:

dict

abstractmethod augment_catalog(cosmo, catalog, **kwargs)[source]

Add the augmentor’s columns to the catalog of one tomographic bin, in place.

Parameters:
  • cosmo (pyccl.Cosmology) – Cosmology.

  • catalog (dict[str, np.ndarray]) – Catalog of one tomographic bin.

  • **kwargs – Per-bin options (augmentor_kwargs of the catalog generator, e.g. ibin).

Return type:

None

class pollux.catalog.CatalogAugmentorShear(compute_reduced_shear=True, compute_magnification=False, generate_intrinsic=False, compute_observed=False, include_ia=True, sigma_e=0.3, seed=None)[source]

Bases: CatalogAugmentor

Augmentor that computes shear-derived quantities and shapes.

Options include reduced shear, magnification, intrinsic shapes, and observed shapes. Intrinsic alignment (IA) shear contributions are included when available and requested.

Parameters:
  • compute_reduced_shear (bool, optional) – If True, compute reduced shear g1, g2. Default is True.

  • compute_magnification (bool, optional) – If True, compute magnification mu. Default is False.

  • generate_intrinsic (bool, optional) – If True, generate random intrinsic shapes e1_int, e2_int. Default is False.

  • compute_observed (bool, optional) – If True, compute observed shapes by adding lensing and IA contributions to intrinsic shapes. Requires generate_intrinsic=True. Default is False.

  • include_ia (bool, optional) – If True, include IA contributions in lensed shapes. Default is True.

  • sigma_e (float, optional) – Standard deviation of the intrinsic ellipticity distribution. Default is 0.3.

  • seed (int or None, optional) – Extra seed of the intrinsic shapes, if not None. The shapes of the galaxies of tomographic bin ibin in shell ishell are drawn from a stream of their own, seeded by the seed of the realization (given by the catalog generator), ibin and ishell: they differ between realizations, and do not depend on how the catalog is split into shells. Default is None.

kind: str | None = 'shear'
config()[source]

Return the type and parameters of the augmentor, for the config.yaml of the catalogs.

The parameters setting the values of the shapes (sigma_e, include_ia, seed) are recorded when they differ from their defaults, so that the configurations of catalogs made before they were recorded stay valid.

Returns:

type and the parameters that differ from their defaults.

Return type:

dict

augment_catalog(cosmo, catalog, ibin=0, realization_seed=0, **kwargs)[source]

Compute derived shear quantities and add them to the catalog.

Parameters:
  • cosmo (pyccl.Cosmology) – Cosmology (unused).

  • catalog (dict[str, np.ndarray]) – Catalog of one tomographic bin, with 'kappa', 'gamma1', 'gamma2' and 'idx_shell'; updated in place.

  • ibin (int, optional) – Tomographic-bin index, used to seed the intrinsic shapes.

  • realization_seed (int, optional) – Seed of the realization (that of the shell builder), used to seed the intrinsic shapes.

  • **kwargs – Unused (other augmentor options).

Return type:

None