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:
- table
astropy.table.Table Catalog containing objects. The catalog needs to have been assigned jackknife fields.
- table
- Returns:
- table_jk
astropy.table.Table Catalog containing the information for each jackknife field. It has exactly as many rows as there are jackknife fields.
- table_jk
- 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:
- table
astropy.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.
- centers
intornumpy.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_threshold
float,optional The angular separation in degrees used to link points and calculate continuous fields before running KMeans. Default is 1.
- weights
numpy.ndarrayorNone,optional Per-lens weights for clustering. If
None, assume the same weight for all points. Default isNone.- seed
intorNone,optional Random seed to initialize the random number generator. Default is
None.
- table
- Returns:
- centers
numpy.ndarray The coordinates of the centers of the jackknife regions.
- centers
- 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:
- f
callable() 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_l
astropy.table.Table Precompute results for the lenses. The catalog must have jackknife regions assigned to it.
- table_r
astropy.table.TableorNone,optional Precompute results for random lenses. The input function must accept the random lens table via the
table_rkeyword argument. Default isNone.- table_l_2
astropy.table.TableorNone,optional Precompute results for a second set of lenses.The input function must accept the second lens table via the
table_l_2keyword argument. Default isNone.- table_r_2
astropy.table.TableorNone,optional Precompute results for a second set of random lenses. The input function must accept the second random lens table via the
table_r_2keyword argument. Default isNone.- compressbool,
optional If
True, compress jackknife fields viadsigma.jackknife.compress_jackknife_fieldsbefore performing the jackknife calculation. This can substantially improve performance. Default isTrue.- **kwargs
Additional keyword arguments to be passed to the function.
- f
- Returns:
- cov
numpy.ndarrayorastropy.units.quantity.Quantity Covariance matrix of the result derived from jackknife re-sampling.
- cov
- 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:
- cov
numpy.ndarrayorastropy.units.quantity.Quantity Covariance matrix.
- sigma
float Scale of the Gaussian filter.
- cov
- Returns:
- cov_smooth
numpy.ndarrayorastropy.units.quantity.Quantity Smoothed covariance matrix.
- cov_smooth