Calibration Utilities

These tools are for calibrating cosmic shear measurements using various schemes.

class txpipe.utils.calibration_tools.HSCCalculator(selector)[source]

This class builds up the total response calibration factors for HSC-convention shear-calibration from each chunk of data it is given. At the end an MPI communicator can be supplied to collect together the results from the different processes.

add_data(data, *args, **kwargs)[source]

Select objects from a new chunk of data and tally their responses

Parameters:
  • data (dict) – Dictionary of data columns to select on and add

  • *args – Positional arguments to be passed to the selection function

  • **kwargs – Keyword arguments to be passed to the selection function

collect(comm=None, allgather=False)[source]

Finalize and sum up all the response values, returning calibration quantities.

Parameters:

comm (MPI Communicator) – If supplied, all processors response values will be combined together. All processes will return the same final value

Returns:

  • R (float) – R calibration factor

  • K (float) – K = (1+m) calibration

  • N (int) – Total object count

class txpipe.utils.calibration_tools.LensfitCalculator(selector, input_m_is_weighted=False)[source]

This class builds up the total calibration factors for lensfit-convention shears from each chunk of data it is given. Note here we derive the c-terms from the data (in constrast to averaging values derived from simulations and stored in the catalog.) At the end an MPI communicator can be supplied to collect together the results from the different processes.

add_data(data, *args, **kwargs)[source]

Select objects from a new chunk of data and tally their responses

Parameters:
  • data (dict) – Dictionary of data columns to select on and add

  • *args – Positional arguments to be passed to the selection function

  • **kwargs – Keyword arguments to be passed to the selection function

collect(comm=None, allgather=False)[source]

Finalize and sum up all the response values, returning calibration quantities.

Parameters:

comm (MPI Communicator) – If supplied, all processors response values will be combined together. All processes will return the same final value

Returns:

  • K (float) – K = (1+m) calibration

  • C (float array) – c1, c2 additive biases (weighted average of g1 and g2)

class txpipe.utils.calibration_tools.MetacalCalculator(selector, delta_gamma)[source]

This class builds up the total response and selection calibration factors for Metacalibration from each chunk of data it is given. At the end an MPI communicator can be supplied to collect together the results from the different processes.

To do this we need the function used to select the data, and the instance this function to each of the metacalibrated variants automatically by wrapping the data object passed in to it and modifying the names of columns that are looked up.

add_data(data, *args, **kwargs)[source]

Select objects from a new chunk of data and tally their responses

Parameters:
  • data (dict) – Dictionary of data columns to select on and add

  • *args – Positional arguments to be passed to the selection function

  • **kwargs – Keyword arguments to be passed to the selection function

collect(comm=None, allgather=False)[source]

Finalize and sum up all the response values, returning separate R (estimator response) and S (selection bias) 2x2 matrices :param comm: If supplied, all processors response values will be combined together.

All processes will return the same final value

Returns:

  • R (2x2 array) – Estimator response matrix

  • S (2x2 array) – Selection bias matrix

txpipe.utils.calibration_tools.read_shear_catalog_type(stage)[source]

Determine the type of shear catalog a stage is using as input. Returns a string, e.g. metacal, lensfit. Also sets shear_catalog_type in the stage’s configuration so that it is available later and is saved in output.

class txpipe.utils.calibrators.Calibrator[source]

Base class for classes which calibrate shear measurements.

These classes do not calculate the calibration factors - that is done by the Calculator classes in calibration_tools.py. Instead they apply the calibrations after they have been calculated.

Subclasses do the actual work. The base classis only useful for the load class method, which chooses the correct subclass depending on the file it is given.

classmethod load(tomo_file, null=False)[source]

Load a set of Calibrator objects from a tomography file. These will be instances of a subclass of Calibrator, depending on the file contents. Returns a list of calibrators, one for each the source bins, and one for the overall 2D bin.

Parameters:
  • tomo_file (str) – The name of the tomography file to load

  • null – Whether to ignore the tomo file type and return null calibrators. Useful for “calibrating” true shears

Returns:

  • cals (list) – A set of Calibrators, one per bin

  • cal2D (Calibrator) – A single Calibrator for the 2D bin

class txpipe.utils.calibrators.HSCCalibrator(R, K)[source]
apply(g1, g2, c1, c2)[source]

For HSC (see Mandelbaum et al., 2018, arXiv:1705.06745): gi = 1/(1 + mhat)[ei/(2R) - ci] (Eq. (A6) in Mandelbaum et al., 2018) R = 1 - < e_rms^2 >w (Eq. (A1) in Mandelbaum et al., 2018) mhat = < m >w (Eq. (A2) in Mandelbaum et al., 2018) (we call this K)

Parameters:
  • g1 (array or float) – Shear 1 component

  • g2 (array or float) – Shear 2 component

  • c1 (array or float) – Shear 1 additive bias component

  • c2 (array or float) – Shear 2 additive bias component

classmethod load(tomo_file)[source]

Make a set of HSC calibrators using the info in a tomography file.

You can use the parent Calibrator.load to automatically load the correct subclass.

Parameters:

tomo_file (str) – A tomography file name the cal factors are read from

Returns:

  • cals (list) – A set of HSCCalibrators, one per bin

  • cal2D (HSCCalibrator) – A single HSCalibrator for the 2D bin

class txpipe.utils.calibrators.LensfitCalibrator(K, c)[source]
apply(g1, g2, subtract_mean=True)[source]

For KiDS (see Joachimi et al., 2020, arXiv:2007.01844): Appendix C, equation C.4 and C.5 Correcting for multiplicative shear calibration. Additionally optionally correct for residual additive bias (true for KiDS-1000 and KV450.)

The c term is only included if subtract_mean = True

Parameters:
  • g1 (array or float) – Shear 1 component

  • g2 (array or float) – Shear 2 component

  • subtract_mean (bool) – whether to subtract the constant c term (default True)

classmethod load(tomo_file)[source]

Make a set of Lensfit calibrators using the info in a tomography file.

You can use the parent Calibrator.load to automatically load the correct subclass.

Parameters:

tomo_file (str) – A tomography file name the cal factors are read from

Returns:

  • cals (list) – A set of LensfitCalibrators, one per bin

  • cal2D (LensfitCalibrator) – A single LensfitCalibrator for the 2D bin

class txpipe.utils.calibrators.MetaCalibrator(R, S, mu, mu_is_calibrated=True)[source]
apply(g1, g2, subtract_mean=True)[source]

Calibrate a set of shears using the response matrix and mean shear subtraction.

Parameters:
  • g1 (array or float) – Shear 1 component

  • g2 (array or float) – Shear 2 component

  • subtract_mean (bool) – whether to subtract mean shear (default True)

classmethod load(tomo_file)[source]

Make a set of Metacal calibrators using the info in a tomography file.

You can use the parent Calibrator.load to automatically load the correct subclass.

Parameters:

tomo_file (str) – A tomography file name the cal factors are read from

Returns:

  • cals (list) – A set of MetaCalibrators, one per bin

  • cal2D (MetaCalibrator) – A single MetaCalibrator for the 2D bin

class txpipe.utils.calibrators.MetaDetectCalibrator(R, mu, mu_is_calibrated=True)[source]
classmethod load(tomo_file)[source]

Make a set of MetaDetect calibrators using the info in a tomography file.

You can use the parent Calibrator.load to automatically load the correct subclass.

Parameters:

tomo_file (str) – A tomography file name the cal factors are read from

Returns:

  • cals (list) – A set of MetaDetectCalibrators, one per bin

  • cal2D (MetaCalibrator) – A single MetaDetectCalibrator for the 2D bin

class txpipe.utils.calibrators.NullCalibrator(mu=None)[source]

This calibrator subclass does nothing - it’s designed

apply(g1, g2, subtract_mean=False)[source]

“Calibrate” a set of shears.

As this is a null calibrator it just returns a copy of them

Parameters:
  • g1 (array or float) – Shear 1 component

  • g2 (array or float) – Shear 2 component

  • subtract_mean (bool) – this is ignored but is here for consistency with other classes

classmethod load(tomo_file)[source]

Make a set of null calibrators.

You can use the parent Calibrator.load to automatically load the correct subclass.

Parameters:

tomo_file (str) – A tomography file name. Used only to get nbin

Returns:

  • cals (list) – A set of Calibrators, one per bin

  • cal2D (NullCalibrator) – A single Calibrator for the 2D bin