NGGCorrelation: Count-shear-shear correlations

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

Bases: Corr3

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

With this class, points 2 and 3 of the triangle (i.e. the vertces opposite d2,d3) are the ones with the shear values. Use GNGCorrelation and GGNCorrelation for classes with the shears in the other positions.

For the shear projection, we follow the lead of the 3-point shear-shear-shear correlation functions (see GGGCorrelation for details), which involves projecting the shear values at each vertex relative to the direction to the triangle’s centroid. Furthermore, the GGG correlations have 4 relevant complex values for each 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}\]

With only a count at vertex 1, \(\Gamma_0 = \Gamma_1\) and \(\Gamma_2 = \Gamma_3^*\). So there are only two independent values. However, you may access these values using whichever names you find most convenient: gam0, gam1, gam2 and gam3 are all valid attributes, which return the corresponding value.

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

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 estimate of \(\Gamma_0\), only including the shot noise.

  • vargam1 – The variance estimate of \(\Gamma_1\), only including the shot noise.

  • vargam2 – The variance estimate of \(\Gamma_2\), only including the shot noise.

  • vargam3 – The variance estimate of \(\Gamma_3\), only including the shot noise.

The typical usage pattern is as follows:

>>> ngg = treecorr.NGGCorrelation(config)
>>> ngg.process(cat1, cat2)       # Compute cross-correlation of two fields.
>>> ngg.process(cat1, cat2, cat3) # Compute cross-correlation of three fields.
>>> ngg.write(file_name)          # Write out to a file.
>>> rgg.process(rand, cat2)       # Compute cross-correlation with randoms.
>>> ngg.calculateZeta(rgg=rgg)    # Calculate zeta using randoms
>>> gam0 = ngg.gam0, etc.         # Access gamma values directly.
>>> gam0r = ngg.gam0r             # Or access real and imag parts separately.
>>> gam0i = ngg.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]
calculateGam(*, rgg=None)[source]

Calculate the correlation function possibly given another correlation function that uses random points for the foreground objects.

  • If rgg is None, the simple correlation functions (self.gam0, self.gam2) are returned.

  • If rgg is not None, then a compensated calculation is done: \(\Gamma_i = (DGG - RGG)\), where DGG represents the correlation of the gamma field with the data points and RGG represents the correlation with random points.

After calling this function, the attributes gam0, gam2, vargam0, vargam2, and cov will correspond to the compensated values (if rgg is provided). The raw, uncompensated values are available as raw_gam0 , raw_gam2, raw_vargam0, and raw_vargam2.

Parameters:

rgg (NGGCorrelation) – The cross-correlation using random locations as the lenses (RGG), if desired. (default: None)

Returns:

Tuple containing
  • gam0 = array of \(\Gamma_0\)

  • gam2 = array of \(\Gamma_2\)

  • vargam0 = array of variance estimates of \(\Gamma_0\)

  • vargam2 = array of variance estimates of \(\Gamma_2\)

copy()[source]

Make a copy

finalize(varg1, varg2)[source]

Finalize the calculation of the correlation function.

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

  • varg2 (float) – The variance per component of the second 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() and gam2.ravel().

getWeight()[source]

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

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

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

gam0r

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

gam0i

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

gam2r

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

gam2i

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

sigma_gam0

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

sigma_gam2

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

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

GNGCorrelation: Shear-count-shear correlations

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

Bases: Corr3

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

With this class, points 1 and 3 of the triangle (i.e. the vertces opposite d2,d3) are the ones with the shear values. Use NGGCorrelation and GGNCorrelation for classes with the shears in the other positions.

For the shear projection, we follow the lead of the 3-point shear-shear-shear correlation functions (see GGGCorrelation for details), which involves projecting the shear values at each vertex relative to the direction to the triangle’s centroid. Furthermore, the GGG correlations have 4 relevant complex values for each 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}\]

With only a count at vertex 2, \(\Gamma_0 = \Gamma_2\) and \(\Gamma_1 = \Gamma_3^*\). So there are only two independent values. However, you may access these values using whichever names you find most convenient: gam0, gam1, gam2 and gam3 are all valid attributes, which return the corresponding value.

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

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 estimate of \(\Gamma_0\), only including the shot noise.

  • vargam1 – The variance estimate of \(\Gamma_1\), only including the shot noise.

  • vargam2 – The variance estimate of \(\Gamma_2\), only including the shot noise.

  • vargam3 – The variance estimate of \(\Gamma_3\), only including the shot noise.

The typical usage pattern is as follows:

>>> gng = treecorr.GNGCorrelation(config)
>>> gng.process(cat1, cat2, cat1) # Compute cross-correlation of two fields.
>>> gng.process(cat1, cat2, cat3) # Compute cross-correlation of three fields.
>>> gng.write(file_name)          # Write out to a file.
>>> grg.process(cat1, rand, cat1) # Compute cross-correlation with randoms.
>>> gng.calculateZeta(grg=grg)    # Calculate zeta using randoms
>>> gam0 = gng.gam0, etc.         # Access gamma values directly.
>>> gam0r = gng.gam0r             # Or access real and imag parts separately.
>>> gam0i = gng.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]
calculateGam(*, grg=None)[source]

Calculate the correlation function possibly given another correlation function that uses random points for the foreground objects.

  • If grg is None, the simple correlation functions (self.gam0, self.gam1) are returned.

  • If grg is not None, then a compensated calculation is done: \(\Gamma_i = (GDG - GRG)\), where GDG represents the correlation of the gamma field with the data points and GRG represents the correlation with random points.

After calling this function, the attributes gam0, gam1, vargam0, vargam1, and cov will correspond to the compensated values (if grg is provided). The raw, uncompensated values are available as raw_gam0 , raw_gam1, raw_vargam0, and raw_vargam1.

Parameters:

grg (GNGCorrelation) – The cross-correlation using random locations as the lenses (GRG), if desired. (default: None)

Returns:

Tuple containing
  • gam0 = array of \(\Gamma_0\)

  • gam1 = array of \(\Gamma_1\)

  • vargam0 = array of variance estimates of \(\Gamma_0\)

  • vargam1 = array of variance estimates of \(\Gamma_1\)

copy()[source]

Make a copy

finalize(varg1, varg2)[source]

Finalize the calculation of the correlation function.

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

  • varg2 (float) – The variance per component of the second 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() and gam1.ravel().

getWeight()[source]

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

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

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

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

sigma_gam0

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

sigma_gam1

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

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

GGNCorrelation: Shear-shear-count correlations

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

Bases: Corr3

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

With this class, points 1 and 2 of the triangle (i.e. the vertces opposite d2,d3) are the ones with the shear values. Use NGGCorrelation and GNGCorrelation for classes with the shears in the other positions.

For the shear projection, we follow the lead of the 3-point shear-shear-shear correlation functions (see GGGCorrelation for details), which involves projecting the shear values at each vertex relative to the direction to the triangle’s centroid. Furthermore, the GGG correlations have 4 relevant complex values for each 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}\]

With only a count at vertex 3, \(\Gamma_0 = \Gamma_3\) and \(\Gamma_1 = \Gamma_2^*\). So there are only two independent values. However, you may access these values using whichever names you find most convenient: gam0, gam1, gam2 and gam3 are all valid attributes, which return the corresponding value.

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

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 estimate of \(\Gamma_0\), only including the shot noise.

  • vargam1 – The variance estimate of \(\Gamma_1\), only including the shot noise.

  • vargam2 – The variance estimate of \(\Gamma_2\), only including the shot noise.

  • vargam3 – The variance estimate of \(\Gamma_3\), only including the shot noise.

The typical usage pattern is as follows:

>>> ggn = treecorr.GGNCorrelation(config)
>>> ggn.process(cat1, cat2)       # Compute cross-correlation of two fields.
>>> ggn.process(cat1, cat2, cat3) # Compute cross-correlation of three fields.
>>> ggn.write(file_name)          # Write out to a file.
>>> ggr.process(cat1, rand)       # Compute cross-correlation with randoms.
>>> ggn.calculateZeta(ggr=ggr)    # Calculate zeta using randoms
>>> gam0 = ggn.gam0, etc.         # Access gamma values directly.
>>> gam0r = ggn.gam0r             # Or access real and imag parts separately.
>>> gam0i = ggn.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]
calculateGam(*, ggr=None)[source]

Calculate the correlation function possibly given another correlation function that uses random points for the foreground objects.

  • If ggr is None, the simple correlation functions (self.gam0, self.gam1) are returned.

  • If ggr is not None, then a compensated calculation is done: \(\Gamma_i = (GGD - GGR)\), where GGD represents the correlation of the gamma field with the data points and GGR represents the correlation with random points.

After calling this function, the attributes gam0, gam1, vargam0, vargam1, and cov will correspond to the compensated values (if ggr is provided). The raw, uncompensated values are available as raw_gam0 , raw_gam1, raw_vargam0, and raw_vargam1.

Parameters:

ggr (GGNCorrelation) – The cross-correlation using random locations as the lenses (GGR), if desired. (default: None)

Returns:

Tuple containing
  • gam0 = array of \(\Gamma_0\)

  • gam1 = array of \(\Gamma_1\)

  • vargam0 = array of variance estimates of \(\Gamma_0\)

  • vargam1 = array of variance estimates of \(\Gamma_1\)

copy()[source]

Make a copy

finalize(varg1, varg2)[source]

Finalize the calculation of the correlation function.

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

  • varg2 (float) – The variance per component of the second 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() and gam1.ravel().

getWeight()[source]

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

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

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

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

sigma_gam0

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

sigma_gam1

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

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