dsigma.jackknife module

Module containing jackknife resampling functions.

dsigma.jackknife.compress_jackknife_fields(table)[source]

Sum together all lenses in each jackknife field.

After assigning jackknife fields, for most applications, we do not need information on individual objects anymore. Compress the information in each jackknife field by taking weighted averages. The only exception is the weight column where the sum is taken.

Parameters:
tableastropy.table.Table

Catalog containing objects. The catalog needs to have been assigned jackknife fields.

Returns:
table_jkastropy.table.Table

Catalog containing the information for each jackknife field. It has exactly as many rows as there are jackknife fields.

dsigma.jackknife.compute_jackknife_fields(table, centers, distance_threshold=1, weights=None, seed=None)[source]

Compute the centers for jackknife regions using DBSCAN and KMeans.

The function first runs DBSCAN to identify continuous fields of points. Afterwards, KMeans clustering is run. The initial cluster centers are random points from each continuous field. The number of initial cluster centers per field is determined according to the total weight of each continuous field. The centers are defined in cartesian coordinates on a unit sphere.

Parameters:
tableastropy.table.Table

Catalog containing objects. The catalog needs to have coordinates and field IDs. The jackknife field for each galaxy will be added in the field_jk column.

centersint or numpy.ndarray

If a number, total number of jackknife fields. Otherwise, the centers returned from a previous call to that function. This allows for different samples to have the same jackknife fields.

distance_thresholdfloat, optional

The angular separation in degrees used to link points and calculate continuous fields before running KMeans. Default is 1.

weightsnumpy.ndarray or None, optional

Per-lens weights for clustering. If None, assume the same weight for all points. Default is None.

seedint or None, optional

Random seed to initialize the random number generator. Default is None.

Returns:
centersnumpy.ndarray

The coordinates of the centers of the jackknife regions.

dsigma.jackknife.jackknife_resampling(f, table_l, table_r=None, table_l_2=None, table_r_2=None, compress=True, **kwargs)[source]

Compute the covariance of a function from jackknife re-sampling.

Parameters:
fcallable()

Function that returns a result for which we want to have uncertainties. The function must take exactly one positional argument, the lens table. Additionally, it can have several additional keyword arguments.

table_lastropy.table.Table

Precompute results for the lenses. The catalog must have jackknife regions assigned to it.

table_rastropy.table.Table or None, optional

Precompute results for random lenses. The input function must accept the random lens table via the table_r keyword argument. Default is None.

table_l_2astropy.table.Table or None, optional

Precompute results for a second set of lenses.The input function must accept the second lens table via the table_l_2 keyword argument. Default is None.

table_r_2astropy.table.Table or None, optional

Precompute results for a second set of random lenses. The input function must accept the second random lens table via the table_r_2 keyword argument. Default is None.

compressbool, optional

If True, compress jackknife fields via dsigma.jackknife.compress_jackknife_fields before performing the jackknife calculation. This can substantially improve performance. Default is True.

**kwargs

Additional keyword arguments to be passed to the function.

Returns:
covnumpy.ndarray or astropy.units.quantity.Quantity

Covariance matrix of the result derived from jackknife re-sampling.

dsigma.jackknife.smooth_covariance_matrix(cov, sigma)[source]

Smooth a covariance matrix.

This function first calculates the correlation matrix, then applies a Gaussian filter on the correlation matrix, and finally reconstructs the covariance matrix using the original diagonal and smoothed correlation matrix.

Parameters:
covnumpy.ndarray or astropy.units.quantity.Quantity

Covariance matrix.

sigmafloat

Scale of the Gaussian filter.

Returns:
cov_smoothnumpy.ndarray or astropy.units.quantity.Quantity

Smoothed covariance matrix.