KZCorrelation: Scalar-complex correlations
- class treecorr.KZCorrelation(config=None, *, logger=None, **kwargs)[source]
Bases:
BaseKZCorrelationThis class handles the calculation and storage of a 2-point scalar-complex correlation function, where the complex field is taken to have spin-0 rotational properties. If the spin-0 field is real, you should instead use
KKCorrelationas it will be faster. This class is intended for correlations of a scalar field with complex values that don’t change with orientation.See the docstring of
Corr2for a description of how the pairs are binned along with the attributes related to the different binning options.In addition to the attributes common to all
Corr2subclasses, objects of this class hold the following attributes:In addition, the following attributes are numpy arrays of length (nbins):
- Attributes:
xi – The correlation function, \(\xi(r) = \langle \kappa\, z\rangle\).
xi_im – The imaginary part of \(\xi(r)\).
varxi – An estimate of the variance of each component of \(\xi\)
cov – An estimate of the full covariance matrix.
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_methodto something else and use patches in the input catalog(s). cf. Covariance Estimates.The typical usage pattern is as follows:
>>> kz = treecorr.KZCorrelation(config) >>> kz.process(cat1, cat2) # Compute the cross-correlation. >>> kz.write(file_name) # Write out to a file. >>> xi, xi_im = kz.xi, kz.xi_im # Or access the correlation function directly.
See also:
NZCorrelation,ZZCorrelation,KVCorrelation.- Parameters:
config (dict) – A configuration dict that can be used to pass in kwargs if desired. This dict is allowed to have additional entries besides those listed in
Corr2, which are ignored here. (default: None)logger (
logging.Logger) – If desired, aLoggerobject 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
Corr2for the list of allowed keyword arguments, which may be passed either directly or in the config dict.
- finalize(vark, varz)[source]
Finalize the calculation of the correlation function.
The
Corr2.process_crosscommand 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.
- write(file_name, *, file_type=None, precision=None, write_patch_results=False, write_cov=False)[source]
Write the correlation function to the file, file_name.
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
xi
The real part of the correlation function, \(xi(r) = \langle \kappa\, z\rangle\)
xi_im
The imaginary part of the correlation function.
sigma
The sqrt of the variance estimate of both of these
weight
The total weight contributing to each bin
npairs
The total number of pairs in each bin
If
sep_unitswas 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.
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 files, 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)
- class treecorr.BaseKZCorrelation(config=None, *, logger=None, **kwargs)[source]
Bases:
Corr2This class is a base class for all the K?Correlation classes, where ? is one of the complex fields of varying spin.
A lot of the implementation is shared among those types, so whenever possible the shared implementation is done in this class.