NGCorrelation: Count-shear correlations

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

Bases: BaseNZCorrelation

This class handles the calculation and storage of a 2-point count-shear correlation function. This is the tangential shear profile around lenses, commonly referred to as galaxy-galaxy lensing.

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 \gamma_T\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 RG calculation. cf. calculateXi

  • raw_xi_im – The raw value of xi_im, uncorrected by an RG calculation. cf. calculateXi

  • raw_varxi – The raw value of varxi, uncorrected by an RG calculation. cf. calculateXi

Note

The default method for estimating the variance and covariance attributes (varxi, 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.

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 use Corr2.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:

>>> ng = treecorr.NGCorrelation(config)
>>> ng.process(cat1,cat2)   # Compute the cross-correlation.
>>> ng.write(file_name)     # Write out to a file.
>>> xi = ng.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 NGCorrelation. See class doc for details.

calculateNMap(*, R=None, rg=None, m2_uform=None)[source]

Calculate the aperture mass statistics from the correlation function.

\[\begin{split}\langle N M_{ap} \rangle(R) &= \int_{0}^{rmax} \frac{r dr}{R^2} T_\times\left(\frac{r}{R}\right) \Re\xi(r) \\ \langle N M_{\times} \rangle(R) &= \int_{0}^{rmax} \frac{r dr}{R^2} T_\times\left(\frac{r}{R}\right) \Im\xi(r)\end{split}\]

The m2_uform parameter sets which definition of the aperture mass to use. The default is to use ‘Crittenden’.

If m2_uform is ‘Crittenden’:

\[\begin{split}U(r) &= \frac{1}{2\pi} (1-r^2) \exp(-r^2/2) \\ T_\times(s) &= \frac{s^2}{128} (12-s^2) \exp(-s^2/4)\end{split}\]

cf. Crittenden, et al (2002): ApJ, 568, 20

If m2_uform is ‘Schneider’:

\[\begin{split}U(r) &= \frac{9}{\pi} (1-r^2) (1/3-r^2) \\ T_\times(s) &= \frac{18}{\pi} s^2 \arccos(s/2) \\ &\qquad - \frac{3}{40\pi} s^3 \sqrt{4-s^2} (196 - 74s^2 + 14s^4 - s^6)\end{split}\]

cf. Schneider, et al (2002): A&A, 389, 729

In neither case is this formula in the above papers, but the derivation is similar to the derivations of \(T_+\) and \(T_-\) in Schneider et al. (2002).

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

  • rg (NGCorrelation) – The cross-correlation using random locations as the lenses (RG), if desired. (default: None)

  • m2_uform (str) – Which form to use for the aperture mass, as described above. (default: ‘Crittenden’; this value can also be given in the constructor in the config dict.)

Returns:

Tuple containing

  • nmap = array of \(\langle N M_{ap} \rangle(R)\)

  • nmx = array of \(\langle N M_{\times} \rangle(R)\)

  • varnmap = array of variance estimates of the above values

calculateXi(*, rg=None)[source]

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

  • If rg is None, the simple correlation function \(\langle \gamma_T\rangle\) is returned.

  • If rg is not None, then a compensated calculation is done: \(\langle \gamma_T\rangle = (DG - RG)\), where DG represents the mean shear around the lenses and RG represents the mean shear around random points.

After calling this function, the attributes xi, xi_im, varxi, and cov will correspond to the compensated values (if rg is provided). The raw, uncompensated values are available as rawxi, raw_xi_im, and raw_varxi.

Parameters:

rg (NGCorrelation) – The cross-correlation using random locations as the lenses (RG), 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(varg)[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:

varg (float) – The variance per component of the shear field.

write(file_name, *, rg=None, file_type=None, precision=None, write_patch_results=False, write_cov=False)[source]

Write the correlation function to the file, file_name.

  • If rg is None, the simple correlation function \(\langle \gamma_T\rangle\) is used.

  • If rg is not None, then a compensated calculation is done: \(\langle \gamma_T\rangle = (DG - RG)\), where DG represents the mean shear around the lenses and RG represents the mean shear 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

gamT

The real part of the mean tangential shear, \(\langle \gamma_T \rangle(r)\)

gamX

The imag part of the mean tangential shear, \(\langle \gamma_\times \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.

  • rg (NGCorrelation) – The cross-correlation using random locations as the lenses (RG), 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)

writeNMap(file_name, *, R=None, rg=None, m2_uform=None, file_type=None, precision=None)[source]

Write the cross correlation of the foreground galaxy counts with the aperture mass based on the correlation function to the file, file_name.

If rg is provided, the compensated calculation will be used for \(\xi\).

See calculateNMap for an explanation of the m2_uform parameter.

The output file will include the following columns:

Column

Description

R

The radius of the aperture.

NMap

An estimate of \(\langle N_{ap} M_{ap} \rangle(R)\)

NMx

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

sig_nmap

The sqrt of the variance estimate of either of these

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

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

  • rg (NGCorrelation) – The cross-correlation using random locations as the lenses (RG), if desired. (default: None)

  • m2_uform (str) – Which form to use for the aperture mass. (default: ‘Crittenden’; this value can also be given in the constructor in the config dict.)

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

writeNorm(file_name, *, gg, dd, rr, R=None, dr=None, rg=None, m2_uform=None, file_type=None, precision=None)[source]

Write the normalized aperture mass cross-correlation to the file, file_name.

The combination \(\langle N M_{ap}\rangle^2 / \langle M_{ap}^2\rangle \langle N_{ap}^2\rangle\) is related to \(r\), the galaxy-mass correlation coefficient. Similarly, \(\langle N_{ap}^2\rangle / \langle M_{ap}^2\rangle\) is related to \(b\), the galaxy bias parameter. cf. Hoekstra et al, 2002: http://adsabs.harvard.edu/abs/2002ApJ…577..604H

This function computes these combinations and outputs them to a file.

  • if rg is provided, the compensated calculation will be used for \(\langle N_{ap} M_{ap} \rangle\).

  • if dr is provided, the compensated calculation will be used for \(\langle N_{ap}^2 \rangle\).

See calculateNMap for an explanation of the m2_uform parameter.

The output file will include the following columns:

Column

Description

R

The radius of the aperture

NMap

An estimate of \(\langle N_{ap} M_{ap} \rangle(R)\)

NMx

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

sig_nmap

The sqrt of the variance estimate of either of these

Napsq

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

sig_napsq

The sqrt of the variance estimate of \(\langle N_{ap}^2 \rangle\)

Mapsq

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

sig_mapsq

The sqrt of the variance estimate of \(\langle M_{ap}^2 \rangle\)

NMap_norm

The ratio \(\langle N_{ap} M_{ap} \rangle^2 /\) \(\langle N_{ap}^2 \rangle \langle M_{ap}^2 \rangle\)

sig_norm

The sqrt of the variance estimate of this ratio

Nsq_Mapsq

The ratio \(\langle N_{ap}^2 \rangle / \langle M_{ap}^2 \rangle\)

sig_nn_mm

The sqrt of the variance estimate of this ratio

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

  • gg (GGCorrelation) – The auto-correlation of the shear field

  • dd (NNCorrelation) – The auto-correlation of the lens counts (DD)

  • rr (NNCorrelation) – The auto-correlation of the random field (RR)

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

  • dr (NNCorrelation) – The cross-correlation of the data with randoms (DR), if desired, in which case the Landy-Szalay estimator will be calculated. (default: None)

  • rd (NNCorrelation) – The cross-correlation of the randoms with data (RD), if desired. (default: None, which means use rd=dr)

  • rg (NGCorrelation) – The cross-correlation using random locations as the lenses (RG), if desired. (default: None)

  • m2_uform (str) – Which form to use for the aperture mass. (default: ‘Crittenden’; this value can also be given in the constructor in the config dict.)

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