Python module for computing 2-point correlation functions
Project description
TreeCorr is a package for efficiently computing 2-point and 3-point correlation functions.
The code is hosted at https://github.com/rmjarvis/TreeCorr
It can compute correlations of regular number counts, weak lensing shears, or scalar quantities such as convergence or CMB temperature fluctutations.
2-point correlations may be auto-correlations or cross-correlations. This includes shear-shear, count-shear, count-count, kappa-kappa, etc. (Any combination of shear, kappa, and counts.)
3-point correlations currently can only be auto-correlations. This includes shear-shear-shear, count-count-count, and kappa-kappa-kappa. The cross varieties are planned to be added in the near future.
Both 2- and 3-point functions can be done with the correct curved-sky calculation using RA, Dec coordinates, on a Euclidean tangent plane, or in 3D using either (RA,Dec,r) or (x,y,z) positions.
The front end is in Python, which can be used as a Python module or as a standalone executable using configuration files. (The executable is corr2 for 2-point and corr3 for 3-point.)
The actual computation of the correlation functions is done in C++ using ball trees (similar to kd trees), which make the calculation extremely efficient.
When available, OpenMP is used to run in parallel on multi-core machines.
Approximate running time for 2-point shear-shear is ~30 sec * (N/10^6) / core for a bin size b=0.1 in log(r). It scales as b^(-2). This is the slowest of the various kinds of 2-point correlations, so others will be a bit faster, but with the same scaling with N and b.
The running time for 3-point functions are highly variable depending on the range of triangle geometries you are calculating. They are significantly slower than the 2-point functions, but many orders of magnitude faster than brute force algorithms.
If you use TreeCorr in published research, please reference: Jarvis, Bernstein, & Jain, 2004, MNRAS, 352, 338 (I’m working on new paper about TreeCorr, including some of the improvements I’ve made since then, but this will suffice as a reference for now.)
If you use the three-point multipole functionality of TreeCorr, please also reference Porth et al, 2023, arXiv:2309.08601
Record on the Astrophyics Source Code Library: http://ascl.net/1508.007
Developed by Mike Jarvis. Fee free to contact me with questions or comments at mikejarvis17 at gmail. Or post an issue (see below) if you have any problems with the code.
The code is licensed under a FreeBSD license. Essentially, you can use the code in any way you want, but if you distribute it, you need to include the file TreeCorr_LICENSE with the distribution. See that file for details.
Installation
The easiest ways to install TreeCorr are either with pip:
pip install treecorr
or with conda:
conda install -c conda-forge treecorr
If you have previously installed TreeCorr, and want to upgrade to a new released version, you should do:
pip install treecorr --upgrade
or:
conda update -c conda-forge treecorr
Depending on the write permissions of the python distribution for your specific system, you might need to use one of the following variants for pip installation:
sudo pip install treecorr pip install treecorr --user
The latter installs the Python module into ~/.local/lib/python3.X/site-packages, which is normally already in your PYTHONPATH, but it puts the executables corr2 and corr3 into ~/.local/bin which is probably not in your PATH. To use these scripts, you should add this directory to your PATH. If you would rather install into a different prefix rather than ~/.local, you can use:
pip install treecorr --install-option="--prefix=PREFIX"
This would install the executables into PREFIX/bin and the Python module into PREFIX/lib/python3.X/site-packages.
If you would rather download the tarball and install TreeCorr yourself, that is also relatively straightforward:
1. Download TreeCorr
You can download the latest tarball from:
https://github.com/rmjarvis/TreeCorr/releases/Or you can clone the repository using either of the following:
git clone git@github.com:rmjarvis/TreeCorr.git git clone https://github.com/rmjarvis/TreeCorr.gitwhich will start out in the current stable release branch.
Either way, cd into the TreeCorr directory.
2. Install dependencies
All required dependencies should be installed automatically for you by pip or conda, so you should not need to worry about these. But if you are interested, the dependencies are:
numpy
pyyaml
LSSTDESC.Coord
pybind11
They can all be installed at once by running:
pip install -r requirements.txtor:
conda install -c conda-forge treecorr --only-deps
3. Install
You can then install TreeCorr from the local distribution. Typically this would be the command:
pip install .If you don’t have write permission in your python distribution, you might need to use:
pip install . --userIn addition to installing the Python module treecorr, this will install the executables corr2 and corr3 in a bin folder somewhere on your system. Look for a line like:
Installing corr2 script to /anaconda3/binor similar in the output to see where the scripts are installed. If the directory is not in your path, you will also get a warning message at the end letting you know which directory you should add to your path if you want to run these scripts.
4. Run Tests (optional)
If you want to run the unit tests, you can do the following:
pip install -r test_requirements.txt cd tests pytest
Two-point Correlations
This software is able to compute a variety of two-point correlations:
- NN:
The normal two-point correlation function of number counts (typically galaxy counts).
- GG:
Two-point shear-shear correlation function.
- KK:
Nominally the two-point kappa-kappa correlation function, although any scalar quantity can be used as “kappa”. In lensing, kappa is the convergence, but this could be used for temperature, size, etc.
- NG:
Cross-correlation of counts with shear. This is what is often called galaxy-galaxy lensing.
- NK:
Cross-correlation of counts with kappa. Again, “kappa” here can be any scalar quantity.
- KG:
Cross-correlation of convergence with shear. Like the NG calculation, but weighting the pairs by the kappa values the foreground points.
There are also additional combinations involving complex fields with different spin than 2 (shear is a spin-2 field). See Two-point Correlation Functions for more details.
Three-point Correlations
This software is not yet able to compute three-point cross-correlations, so the only avaiable three-point correlations are:
- NNN:
Three-point correlation function of number counts.
- GGG:
Three-point shear correlation function. We use the “natural components” called Gamma, described by Schneider & Lombardi (2003) (Astron.Astrophys. 397, 809) using the triangle centroid as the reference point.
- KKK:
Three-point kappa correlation function. Again, “kappa” here can be any scalar quantity.
See Three-point Correlation Functions for more details.
Running corr2 and corr3
The executables corr2 and corr3 each take one required command-line argument, which is the name of a configuration file:
corr2 config_file corr3 config_file
A sample configuration file for corr2 is provided, called sample.params. See Configuration Parameters for the complete documentation about the allowed parameters.
You can also specify parameters on the command line after the name of the configuration file. e.g.:
corr2 config_file file_name=file1.dat gg_file_name=file1.out corr2 config_file file_name=file2.dat gg_file_name=file2.out ...
This can be useful when running the program from a script for lots of input files.
See Using configuration files for more details.
Using the Python module
The typical usage in python is in three stages:
Define one or more Catalogs with the input data to be correlated.
Define the correlation function that you want to perform on those data.
Run the correlation by calling process.
Maybe write the results to a file or use them in some way.
For instance, computing a shear-shear correlation from an input file stored in a fits file would look something like the following:
>>> import treecorr >>> cat = treecorr.Catalog('cat.fits', ra_col='RA', dec_col='DEC', ... ra_units='degrees', dec_units='degrees', ... g1_col='GAMMA1', g2_col='GAMMA2') >>> gg = treecorr.GGCorrelation(min_sep=1., max_sep=100., bin_size=0.1, ... sep_units='arcmin') >>> gg.process(cat) >>> xip = gg.xip # The xi_plus correlation function >>> xim = gg.xim # The xi_minus correlation function >>> gg.write('gg.out') # Write results to a file
For more details, see our slightly longer Getting Started Guide.
Or for a more involved worked example, see our Jupyter notebook tutorial.
And for the complete details about all aspects of the code, see the Sphinx-generated documentation.
Reporting bugs
If you find a bug running the code, please report it at:
https://github.com/rmjarvis/TreeCorr/issues
Click “New Issue”, which will open up a form for you to fill in with the details of the problem you are having.
Requesting features
If you would like to request a new feature, do the same thing. Open a new issue and fill in the details of the feature you would like added to TreeCorr. Or if there is already an issue for your desired feature, please add to the discussion, describing your use case. The more people who say they want a feature, the more likely I am to get around to it sooner than later.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file treecorr-5.0.2.tar.gz
.
File metadata
- Download URL: treecorr-5.0.2.tar.gz
- Upload date:
- Size: 988.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c22b365bb1787dccb2873340511b9ea7c45a184fa0192f0a84fb84a9079e659 |
|
MD5 | 650d0a1fb36996a338cb642836d3925b |
|
BLAKE2b-256 | e1e6568b4048d20a220afe1d3204630c6f3f726d09e1138d2a1c95e5557838aa |
File details
Details for the file TreeCorr-5.0.2-cp312-cp312-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp312-cp312-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 11.7 MB
- Tags: CPython 3.12, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b702eb4474c92a65aacba6d2785b65e0ec3e6f30dfbc239d874c0d458d0c4ecf |
|
MD5 | 8b0571e290eca43803886a4c43179ab4 |
|
BLAKE2b-256 | 93056bd51c2139dae2fe34d971641fb7b7f1d17090f9c395bab5e5d43d0b169a |
File details
Details for the file TreeCorr-5.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 11.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70b8305d8157e38cb6ef14808f29e32627a50e28d417023cda6651b037ae0fdd |
|
MD5 | fe497ea0507f7402d8d53b22831179fc |
|
BLAKE2b-256 | 6d96e9d80e2c0ec1768ba52cf051752d6b83fa14fd85a0853fd81f15a7c0b3af |
File details
Details for the file TreeCorr-5.0.2-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 905.8 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0417140807a70f7fff12a1099e7f84d28f5322eeaa05729355c2c8a1e23ba53 |
|
MD5 | 5f61f9c20a68d529a4cba343bb7770c3 |
|
BLAKE2b-256 | b9ebc2442bf699062664a38167bb0b2419db95ea5969f429ad34ece1962f1ce0 |
File details
Details for the file TreeCorr-5.0.2-cp311-cp311-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp311-cp311-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 11.6 MB
- Tags: CPython 3.11, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1126a6ee60ec05845e3fba79d2544a2cdb129f49ed265ce951c09ca33240230 |
|
MD5 | 48548d6981e851370d223765216d56d3 |
|
BLAKE2b-256 | 3df41510240337f771b15c1046519519197965a926fd3c90e969222f68068d14 |
File details
Details for the file TreeCorr-5.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 11.4 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9af256a6dfa2c1345fd994a0d15e5b428b450d37b4e1cd2a6678eb5840c4348 |
|
MD5 | 42a0eeaf8e5ab13570e04f55d7d2f542 |
|
BLAKE2b-256 | c421af5240eddcc47d267970f61d3aae59c4ce3c0272ef62e9f88a7d0040d435 |
File details
Details for the file TreeCorr-5.0.2-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 901.3 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea44a5b48db7870cc6753b6493f293987a379092af4ada38e703d85346d0617d |
|
MD5 | f8b1c6c12723ef3caeea05f2a029347d |
|
BLAKE2b-256 | eb131a36694479baefad633e44b496422ae5c1cf0eb5d9595a7829890275020e |
File details
Details for the file TreeCorr-5.0.2-cp310-cp310-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp310-cp310-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 11.6 MB
- Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71479bcefd7b3cf950dfd7e1d443b967da3312d969ca9b4ef6720cc8eeed23fc |
|
MD5 | 32a2e155e72c23fa385cc73a96c0ce95 |
|
BLAKE2b-256 | cfb203d988612a784fbe89a40d22f3870394b696aa38784700360e74ee094ee6 |
File details
Details for the file TreeCorr-5.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 11.4 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be6f4f87ae032ec30e4f2a0c8f0af6ea536331ed64a762253bbc22ad5554cb2a |
|
MD5 | a661db1e2a58800104bf295e04471b41 |
|
BLAKE2b-256 | 98d36a96a88c61075220326506d3be717275a187ae0c7ca9f683327270a16117 |
File details
Details for the file TreeCorr-5.0.2-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 899.9 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e81a5045c49677d63600f1492bfb544978c5dc3678bbe57d0f0efd702a2eac0 |
|
MD5 | 64a8b4122b67c7ffe1ca69be814d77c7 |
|
BLAKE2b-256 | 56e7ef977ca6ab534de07647b4108a2e9cf99bbf03bd2fb08345d88f245ad1ba |
File details
Details for the file TreeCorr-5.0.2-cp39-cp39-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp39-cp39-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 11.6 MB
- Tags: CPython 3.9, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8398ec39c6b52fe06b2fc608602b238c2237031c68b4faa6ba917a9c7b59b698 |
|
MD5 | 6e89390e15e935fedc28b1c56604933b |
|
BLAKE2b-256 | 6ae0e098d9330c3e765eed5a2c895b9a65009e4566fb9d3c07b0139fbaa93236 |
File details
Details for the file TreeCorr-5.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 11.4 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19497e19d2dfe23409cc74b44da9ac2c0f0959d5defc72ee3b5c6f24dddc6064 |
|
MD5 | 8eb7485774a6600ec2dedd0799b66d65 |
|
BLAKE2b-256 | e8e75e5442cfaa198575a9efc36ecd6ffeba2f400473c08a6023f60dfc536c35 |
File details
Details for the file TreeCorr-5.0.2-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 899.9 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b1a1b5393056d5c854347ee833e6aadf71d4471657d594eb8e0fb64995cf4e3 |
|
MD5 | fed6bce0e890127acd159f5c5e5db49a |
|
BLAKE2b-256 | 61cc60a9cfbc6acbe93d92994b224b4e24fab767288f3d5e1b770982584e4b44 |
File details
Details for the file TreeCorr-5.0.2-cp38-cp38-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp38-cp38-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 11.6 MB
- Tags: CPython 3.8, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 678b975bdbad6cc5e519cac3d127e328811165852abfc44ff96938849017e474 |
|
MD5 | 6b5012abfbbc47c706e1d80587fe727f |
|
BLAKE2b-256 | ed0a036df835baeb2efdd14adf6bf018fa420868f97d61e08100044e5f5776b9 |
File details
Details for the file TreeCorr-5.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 11.4 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06e2a4a6e9c1c538debefc4b0967259dbcaa1429b6ec2843c9611cd73aad2f61 |
|
MD5 | 4674d44b6d7579f93fe26f63ed4d987d |
|
BLAKE2b-256 | 00d82e96799de04be2ca8327603bb026cb0eaf91335ba2483e13097523dc1199 |
File details
Details for the file TreeCorr-5.0.2-cp38-cp38-macosx_11_0_arm64.whl
.
File metadata
- Download URL: TreeCorr-5.0.2-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 899.8 kB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c1f76a1ecfff27a0812bf0872af184392dcfc9d891691556a33b4453be803a4 |
|
MD5 | 1f24df853dd92db0096c589122d7c73c |
|
BLAKE2b-256 | 7050f72037c0a6825514af666f2eecb6f764c2d692842ce2febf5ecdcd40448a |