sp_validation.calibration¶
CALIBRATION.
- Name:
calibration.py
- Description:
This script contains methods for shear calibration.
- Author:
Martin Kilbinger
- get_calibrated_quantities(gal_metacal)[source]¶
Get Calibrated Quantities.
Return catalogue quantities for objects calibrated for multiplicative bias.
- Parameters:
gal_metacal (dict) – galaxy metacalibration catalogue
- Returns:
g_corr (array(2, ngal) of float) – shear estimates calibrated for multiplicative bias
g_uncorr (array(2, ngal) of float) – uncalibrated shear estimates
w (array of float) – weights
mask (array of bool) – mask to indicate valid objects in “no-shear” sample
- get_calibrated_m_c(gal_metacal, additive_correction=True)[source]¶
Get Calibrated C.
Return catalogue quantities for objects calibrated for multiplicative and additive bias.
- Parameters:
gal_metacal (dict) – galaxy metacalibration catalogue
additive_correction (bool, optional, default=True) – if False, do not subtract the additive bias c from the shear estimates; use for constant-shear image sims, where the mean shear is the signal (see issue #226). c and c_err are still computed and returned
- Returns:
numpy.ndarray – shear estimates calibrated for multiplicative and additive bias; array(2, ngal) of float
numpy.ndarray – uncalibrated shear estimates; array(2, ngal) of float
numpy.ndarray – weights; array of float
numpy.ndarray – mask to indicate valid objects in “no-shear” sample; array of bool
numpy.ndarray – additive bias for both components;
numpy.ndarray – error on the additive bias for both components
- create_bins(x, num_bins, type='log', x_min=None, x_max=None)[source]¶
Create Bins. Create bins for a given array. The bins are logarithmic by default.
- Parameters:
x (array) – Array to bin
num_bins (int) – Number of bins
type (str, optional) – Type of binning. Options are ‘log’ (defaults)
x_min (float, optional) – Minimum value of the bins. If None, the minimum value of x is used.
x_max (float, optional) – Maximum value of the bins. If None, the maximum value of x is used.
- cut_to_bins(df, key, num_bins, type='log', x_min=None, x_max=None)[source]¶
Cut To Bins.
Cut a given array into bins. Create a new column in the DataFrame with the binning.
- Parameters:
df (pandas.DataFrame) – DataFrame to cut
key (str) – Key to cut
num_bins (int) – Number of bins
type (str, optional) – Type of binning. Options are ‘log’ (default)
x_min (float, optional) – Minimum value of the bins. If None, the minimum value of x is used.
x_max (float, optional) – Maximum value of the bins. If None, the maximum value of x is used.
- Returns:
bin edges
- Return type:
- build_df(cat_gal)[source]¶
Build DF.
Build pandas dataframe.
- Parameters:
cat_gal (dict) – input data
- Returns:
collected data
- Return type:
pd.DataFrame
- get_w_des(cat_gal, num_bins, snr_min=None, snr_max=None, size_ratio_min=None, size_ratio_max=None)[source]¶
Get DES weights. (Gatti et al. 2021) Return an array of DES weights obtained by binning in SNR and size and computing the ratio between the shear response and the shape noise.
- Parameters:
cat_gal (dict) – A catalog of galaxies containing the response matrix and the uncalibrated ellipticities
num_bins (int) – Number of bins to use for the binning of the SNR and size.
snr_min (float, optional) – Minimum SNR, default (None): determined by the data
snr_max (float, optional) – Maximum SNR, default (None): determined by the data
size_ratio_min (float, optional) – Minimum size ratio, default (None): determined by the data
size_ratio_max (float, optional) – Maximum size ratio, default (None): determined by the data
- Returns:
w – DES weights
- Return type:
array of float
- get_alpha_leakage_per_object(cat_gal, num_bins, weight_type='des')[source]¶
Compute the leakage per object (Li et al. 2024) Return an array of leakage coefficients obtained by binning in SNR and size.
- Parameters:
- Returns:
alpha_1 (np.array) – Array containing the correction coefficient for the PSF leakage per object for the first component.
alpha_2 (np.array) – Array containing the correction coefficient for the PSF leakage per object for the second component.
- get_quantities_binned(cat_gal, num_bins_x, num_bins_y=None, which=['response', 'number', 'leakage'], verbose=True)[source]¶
- get_calibrate_e_from_cat(path_cat_gal, weight_type='des', verbose=False)[source]¶
Calibrates ellipticities from a galaxy catalog with a certain weight type.
- Parameters:
- Returns:
g_cal – Calibrated ellipticities
- Return type:
np.array
- get_calibrate_no_leakage_e_from_cat(path_cat_gal, weight_type='des', verbose=False)[source]¶
Calibrate ellipticities and removes leakage from a galaxy catalog with a certain weight type.
- Parameters:
- Returns:
e1_noleak (np.array) – Calibrated ellipticities without leakage for the first component
e2_noleak (np.array) – Calibrated ellipticities without leakage for the second component
- class metacal(data, mask, masking_type='gal', step=0.01, prefix='NGMIX', snr_min=10, snr_max=500, rel_size_min=0.5, rel_size_max=3.0, size_corr_ell=True, global_R_weight=None, sigma_eps=0.34, verbose=False)[source]¶
Bases:
objectMetacal.
Metacalibration.
- Parameters:
data – input galaxy catalogue
mask (array of bool) – mask according to galaxy selection, e.g. spread_model
masking_type (string, optional, default='gal') – masking type, one in ‘gal’, ‘gal_mom’, ‘star’
step (float, optional, default=0.01) – step h in finite differences
prefix (string, optional, default='NGMIX') – to specify columns in input catalogue
snr_min (float, optional, default=10) – signal-to-noise minimum
float (snr_max;) – signal-to-noise maximum
optional – signal-to-noise maximum
default=500 – signal-to-noise maximum
rel_size_min (float, optional, default=0.5) – relative size minimum
rel_size_max (float, optional, default=3.0) – relative size maximum
size_corr_ell (bool, optional, default=True)
global_R_weight (str, optional,) – weight column name for global response matrix; default is
None(unweighted mean)sigma_eps (float, optional) – ellipticity dispersion (one component) for computation of weights; default is 0.34
verbose (bool, optional, default=False) – verbose output if True
- _read_data_ngmix(masked_data, m1, p1, m2, p2, ns)[source]¶
Read Data Ngmix.
Read data from ngmix catalogue.
- static get_variance_ivweights(data, sigma_eps, prefix='NGMIX', mask=None)[source]¶
Get Variance IVWEIGHTS.
Compute variance and inverse-variance weights.
- Parameters:
data (numpy.ndarray) – input data
sigma_eps (float) – ellipticity dispersion
prefix (str, optional) – shape measurement identifier; default is “NGMIX”
mask (list, optional) – indicates valid objects with
Truevalues; default isNone= use all objects type has to be bool
- Returns:
float – variance first component
float – variance second component
float – weight
- add_cuts(snr_min=10, snr_max=500, rel_size_min=0.5, rel_size_max=3.0)[source]¶
Add Cuts.
Apply additional cuts to metacal galaxy catalogue.