NKKCorrelation: Count-scalar-scalar correlations
- class treecorr.NKKCorrelation(config=None, *, logger=None, **kwargs)[source]
Bases:
Corr3This class handles the calculation and storage of a 3-point count-scalar-scalar correlation function.
With this class, point 1 of the triangle (i.e. the vertex opposite d1) is the one with the scalar value. Use
KNKCorrelationandKKNCorrelationfor classes with the scalar in the other two positions.See the docstring of
Corr3for 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
Corr3subclasses, objects of this class hold the following attributes:- Attributes:
zeta – The correlation function, \(\zeta\).
varzeta – The variance estimate of \(\zeta\), computed according to
var_method(default:'shot').
The typical usage pattern is as follows:
>>> nkk = treecorr.NKKCorrelation(config) >>> nkk.process(cat1, cat2) # Compute the cross-correlation of two fields. >>> # nkk.process(cat1, cat2, cat3) # ... or of three fields. >>> nkk.write(file_name) # Write out to a file. >>> rkk.process(rand, cat2) # Compute the random cross-correlation. >>> nkk.calculateZeta(rkk=rkk) # Calculate zeta using randoms. >>> zeta = nkk.zeta # Access the correlation function. >>> zetar = nkk.zetar # Or access real and imaginary parts separately. >>> zetai = nkk.zetai
See also:
KNKCorrelation,KKNCorrelation,NNKCorrelation,KKKCorrelation,NKCorrelation.- 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
Corr3, 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
Corr3for the list of allowed keyword arguments, which may be passed either directly or in the config dict.
- calculateZeta(*, rkk=None)[source]
Calculate the correlation function possibly given another correlation function that uses random points for the foreground objects.
If rkk is None, the simple correlation function (self.zeta) is returned.
If rkk is not None, then a compensated calculation is done: \(\zeta = (DKK - RKK)\), where DKK represents the correlation of the kappa field with the data points and RKK represents the correlation with random points.
After calling this function, the attributes
zeta,varzetaandcovwill correspond to the compensated values (if rkk is provided). The raw, uncompensated values are available asraw_zetaandraw_varzeta.Note
The returned variance estimate (
varzeta) is computed according to this object’svar_methodsetting, specified when constructing the object (default:'shot'). Internally, this method callsCorr3.estimate_cov; see that method for details about available variance and covariance estimation schemes.- Parameters:
rkk (NKKCorrelation) – The cross-correlation using random locations as the lenses (RKK), if desired. (default: None)
- Returns:
- Tuple containing
zeta = array of \(\zeta\)
varzeta = array of variance estimates of \(\zeta\)
- 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.
For bin_type = LogRUV, the output file will include the following columns:
Column
Description
r_nom
The nominal center of the bin in r = d2 where d1 > d2 > d3
u_nom
The nominal center of the bin in u = d3/d2
v_nom
The nominal center of the bin in v = +-(d1-d2)/d3
meanu
The mean value \(\langle u\rangle\) of triangles that fell into each bin
meanv
The mean value \(\langle v\rangle\) of triangles that fell into each bin
For bin_type = LogSAS, the output file will include the following columns:
Column
Description
d2_nom
The nominal center of the bin in d2
d3_nom
The nominal center of the bin in d3
phi_nom
The nominal center of the bin in phi, the opening angle between d2 and d3 in the counter-clockwise direction
meanphi
The mean value \(\langle phi\rangle\) of triangles that fell into each bin
For bin_type = LogMultipole, the output file will include the following columns:
Column
Description
d2_nom
The nominal center of the bin in d2
d3_nom
The nominal center of the bin in d3
n
The multipole index n
In addition, all bin types include the following columns:
Column
Description
meand1
The mean value \(\langle d1\rangle\) of triangles that fell into each bin
meanlogd1
The mean value \(\langle \log(d1)\rangle\) of triangles that fell into each bin
meand2
The mean value \(\langle d2\rangle\) of triangles that fell into each bin
meanlogd2
The mean value \(\langle \log(d2)\rangle\) of triangles that fell into each bin
meand3
The mean value \(\langle d3\rangle\) of triangles that fell into each bin
meanlogd3
The mean value \(\langle \log(d3)\rangle\) of triangles that fell into each bin
zeta
The estimator of \(\zeta\) (For LogMultipole, this is split into real and imaginary parts, zetar and zetai.)
sigma_zeta
The sqrt of the variance estimate of \(\zeta\).
weight
The total weight of triangles contributing to each bin. (For LogMultipole, this is split into real and imaginary parts, weightr and weighti.)
ntri
The number of triangles contributing to 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)
KNKCorrelation: Scalar-count-scalar correlations
- class treecorr.KNKCorrelation(config=None, *, logger=None, **kwargs)[source]
Bases:
Corr3This class handles the calculation and storage of a 3-point scalar-count-scalar correlation function.
With this class, point 2 of the triangle (i.e. the vertex opposite d2) is the one with the scalar value. Use
NKKCorrelationandKKNCorrelationfor classes with the scalar in the other two positions.See the docstring of
Corr3for 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
Corr3subclasses, objects of this class hold the following attributes:- Attributes:
zeta – The correlation function, \(\zeta\).
varzeta – The variance estimate of \(\zeta\), computed according to
var_method(default:'shot').
The typical usage pattern is as follows:
>>> knk = treecorr.KNKCorrelation(config) >>> knk.process(cat1, cat2, cat1) # Compute the cross-correlation of two fields. >>> # knk.process(cat1, cat2, cat3) # ... or of three fields. >>> knk.write(file_name) # Write out to a file. >>> krk.process(cat1, rand, cat1) # Compute the random cross-correlation. >>> knk.calculateZeta(krk=krk) # Calculate zeta using randoms. >>> zeta = knk.zeta # Access the correlation function. >>> zetar = knk.zetar # Or access real and imaginary parts separately. >>> zetai = knk.zetai
See also:
NKKCorrelation,KKNCorrelation,NNKCorrelation,KKKCorrelation,NKCorrelation.- 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
Corr3, 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
Corr3for the list of allowed keyword arguments, which may be passed either directly or in the config dict.
- calculateZeta(*, krk=None)[source]
Calculate the correlation function possibly given another correlation function that uses random points for the foreground objects.
If krk is None, the simple correlation function (self.zeta) is returned.
If krk is not None, then a compensated calculation is done: \(\zeta = (KDK - KRK)\), where KDK represents the correlation of the kappa field with the data points and KRK represents the correlation with random points.
After calling this function, the attributes
zeta,varzetaandcovwill correspond to the compensated values (if krk is provided). The raw, uncompensated values are available asraw_zetaandraw_varzeta.Note
The returned variance estimate (
varzeta) is computed according to this object’svar_methodsetting, specified when constructing the object (default:'shot'). Internally, this method callsCorr3.estimate_cov; see that method for details about available variance and covariance estimation schemes.- Parameters:
krk (KNKCorrelation) – The cross-correlation using random locations as the lenses (KRK), if desired. (default: None)
- Returns:
- Tuple containing
zeta = array of \(\zeta\)
varzeta = array of variance estimates of \(\zeta\)
- 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.
For bin_type = LogRUV, the output file will include the following columns:
Column
Description
r_nom
The nominal center of the bin in r = d2 where d1 > d2 > d3
u_nom
The nominal center of the bin in u = d3/d2
v_nom
The nominal center of the bin in v = +-(d1-d2)/d3
meanu
The mean value \(\langle u\rangle\) of triangles that fell into each bin
meanv
The mean value \(\langle v\rangle\) of triangles that fell into each bin
For bin_type = LogSAS, the output file will include the following columns:
Column
Description
d2_nom
The nominal center of the bin in d2
d3_nom
The nominal center of the bin in d3
phi_nom
The nominal center of the bin in phi, the opening angle between d2 and d3 in the counter-clockwise direction
meanphi
The mean value \(\langle phi\rangle\) of triangles that fell into each bin
For bin_type = LogMultipole, the output file will include the following columns:
Column
Description
d2_nom
The nominal center of the bin in d2
d3_nom
The nominal center of the bin in d3
n
The multipole index n
In addition, all bin types include the following columns:
Column
Description
meand1
The mean value \(\langle d1\rangle\) of triangles that fell into each bin
meanlogd1
The mean value \(\langle \log(d1)\rangle\) of triangles that fell into each bin
meand2
The mean value \(\langle d2\rangle\) of triangles that fell into each bin
meanlogd2
The mean value \(\langle \log(d2)\rangle\) of triangles that fell into each bin
meand3
The mean value \(\langle d3\rangle\) of triangles that fell into each bin
meanlogd3
The mean value \(\langle \log(d3)\rangle\) of triangles that fell into each bin
zeta
The estimator of \(\zeta\) (For LogMultipole, this is split into real and imaginary parts, zetar and zetai.)
sigma_zeta
The sqrt of the variance estimate of \(\zeta\).
weight
The total weight of triangles contributing to each bin. (For LogMultipole, this is split into real and imaginary parts, weightr and weighti.)
ntri
The number of triangles contributing to 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)
KKNCorrelation: Scalar-scalar-count correlations
- class treecorr.KKNCorrelation(config=None, *, logger=None, **kwargs)[source]
Bases:
Corr3This class handles the calculation and storage of a 3-point scalar-scalar-count correlation function.
With this class, point 3 of the triangle (i.e. the vertex opposite d3) is the one with the scalar value. Use
NKKCorrelationandKNKCorrelationfor classes with the scalar in the other two positions.See the docstring of
Corr3for 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
Corr3subclasses, objects of this class hold the following attributes:- Attributes:
zeta – The correlation function, \(\zeta\).
varzeta – The variance estimate of \(\zeta\), computed according to
var_method(default:'shot').
The typical usage pattern is as follows:
>>> kkn = treecorr.KKNCorrelation(config) >>> kkn.process(cat1, cat2) # Compute the cross-correlation of two fields. >>> # kkn.process(cat1, cat2, cat3) # ... or of three fields. >>> kkn.write(file_name) # Write out to a file. >>> kkr.process(cat1, rand) # Compute the random cross-correlation. >>> kkn.calculateZeta(kkr=kkr) # Calculate zeta using randoms. >>> zeta = kkn.zeta # Access the correlation function. >>> zetar = kkn.zetar # Or access real and imaginary parts separately. >>> zetai = kkn.zetai
See also:
NKKCorrelation,KNKCorrelation,NNKCorrelation,KKKCorrelation,NKCorrelation.- 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
Corr3, 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
Corr3for the list of allowed keyword arguments, which may be passed either directly or in the config dict.
- calculateZeta(*, kkr=None)[source]
Calculate the correlation function possibly given another correlation function that uses random points for the foreground objects.
If kkr is None, the simple correlation function (self.zeta) is returned.
If kkr is not None, then a compensated calculation is done: \(\zeta = (KKD - KKR)\), where KKD represents the correlation of the kappa field with the data points and KKR represents the correlation with random points.
After calling this function, the attributes
zeta,varzetaandcovwill correspond to the compensated values (if kkr is provided). The raw, uncompensated values are available asraw_zetaandraw_varzeta.Note
The returned variance estimate (
varzeta) is computed according to this object’svar_methodsetting, specified when constructing the object (default:'shot'). Internally, this method callsCorr3.estimate_cov; see that method for details about available variance and covariance estimation schemes.- Parameters:
kkr (KKNCorrelation) – The cross-correlation using random locations as the lenses (KKR), if desired. (default: None)
- Returns:
- Tuple containing
zeta = array of \(\zeta\)
varzeta = array of variance estimates of \(\zeta\)
- 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.
For bin_type = LogRUV, the output file will include the following columns:
Column
Description
r_nom
The nominal center of the bin in r = d2 where d1 > d2 > d3
u_nom
The nominal center of the bin in u = d3/d2
v_nom
The nominal center of the bin in v = +-(d1-d2)/d3
meanu
The mean value \(\langle u\rangle\) of triangles that fell into each bin
meanv
The mean value \(\langle v\rangle\) of triangles that fell into each bin
For bin_type = LogSAS, the output file will include the following columns:
Column
Description
d2_nom
The nominal center of the bin in d2
d3_nom
The nominal center of the bin in d3
phi_nom
The nominal center of the bin in phi, the opening angle between d2 and d3 in the counter-clockwise direction
meanphi
The mean value \(\langle phi\rangle\) of triangles that fell into each bin
For bin_type = LogMultipole, the output file will include the following columns:
Column
Description
d2_nom
The nominal center of the bin in d2
d3_nom
The nominal center of the bin in d3
n
The multipole index n
In addition, all bin types include the following columns:
Column
Description
meand1
The mean value \(\langle d1\rangle\) of triangles that fell into each bin
meanlogd1
The mean value \(\langle \log(d1)\rangle\) of triangles that fell into each bin
meand2
The mean value \(\langle d2\rangle\) of triangles that fell into each bin
meanlogd2
The mean value \(\langle \log(d2)\rangle\) of triangles that fell into each bin
meand3
The mean value \(\langle d3\rangle\) of triangles that fell into each bin
meanlogd3
The mean value \(\langle \log(d3)\rangle\) of triangles that fell into each bin
zeta
The estimator of \(\zeta\) (For LogMultipole, this is split into real and imaginary parts, zetar and zetai.)
sigma_zeta
The sqrt of the variance estimate of \(\zeta\).
weight
The total weight of triangles contributing to each bin. (For LogMultipole, this is split into real and imaginary parts, weightr and weighti.)
ntri
The number of triangles contributing to 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)