Welcome to LensTools!

This python package collects together a suite of widely used analysis tools in Weak Gravitational Lensing


This python add-on will handle basically every operation you will need to perform on Weak Lensing survey data; the distribution includes a range of tools in image analysis, statistical processing and numerical theory predictions and supports multiprocessing using the mpi4py module. This package includes many useful features, including:

  • Measure units handling through astropy
  • Complete flexibility and easy customization of input/output formats
  • Efficient measurements of power spectrum, PDF, Minkowski functionals and peak counts of convergence maps
  • Survey masks
  • Efficient \(E\) and \(B\) mode decompositions of shear maps
  • Artificial noise generation engines
  • Easy to compute parameter statistical inferences
  • Easy input/output from \(N\)-body simulation snapshots in the Gadget2 binary format
  • Interfaces with existing simulation sets
  • Ray Tracing simulations (in development...)
  • CPU vectorization of expensive computations via numpy
  • Easy multiprocessing and cluster deployment via the mpi4py module
  • Future prospect: taking advantage of numpy offload capabilities to Intel Xeon Phi coprocessors to boost performance (planned)


The easiest way is to install through pip

pip install lenstools

An alternative is to install from source by cloning or forking the github repository to download the source and build it manually. First clone the repository (the original one, or your fork):

git clone https://github.com/apetri/LensTools

Then, inside the LensTools directory build the source:

python setup.py build

If you want to test the build before installing to your system, look to the instructions in Test. Once you are satisfied install the package (might require root privileges depending on the install location):

python setup.py install


The core features require the standard numpy, scipy and the more unusual astropy (mainly for the cosmology and measure units support) and emcee (from which LensTools borrows the MPI Pool utility), and the Test suite requires additionally the matplotlib package. matpoltlib should eventually be installed if you want to use the plotting engines of LensTools. If you want to run the calculations in parallel on a computer cluster you will need to install mpi4py (a python wrapper for the MPI library). Installation of all these packages is advised (if you run astrophysical data analyses you should use them anyway). One of the lenstools features, namely the Design class, requires that you have a working version of GSL to link to; if you don’t have one, just hit enter during the installation process and the package will work correctly without this additional feature.


To check that everything works before installing you can run the pre implemented test suite that comes with the source code. First you will need to install pytest, then you need to download some data files (mainly FITS images) that the test suite depends on (you can find these data files here, the file is approximately 250MB). Once you downloaded it into the Test directory unpack it:

tar -xvf data.tar.gz

Then you’re good to go! Just run:


Each test, if successful, will produce some PNG plots.


The code is maintained and developed on github, pull requests are welcome!


Copyright 2014 Andrea Petri and contributors; lenstools is free software made available under the MIT License. For details see the LICENSE file

Indices and tables