NKCorrelation: Count-scalar correlations
- class treecorr.NKCorrelation(config=None, *, logger=None, **kwargs)[source]
Bases:
Corr2
This class handles the calculation and storage of a 2-point count-scalar correlation function.
Note
While we use the term kappa (\(\kappa\)) here and the letter K in various places, in fact any scalar field will work here. For example, you can use this to compute correlations of non-shear quantities, e.g. the sizes or concentrations of galaxies, around a set of lenses, where “kappa” would be the measurements of these quantities.
See the doc string of
Corr3
for a description of how the triangles are binned along with the attributes related to the different binning options.In addition to the attributes common to all
Corr3
subclasses, objects of this class hold the following attributes:- Attributes:
xi – The correlation function, \(\xi(r) = \langle \kappa\rangle\).
varxi – An estimate of the variance of \(\xi\)
cov – An estimate of the full covariance matrix.
raw_xi – The raw value of xi, uncorrected by an RK calculation. cf.
calculateXi
raw_varxi – The raw value of varxi, uncorrected by an RK calculation. cf.
calculateXi
Note
The default method for estimating the variance and covariance attributes (
varxi
, andcov
) is ‘shot’, which only includes the shape noise propagated into the final correlation. This does not include sample variance, so it is always an underestimate of the actual variance. To get better estimates, you need to setvar_method
to something else and use patches in the input catalog(s). cf. Covariance Estimates.The typical usage pattern is as follows:
>>> nk = treecorr.NKCorrelation(config) >>> nk.process(cat1,cat2) # Compute the cross-correlation function. >>> nk.write(file_name) # Write out to a file. >>> xi = nk.xi # Or access the correlation function directly.
- Parameters:
config (dict) – A configuration dict that can be used to pass in kwargs if desired. This dict is allowed to have addition entries besides those listed in
Corr2
, which are ignored here. (default: None)logger – If desired, a logger object for logging. (default: None, in which case one will be built according to the config dict’s verbose level.)
- Keyword Arguments:
**kwargs – See the documentation for
Corr2
for the list of allowed keyword arguments, which may be passed either directly or in the config dict.
- calculateXi(*, rk=None)[source]
Calculate the correlation function possibly given another correlation function that uses random points for the foreground objects.
If rk is None, the simple correlation function \(\langle \kappa \rangle\) is returned.
If rk is not None, then a compensated calculation is done: \(\langle \kappa \rangle = (DK - RK)\), where DK represents the mean kappa around the lenses and RK represents the mean kappa around random points.
After calling this function, the attributes
xi
,varxi
andcov
will correspond to the compensated values (if rk is provided). The raw, uncompensated values are available asrawxi
andraw_varxi
.- Parameters:
rk (NKCorrelation) – The cross-correlation using random locations as the lenses (RK), if desired. (default: None)
- Returns:
Tuple containing
xi = array of \(\xi(r)\)
varxi = array of variance estimates of \(\xi(r)\)
- finalize(vark)[source]
Finalize the calculation of the correlation function.
The
Corr2.process_cross
command accumulates values in each bin, so it can be called multiple times if appropriate. Afterwards, this command finishes the calculation by dividing each column by the total weight.- Parameters:
vark – The variance of the scalar field.
- write(file_name, *, rk=None, file_type=None, precision=None, write_patch_results=False, write_cov=False)[source]
Write the correlation function to the file, file_name.
If rk is None, the simple correlation function \(\langle \kappa \rangle(R)\) is used.
If rk is not None, then a compensated calculation is done: \(\langle \kappa \rangle = (DK - RK)\), where DK represents the mean kappa around the lenses and RK represents the mean kappa around random points.
The output file will include the following columns:
Column
Description
r_nom
The nominal center of the bin in r
meanr
The mean value \(\langle r\rangle\) of pairs that fell into each bin
meanlogr
The mean value \(\langle \log(r)\rangle\) of pairs that fell into each bin
kappa
The mean value \(\langle \kappa\rangle(r)\)
sigma
The sqrt of the variance estimate of \(\langle \kappa\rangle\)
weight
The total weight contributing to each bin
npairs
The total number of pairs in each bin
If
sep_units
was given at construction, then the distances will all be in these units. Otherwise, they will be in either the same units as x,y,z (for flat or 3d coordinates) or radians (for spherical coordinates).- Parameters:
file_name (str) – The name of the file to write to.
rk (NKCorrelation) – The cross-correlation using random locations as the lenses (RK), if desired. (default: None)
file_type (str) – The type of file to write (‘ASCII’ or ‘FITS’). (default: determine the type automatically from the extension of file_name.)
precision (int) – For ASCII output catalogs, the desired precision. (default: 4; this value can also be given in the constructor in the config dict.)
write_patch_results (bool) – Whether to write the patch-based results as well. (default: False)
write_cov (bool) – Whether to write the covariance matrix as well. (default: False)