NZCorrelation: Count-complex correlations
- class treecorr.NZCorrelation(config=None, *, logger=None, **kwargs)[source]
Bases:
BaseNZCorrelation
This class handles the calculation and storage of a 2-point count-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
NKCorrelation
as it will be faster. This class is intended for correlations of a scalar field with a complex values that don’t change with orientation.Ojects of this class holds the following attributes:
- Attributes:
nbins – The number of bins in logr
bin_size – The size of the bins in logr
min_sep – The minimum separation being considered
max_sep – The maximum separation being considered
In addition, the following attributes are numpy arrays of length (nbins):
- Attributes:
logr – The nominal center of the bin in log(r) (the natural logarithm of r).
rnom – The nominal center of the bin converted to regular distance. i.e. r = exp(logr).
meanr – The (weighted) mean value of r for the pairs in each bin. If there are no pairs in a bin, then exp(logr) will be used instead.
meanlogr – The (weighted) mean value of log(r) for the pairs in each bin. If there are no pairs in a bin, then logr will be used instead.
xi – The correlation function, \(\xi(r) = \langle z\rangle\).
xi_im – The imaginary part of \(\xi(r)\).
varxi – An estimate of the variance of \(\xi\)
weight – The total weight in each bin.
npairs – The number of pairs going into each bin (including pairs where one or both objects have w=0).
cov – An estimate of the full covariance matrix.
raw_xi – The raw value of xi, uncorrected by an RZ calculation. cf.
calculateXi
raw_xi_im – The raw value of xi_im, uncorrected by an RZ calculation. cf.
calculateXi
raw_varxi – The raw value of varxi, uncorrected by an RZ 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.If
sep_units
are given (either in the config dict or as a named kwarg) then the distances will all be in these units.Note
If you separate out the steps of the
Corr2.process
command and useCorr2.process_cross
, then the units will not be applied tomeanr
ormeanlogr
until thefinalize
function is called.The typical usage pattern is as follows:
>>> nz = treecorr.NZCorrelation(config) >>> nz.process(cat1,cat2) # Compute the cross-correlation. >>> nz.write(file_name) # Write out to a file. >>> xi = nz.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.
- __init__(config=None, *, logger=None, **kwargs)[source]
Initialize
NZCorrelation
. See class doc for details.
- calculateXi(*, rz=None)[source]
Calculate the correlation function possibly given another correlation function that uses random points for the foreground objects.
If rz is None, the simple correlation function \(\langle z\rangle\) is returned.
If rz is not None, then a compensated calculation is done: \(\langle z\rangle = (DZ - RZ)\), where DZ represents the mean field value around the data points and RZ represents the mean value around random points.
After calling this function, the attributes
xi
,xi_im
,varxi
, andcov
will correspond to the compensated values (if rz is provided). The raw, uncompensated values are available asrawxi
,raw_xi_im
, andraw_varxi
.- Parameters:
rz (NZCorrelation) – The cross-correlation using random locations as the lenses (RZ), if desired. (default: None)
- Returns:
Tuple containing
xi = array of the real part of \(\xi(R)\)
xi_im = array of the imaginary part of \(\xi(R)\)
varxi = array of the variance estimates of the above values
- finalize(varz)[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:
varz (float) – The variance per component of the complex field.
- write(file_name, *, rz=None, file_type=None, precision=None, write_patch_results=False, write_cov=False)[source]
Write the correlation function to the file, file_name.
If rz is None, the simple correlation function \(\langle z\rangle\) is used.
If rz is not None, then a compensated calculation is done: \(\langle z\rangle = (DZ - RZ)\), where DZ represents the mean field value around the data points and RZ represents the mean value 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
z_real
The mean real component, \(\langle real(z) \rangle(r)\)
z_imag
The mean imaginary component, \(\langle imag(z) \rangle(r)\).
sigma
The sqrt of the variance estimate of either of these
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.
rz (NZCorrelation) – The cross-correlation using random locations as the lenses (RZ), 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)
- class treecorr.BaseNZCorrelation(config=None, *, logger=None, **kwargs)[source]
Bases:
Corr2
This class is a base class for all the N?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.