binny.nz.psf_selection module#

Calibration tools for PSF-selected galaxy redshift distributions.

This module provides utilities for modelling how survey depth and image quality change the effective source sample used in weak-lensing forecasts.

The main goal is to derive empirical redshift distributions and galaxy number densities from mock or simulated catalogs after applying both:

  • a magnitude-limit selection;

  • a PSF-dependent shear-selection weight.

These routines are intended for forecasting studies where changes in the PSF or limiting magnitude need to be propagated into source redshift distributions, tomographic samples, and selection-weighted galaxy densities.

binny.calibration.psf_selection.calibrate_psf_depth_from_mock(z_true: ndarray, mag: ndarray, r_gal: ndarray, *, maglims: ndarray, r_psf_values: ndarray, area_deg2: float, z_edges: ndarray, r_min: float = 0.3, selection_kind: Literal['hard', 'sigmoid'] = 'sigmoid', width: float = 0.05, normalize_nz: bool = True) → dict[str, Any]#

Calibrate source redshift distributions versus survey depth and PSF size.

This routine evaluates how the source redshift distribution and selection-weighted galaxy number density change across a grid of limiting magnitudes and PSF sizes. It is intended for forecasting studies that compare baseline and as-built survey scenarios.

Parameters:
  • z_true – True galaxy redshifts from the mock catalog.

  • mag – Apparent magnitudes of the same galaxies.

  • r_gal – Galaxy sizes of the same galaxies.

  • maglims – Limiting magnitudes to evaluate.

  • r_psf_values – PSF sizes to evaluate.

  • area_deg2 – Survey or mock area in square degrees.

  • z_edges – Redshift-bin edges used to histogram the selected samples.

  • r_min – Minimum resolution factor required for shear selection.

  • selection_kind – Selection model used to convert resolution into weights.

  • width – Width of the sigmoid transition for smooth selection.

  • normalize_nz – Whether to normalize each redshift distribution to unit area.

Returns:

Dictionary containing the calibration grid, redshift distributions, and selection-weighted galaxy densities.

Raises:
  • ValueError – If input catalog arrays do not have matching shapes.

  • ValueError – If area_deg2 is not positive.

binny.calibration.psf_selection.resolution_factor(r_gal: ndarray, r_psf: float) → ndarray#

Compute the resolution factor of galaxies relative to the PSF.

The resolution factor describes how well a galaxy is resolved compared with the point-spread function. Values close to zero correspond to poorly resolved galaxies, while values close to one correspond to well-resolved galaxies.

Parameters:
  • r_gal – Intrinsic or pre-seeing galaxy sizes.

  • r_psf – Characteristic PSF size in the same units as r_gal.

Returns:

Galaxy resolution factors.

Raises:

ValueError – If r_psf is negative.

binny.calibration.psf_selection.selected_number_density_from_mock(mag: ndarray, r_gal: ndarray, *, maglim: float, r_psf: float, area_deg2: float, r_min: float = 0.3, selection_kind: Literal['hard', 'sigmoid'] = 'hard', width: float = 0.05) → float#

Estimates the PSF-selected galaxy density from a mock catalog.

This function computes the selection-weighted source density after applying a magnitude limit and a PSF-dependent shear-selection weight. It does not include shape measurement noise and is therefore distinct from the noise-equivalent weak-lensing effective number density.

Parameters:
  • mag – Apparent magnitudes from the mock catalog.

  • r_gal – Galaxy sizes of the same galaxies.

  • maglim – Limiting magnitude used to define the source sample.

  • r_psf – Characteristic PSF size in the same units as r_gal.

  • area_deg2 – Survey or mock area in square degrees.

  • r_min – Minimum resolution factor required for shear selection.

  • selection_kind – Selection model used to convert resolution into weights.

  • width – Width of the sigmoid transition for smooth selection.

Returns:

Weighted galaxy number density in galaxies per arcmin².

Raises:
  • ValueError – If input catalog arrays do not have matching shapes.

  • ValueError – If area_deg2 is not positive.

binny.calibration.psf_selection.shear_selection_weight(r_gal: ndarray, *, r_psf: float, r_min: float = 0.3, kind: Literal['hard', 'sigmoid'] = 'sigmoid', width: float = 0.05) → ndarray#

Compute PSF-dependent shear-selection weights.

This function assigns each galaxy a weight describing whether it remains usable for shear measurements after accounting for PSF resolution. The selection can be either a hard resolution threshold or a smooth sigmoid transition around the threshold.

Parameters:
  • r_gal – Intrinsic or pre-seeing galaxy sizes.

  • r_psf – Characteristic PSF size in the same units as r_gal.

  • r_min – Minimum resolution factor required for shear selection.

  • kind – Selection model used to convert resolution into weights.

  • width – Width of the sigmoid transition when kind="sigmoid".

Returns:

Shear-selection weights between zero and one.

Raises:
  • ValueError – If r_min is outside [0, 1].

  • ValueError – If kind is not supported.

  • ValueError – If width is not positive for sigmoid selection.

binny.calibration.psf_selection.weighted_nz_from_mock(z_true: ndarray, mag: ndarray, r_gal: ndarray, *, maglim: float, r_psf: float, z_edges: ndarray, r_min: float = 0.3, selection_kind: Literal['hard', 'sigmoid'] = 'sigmoid', width: float = 0.05, normalize: bool = True) → tuple[ndarray, ndarray, ndarray, ndarray]#

Build a PSF-selected redshift distribution from a mock catalog.

This function estimates the source redshift distribution after applying a magnitude limit and a PSF-dependent shear-selection weight. It returns the selected redshifts, redshift-bin centers, weighted distribution, and selection weights.

Parameters:
  • z_true – True galaxy redshifts from the mock catalog.

  • mag – Apparent magnitudes of the same galaxies.

  • r_gal – Galaxy sizes of the same galaxies.

  • maglim – Limiting magnitude used to define the source sample.

  • r_psf – Characteristic PSF size in the same units as r_gal.

  • z_edges – Redshift-bin edges used to histogram the selected sample.

  • r_min – Minimum resolution factor required for shear selection.

  • selection_kind – Selection model used to convert resolution into weights.

  • width – Width of the sigmoid transition for smooth selection.

  • normalize – Whether to normalize the redshift distribution to unit area.

Returns:

Tuple containing selected redshifts, redshift-bin centers, the weighted redshift distribution, and selection weights.

Raises:
  • ValueError – If input catalog arrays do not have matching shapes.

  • ValueError – If z_edges does not contain at least two bin edges.