GGGCorrelation: Shear-shear-shear correlations

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

Bases: Corr3

This class handles the calculation and storage of a 3-point shear-shear-shear correlation function.

We use the “natural components” of the shear 3-point function described by Schneider & Lombardi (2003) [Astron.Astrophys. 397 (2003) 809-818]. In this paradigm, the shears are projected relative to some point defined by the geometry of the triangle. They give several reasonable choices for this point. We choose the triangle’s centroid as the “most natural” point, as many simple shear fields have purely real \(\Gamma_0\) using this definition. It is also a fairly simple point to calculate in the code compared to some of the other options they offer, so projections relative to it are fairly efficient.

There are 4 complex-valued 3-point shear corrletion functions defined for triples of shear values projected relative to the line joining the location of the shear to the cenroid of the triangle:

\[\begin{split}\Gamma_0 &= \langle \gamma(\mathbf{x1}) \gamma(\mathbf{x2}) \gamma(\mathbf{x3}) \rangle \\ \Gamma_1 &= \langle \gamma(\mathbf{x1})^* \gamma(\mathbf{x2}) \gamma(\mathbf{x3}) \rangle \\ \Gamma_2 &= \langle \gamma(\mathbf{x1}) \gamma(\mathbf{x2})^* \gamma(\mathbf{x3}) \rangle \\ \Gamma_3 &= \langle \gamma(\mathbf{x1}) \gamma(\mathbf{x2}) \gamma(\mathbf{x3})^* \rangle \\\end{split}\]

where \(\mathbf{x1}, \mathbf{x2}, \mathbf{x3}\) are the corners of the triange opposite sides d1, d2, d3 respectively, where d1 > d2 > d3, and \({}^*\) indicates complex conjugation.

See the doc string of Corr3 for a description of how the triangles are binned.

Ojects of this class holds the following attributes:

Attributes:
  • nbins – The number of bins in logr where r = d2.

  • bin_size – The size of the bins in logr.

  • min_sep – The minimum separation being considered.

  • max_sep – The maximum separation being considered.

  • logr1d – The nominal centers of the nbins bins in log(r).

If the bin_type is LogRUV, then it will have these attributes:

Attributes:
  • nubins – The number of bins in u where u = d3/d2.

  • ubin_size – The size of the bins in u.

  • min_u – The minimum u being considered.

  • max_u – The maximum u being considered.

  • nvbins – The number of bins in v where v = +-(d1-d2)/d3.

  • vbin_size – The size of the bins in v.

  • min_v – The minimum v being considered.

  • max_v – The maximum v being considered.

  • u1d – The nominal centers of the nubins bins in u.

  • v1d – The nominal centers of the nvbins bins in v.

If the bin_type is LogSAS, then it will have these attributes:

Attributes:
  • nphi_bins – The number of bins in phi.

  • phi_bin_size – The size of the bins in phi.

  • min_phi – The minimum phi being considered.

  • max_phi – The maximum phi being considered.

  • phi1d – The nominal centers of the nphi_bins bins in phi.

If the bin_type is LogMultipole, then it will have these attributes:

Attributes:
  • max_n – The maximum multipole index n being stored.

  • n1d – The multipole index n in the 2*max_n+1 bins of the third bin direction.

In addition, the following attributes are numpy arrays whose shape is:

  • (nbins, nubins, nvbins) if bin_type is LogRUV

  • (nbins, nbins, nphi_bins) if bin_type is LogSAS

  • (nbins, nbins, 2*max_n+1) if bin_type is LogMultipole

If bin_type is LogRUV:

Attributes:
  • logr – The nominal center of each bin in log(r).

  • rnom – The nominal center of each bin converted to regular distance. i.e. r = exp(logr).

  • u – The nominal center of each bin in u.

  • v – The nominal center of each bin in v.

  • meanu – The (weighted) mean value of u for the triangles in each bin.

  • meanv – The (weighted) mean value of v for the triangles in each bin.

If bin_type is LogSAS:

Attributes:
  • logd2 – The nominal center of each bin in log(d2).

  • d2nom – The nominal center of each bin converted to regular d2 distance. i.e. d2 = exp(logd2).

  • logd3 – The nominal center of each bin in log(d3).

  • d3nom – The nominal center of each bin converted to regular d3 distance. i.e. d3 = exp(logd3).

  • phi – The nominal center of each angular bin.

  • meanphi – The (weighted) mean value of phi for the triangles in each bin.

If bin_type is LogMultipole:

Attributes:
  • logd2 – The nominal center of each bin in log(d2).

  • d2nom – The nominal center of each bin converted to regular d2 distance. i.e. d2 = exp(logd2).

  • logd3 – The nominal center of each bin in log(d3).

  • d3nom – The nominal center of each bin converted to regular d3 distance. i.e. d3 = exp(logd3).

  • n – The multipole index n for each bin.

For any bin_type:

Attributes:
  • gam0 – The 0th “natural” correlation function, \(\Gamma_0\).

  • gam1 – The 1st “natural” correlation function, \(\Gamma_1\).

  • gam2 – The 2nd “natural” correlation function, \(\Gamma_2\).

  • gam3 – The 3rd “natural” correlation function, \(\Gamma_3\).

  • vargam0 – The variance of \(\Gamma_0\), only including the shot noise propagated into the final correlation. This (and the related values for 1,2,3) does not include sample variance, so it is always an underestimate of the actual variance.

  • vargam1 – The variance of \(\Gamma_1\).

  • vargam2 – The variance of \(\Gamma_2\).

  • vargam3 – The variance of \(\Gamma_3\).

  • meand1 – The (weighted) mean value of d1 for the triangles in each bin.

  • meanlogd1 – The (weighted) mean value of log(d1) for the triangles in each bin.

  • meand2 – The (weighted) mean value of d2 for the triangles in each bin.

  • meanlogd2 – The (weighted) mean value of log(d2) for the triangles in each bin.

  • meand3 – The (weighted) mean value of d3 for the triangles in each bin.

  • meanlogd3 – The (weighted) mean value of log(d3) for the triangles in each bin.

  • weight – The total weight in each bin.

  • ntri – The number of triangles going into each bin (including those where one or more objects have w=0).

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 Corr3.process command and use process_auto and/or Corr3.process_cross, then the units will not be applied to meanr or meanlogr until the finalize function is called.

The typical usage pattern is as follows:

>>> ggg = treecorr.GGGCorrelation(config)
>>> ggg.process(cat)              # For auto-correlation.
>>> ggg.process(cat1,cat2,cat3)   # For cross-correlation.
>>> ggg.write(file_name)          # Write out to a file.
>>> gam0 = ggg.gam0, etc.         # To access gamma values directly.
>>> gam0r = ggg.gam0r             # You can also access real and imag parts separately.
>>> gam0i = ggg.gam0i
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 Corr3, 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 Corr3 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 GGGCorrelation. See class doc for details.

calculateMap3(*, R=None, k2=1, k3=1)[source]

Calculate the skewness of the aperture mass from the correlation function.

The equations for this come from Jarvis, Bernstein & Jain (2004, MNRAS, 352). See their section 3, especially equations 51 and 52 for the \(T_i\) functions, equations 60 and 61 for the calculation of \(\langle \cal M^3 \rangle\) and \(\langle \cal M^2 M^* \rangle\), and equations 55-58 for how to convert these to the return values.

If k2 or k3 != 1, then this routine calculates the generalization of the skewness proposed by Schneider, Kilbinger & Lombardi (2005, A&A, 431): \(\langle M_{ap}^3(R, k_2 R, k_3 R)\rangle\) and related values.

If k2 = k3 = 1 (the default), then there are only 4 combinations of Map and Mx that are relevant:

  • map3 = \(\langle M_{ap}^3(R)\rangle\)

  • map2mx = \(\langle M_{ap}^2(R) M_\times(R)\rangle\),

  • mapmx2 = \(\langle M_{ap}(R) M_\times(R)\rangle\)

  • mx3 = \(\langle M_{\rm \times}^3(R)\rangle\)

However, if k2 or k3 != 1, then there are 8 combinations:

  • map3 = \(\langle M_{ap}(R) M_{ap}(k_2 R) M_{ap}(k_3 R)\rangle\)

  • mapmapmx = \(\langle M_{ap}(R) M_{ap}(k_2 R) M_\times(k_3 R)\rangle\)

  • mapmxmap = \(\langle M_{ap}(R) M_\times(k_2 R) M_{ap}(k_3 R)\rangle\)

  • mxmapmap = \(\langle M_\times(R) M_{ap}(k_2 R) M_{ap}(k_3 R)\rangle\)

  • mxmxmap = \(\langle M_\times(R) M_\times(k_2 R) M_{ap}(k_3 R)\rangle\)

  • mxmapmx = \(\langle M_\times(R) M_{ap}(k_2 R) M_\times(k_3 R)\rangle\)

  • mapmxmx = \(\langle M_{ap}(R) M_\times(k_2 R) M_\times(k_3 R)\rangle\)

  • mx3 = \(\langle M_\times(R) M_\times(k_2 R) M_\times(k_3 R)\rangle\)

To accommodate this full generality, we always return all 8 values, along with the estimated variance (which is equal for each), even when k2 = k3 = 1.

Note

The formulae for the m2_uform = ‘Schneider’ definition of the aperture mass, described in the documentation of calculateMapSq, are not known, so that is not an option here. The calculations here use the definition that corresponds to m2_uform = ‘Crittenden’.

Parameters:
  • R (array) – The R values at which to calculate the aperture mass statistics. (default: None, which means use self.rnom1d)

  • k2 (float) – If given, the ratio R2/R1 in the SKL formulae. (default: 1)

  • k3 (float) – If given, the ratio R3/R1 in the SKL formulae. (default: 1)

Returns:

  • map3 = array of \(\langle M_{ap}(R) M_{ap}(k_2 R) M_{ap}(k_3 R)\rangle\)

  • mapmapmx = array of \(\langle M_{ap}(R) M_{ap}(k_2 R) M_\times(k_3 R)\rangle\)

  • mapmxmap = array of \(\langle M_{ap}(R) M_\times(k_2 R) M_{ap}(k_3 R)\rangle\)

  • mxmapmap = array of \(\langle M_\times(R) M_{ap}(k_2 R) M_{ap}(k_3 R)\rangle\)

  • mxmxmap = array of \(\langle M_\times(R) M_\times(k_2 R) M_{ap}(k_3 R)\rangle\)

  • mxmapmx = array of \(\langle M_\times(R) M_{ap}(k_2 R) M_\times(k_3 R)\rangle\)

  • mapmxmx = array of \(\langle M_{ap}(R) M_\times(k_2 R) M_\times(k_3 R)\rangle\)

  • mx3 = array of \(\langle M_\times(R) M_\times(k_2 R) M_\times(k_3 R)\rangle\)

  • varmap3 = array of variance estimates of the above values

Return type:

Tuple containing

finalize(varg1, varg2, varg3)[source]

Finalize the calculation of the correlation function.

The process_auto, process_cross12 and Corr3.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 by the total weight.

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

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

  • varg3 (float) – The variance per component of the third shear field.

getStat()[source]

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

In this case, the concatenation of gam0.ravel(), gam1.ravel(), gam2.ravel(), gam3.ravel().

Note

This is a complex array, unlike most other statistics. The computed covariance matrix will be complex, although since it is Hermitian the diagonal is real, so the resulting vargam0, etc. will all be real arrays.

getWeight()[source]

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

In this case, 4 copies of self.weight.ravel().

process_auto(cat, *, metric=None, num_threads=None)[source]

Process a single catalog, accumulating the auto-correlation.

This accumulates the auto-correlation for the given catalog. After calling this function as often as desired, the finalize command will finish the calculation of meand1, meanlogd1, etc.

Parameters:
  • cat (Catalog) – The catalog to process

  • metric (str) – Which metric to use. See Metrics for details. (default: ‘Euclidean’; this value can also be given in the constructor in the config dict.)

  • num_threads (int) – How many OpenMP threads to use during the calculation. (default: use the number of cpu cores; this value can also be given in the constructor in the config dict.)

process_cross12(cat1, cat2, *, metric=None, ordered=True, num_threads=None)[source]

Process two catalogs, accumulating the 3pt cross-correlation, where one of the points in each triangle come from the first catalog, and two come from the second.

This accumulates the cross-correlation for the given catalogs as part of a larger auto- or cross-correlation calculation. E.g. when splitting up a large catalog into patches, this is appropriate to use for the cross correlation between different patches as part of the complete auto-correlation of the full catalog.

Parameters:
  • cat1 (Catalog) – The first catalog to process. (1 point in each triangle will come from this catalog.)

  • cat2 (Catalog) – The second catalog to process. (2 points in each triangle will come from this catalog.)

  • metric (str) – Which metric to use. See Metrics for details. (default: ‘Euclidean’; this value can also be given in the constructor in the config dict.)

  • ordered (bool) – Whether to fix the order of the triangle vertices to match the catalogs. (default: True)

  • num_threads (int) – How many OpenMP threads to use during the calculation. (default: use the number of cpu cores; this value can also be given in the constructor in the config dict.)

toSAS(*, target=None, **kwargs)[source]

Convert a multipole-binned correlation to the corresponding SAS binning.

This is only valid for bin_type == LogMultipole.

Keyword Arguments:
  • target – A target GGGCorrelation object with LogSAS binning to write to. If this is not given, a new object will be created based on the configuration paramters of the current object. (default: None)

  • **kwargs – Any kwargs that you want to use to configure the returned object. Typically, might include min_phi, max_phi, nphi_bins, phi_bin_size. The default phi binning is [0,pi] with nphi_bins = self.max_n.

Returns:

A GGGCorrelation object with bin_type=LogSAS containing the same information as this object, but with the SAS binning.

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.

As described in the doc string for GGGCorrelation, we use the “natural components” of the shear 3-point function described by Schneider & Lombardi (2003) using the triangle centroid as the projection point. There are 4 complex-valued natural components, so there are 8 columns in the output file.

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

gam0r

The real part of the estimator of \(\Gamma_0\)

gam0i

The imag part of the estimator of \(\Gamma_0\)

gam1r

The real part of the estimator of \(\Gamma_1\)

gam1i

The imag part of the estimator of \(\Gamma_1\)

gam2r

The real part of the estimator of \(\Gamma_2\)

gam2i

The imag part of the estimator of \(\Gamma_2\)

gam3r

The real part of the estimator of \(\Gamma_3\)

gam3i

The imag part of the estimator of \(\Gamma_3\)

sigma_gam0

The sqrt of the variance estimate of \(\Gamma_0\)

sigma_gam1

The sqrt of the variance estimate of \(\Gamma_1\)

sigma_gam2

The sqrt of the variance estimate of \(\Gamma_2\)

sigma_gam3

The sqrt of the variance estimate of \(\Gamma_3\)

weight

The total weight of triangles contributing to each bin. (For LogMultipole, this is split into real and imaginary parts, weight_re and weight_im.)

ntri

The number of triangles contributing to 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)

writeMap3(file_name, *, R=None, file_type=None, precision=None)[source]

Write the aperture mass skewness based on the correlation function to the file, file_name.

The output file will include the following columns:

Column

Description

R

The aperture radius

Map3

An estimate of \(\langle M_{ap}^3\rangle(R)\) (cf. calculateMap3)

Map2Mx

An estimate of \(\langle M_{ap}^2 M_\times\rangle(R)\)

MapMx2

An estimate of \(\langle M_{ap} M_\times^2\rangle(R)\)

Mx3

An estimate of \(\langle M_\times^3\rangle(R)\)

sig_map

The sqrt of the variance estimate of each of these

Parameters:
  • file_name (str) – The name of the file to write to.

  • R (array) – The R values at which to calculate the statistics. (default: None, which means use self.rnom)

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