ZZCorrelation: Complex-complex correlations

class treecorr.ZZCorrelation(config=None, *, logger=None, **kwargs)[source]

Bases: BaseZZCorrelation

This class handles the calculation and storage of a 2-point correlation function of two complex spin-0 fields. If either spin-0 field is real, you should instead use KZCorrelation as it will be faster, and if both are real, you should use KKCorrelation. This class is intended for correlations of scalar fields with a complex values that don’t change with orientation.

To be consistent with the other spin correlation functions, we compute two quantities:

\[\xi_+ = \langle z_1 z_2^* \rangle \xi_- = \langle z_1 z_2 \rangle\]

There is no projection along the line connecting the two points as there is for the other complex fields, since the field values don’t change with orientation.

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 Corr2 subclasses, objects of this class hold the following attributes:

Attributes:
  • xip – The correlation function, \(\xi_+(r)\).

  • xim – The correlation function, \(\xi_-(r)\).

  • xip_im – The imaginary part of \(\xi_+(r)\).

  • xim_im – The imaginary part of \(\xi_-(r)\).

  • varxip – An estimate of the variance of \(\xi_+(r)\)

  • varxim – An estimate of the variance of \(\xi_-(r)\)

  • cov – An estimate of the full covariance matrix for the data vector with \(\xi_+\) first and then \(\xi_-\).

Note

The default method for estimating the variance and covariance attributes (varxip, varxim, and cov) 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 set var_method to something else and use patches in the input catalog(s). cf. Covariance Estimates.

The typical usage pattern is as follows:

>>> zz = treecorr.ZZCorrelation(config)
>>> zz.process(cat)         # For auto-correlation.
>>> zz.process(cat1,cat2)   # For cross-correlation.
>>> zz.write(file_name)     # Write out to a file.
>>> xip = zz.xip            # 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.

class treecorr.BaseZZCorrelation(config=None, *, logger=None, **kwargs)[source]

Bases: Corr2

This class is a base class for all the ??Correlation classes, where both ?’s are 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.

__init__(config=None, *, logger=None, **kwargs)[source]
finalize(varz1, varz2)[source]

Finalize the calculation of the correlation function.

The Corr2.process_auto and Corr2.process_cross commands accumulate values in each bin, so they can be called multiple times if appropriate. Afterwards, this command finishes the calculation by dividing each column by the total weight.

Parameters:
  • varz1 (float) – The variance per component of the first field.

  • varz2 (float) – The variance per component of the second field.

getStat()[source]

The standard statistic for the current correlation object as a 1-d array.

In this case, this is the concatenation of self.xip and self.xim (raveled if necessary).

getWeight()[source]

The weight array for the current correlation object as a 1-d array.

This is the weight array corresponding to getStat. In this case, the weight is duplicated to account for both xip and xim returned as part of getStat().

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

xip

The real part of the \(\xi_+\) correlation function

xim

The real part of the \(\xi_-\) correlation function

xip_im

The imag part of the \(\xi_+\) correlation function

xim_im

The imag part of the \(\xi_-\) correlation function

sigma_xip

The sqrt of the variance estimate of \(\xi_+\)

sigma_xim

The sqrt of the variance estimate of \(\xi_-\)

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.

  • 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)