Skip to main content

Strong Gravitational Lensing for the masses

Project description

# PyAutoLens

PyAutoLens makes it simple to model strong gravitational lenses. It is based on the following papers:<br/>

## Slack

We're building a PyAutoLens community on Slack, so you should contact us on our [Slack channel]( before getting started with PyAutoLens. Here, I can introduce you to the community, give you the latest update on the software and discuss how best to use PyAutoLens for your science case.

Unfortunately, Slack is invitation-only, so first send me an [email]( requesting an invite.

## Installation with Docker

We recommend you install AutoLens using Docker. It makes installation easier by containerising the project.

If you don't have Docker then you can install it by following the guide [here](

Once you have Docker installed you can download the AutoLens Docker project with the command:

docker pull autolens/autolens

This command can also be used to update the project.

The project can be run using:

docker run -it -e LOCAL_USER_ID=`id -u $USER` -h autolens -p 8888:8888 -p 6006:6006 -v $HOME/autolens_workspace:/home/user/workspace autolens/autolens

Once the project is running Docker will provide you with a URL. Copy and paste this URL into your browser, making sure you replace '(PyAutoLens or' with ''. This will bring up a Jupyter notebook including the 'howtolens' directory which is full of tutorials.

Any changes you make inside the Docker workspace will be saved in the autolens_workspace in your home directory.

## Installation with pip

Installation is also available via pip, however there are a number of dependencies that can be installation difficult, see the file [INSTALL.notes](

AutoLens requires [PyMultiNest]( and [Numba](

$ pip install autolens

## Workspace

If you install AutoLens with Docker a workspace will be generated for you in the home directory the first time you run the image. This contains configuration, examples and tutorials. After the first time you run docker the workspace will persist any changes you make and won't be updated again.

If you installed AutoLens with pip or want to get access to the latest workspace then you can download it from [here](

## Features

PyAutoLens's advanced modeling features include:

- **Pipelines** - build automated analysis pipelines to fit complex lens models to large samples of strong lenses.
- **Inversions** - Reconstruct complex source galaxy morphologies on a variety of pixel-grids.
- **Adaption** - (December 2018) - Adapt the lensing analysis to the features of the observed strong lens imaging.
- **Multi-Plane** - (January 2018) Model multi-plane lenses, including systems with multiple lensed source galaxies.

## HowToLens

Detailed tutorials demonstrating how to use PyAutoLens can be found in the 'workspace/howtolens' folder:

- **Introduction** - An introduction to strong gravitational lensing and PyAutolens, familiarizing you with the interface and project structure.
- **Lens Modeling** - How to model strong lenses, including a primer on Bayesian non-linear analysis.
- **Pipelines** - How to build pipelines and tailor them to your own science case.
- **Inversions** - How to perform pixelized reconstructions of the source-galaxy.

## Support & Discussion

If you're having difficulty with installation, lens modeling, or just want a chat, feel free to message us on our [Slack channel](

## Contributing

If you have any suggestions or would like to contribute please get in touch.

## Python Example

With PyAutoLens, you can begin modeling a lens in just a couple of minutes. The example below demonstrates a simple analysis which fits a lens galaxy's light, mass and a source galaxy.

from autolens.pipeline import phase as ph
from autofit.core import non_linear as nl
from autolens.lensing import galaxy_model as gm
from autolens.imaging import image as im
from autolens.profiles import light_profiles as lp
from autolens.profiles import mass_profiles as mp
from autolens.plotting import fitting_plotters
import os

# In this example, we'll generate a phase which fits a lens + source plane system.

# First, lets setup the path to this script so we can easily load the example data.
path = "{}".format(os.path.dirname(os.path.realpath(__file__)))

# Now, load the image, noise-map and PSF from the 'data' folder.
image = im.load_imaging_from_path(image_path=path + '/data/image.fits',
noise_map_path=path + '/data/noise_maps.fits',
psf_path=path + '/data/psf.fits', pixel_scale=0.1)

# We're going to model our lens galaxy using a light profile (an elliptical Sersic) and mass profile
# (a singular isothermal sphere). We load these profiles from the 'light_profile (lp)' and 'mass_profile (mp)'
# modules (check out the source code to see all the profiles that are available).

# To setup our model galaxies, we use the 'galaxy_model' module and GalaxyModel class.
# A GalaxyModel represents a galaxy where the parameters of its associated profiles are
# variable and fitted for by the analysis.
lens_galaxy_model = gm.GalaxyModel(light=lp.AbstractEllipticalSersic, mass=mp.EllipticalIsothermal)
source_galaxy_model = gm.GalaxyModel(light=lp.AbstractEllipticalSersic)

# To perform the analysis, we set up a phase using the 'phase' module (imported as 'ph').
# A phase takes our galaxy models and fits their parameters using a non-linear search (in this case, MultiNest).
phase = ph.LensSourcePlanePhase(lens_galaxies=[lens_galaxy_model], source_galaxies=[source_galaxy_model],
optimizer_class=nl.MultiNest, phase_name='phase_example')

# We run the phase on the image, print the results and plot the fit.
results =


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
autolens-0.8.13-py2.py3-none-any.whl (430.6 kB) Copy SHA256 hash SHA256 Wheel py2.py3
autolens-0.8.13.tar.gz (296.9 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page