PyAutoLens
When two or more galaxies are aligned perfectly down our line-of-sight, the background galaxy is strongly lensed and appears multiple times or as an Einstein ring of light. PyAutoLens makes it simple to model strong gravitational lenses, like this one:
PyAutoLens is based on the following papers:
Adaptive Semi-linear Inversion of Strong Gravitational Lens Imaging
AutoLens: Automated Modeling of a Strong Lens's Light, Mass and Source
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 autofit import conf
from autofit.optimize import non_linear as nl
from autolens.pipeline import phase as ph
from autolens.data.array import mask as msk
from autolens.model.galaxy import galaxy_model as gm
from autolens.data import ccd
from autolens.model.profiles import light_profiles as lp
from autolens.model.profiles import mass_profiles as mp
from autolens.data.plotters import ccd_plotters
from autolens.lens.plotters import lens_fit_plotters
import os
# In this example, we'll generate a phase which fits a simple lens + source plane system.
# Get the relative path to the data in our workspace and load the ccd imaging data.
path = '{}/../'.format(os.path.dirname(os.path.realpath(__file__)))
lens_name = 'example_lens'
ccd_data = ccd.load_ccd_data_from_fits(image_path=path + '/data/' + lens_name + '/image.fits',
psf_path=path+'/data/'+lens_name+'/psf.fits',
noise_map_path=path+'/data/'+lens_name+'/noise_map.fits',
pixel_scale=0.1)
# Create a mask for the data, which we setup below as a 3.0" circle.
mask = msk.Mask.circular(shape=ccd_data.shape, pixel_scale=ccd_data.pixel_scale, radius_arcsec=3.0)
# We model our lens galaxy using a mass profile (a singular isothermal ellipsoid) and our source galaxy
# a light profile (an elliptical Sersic). We load these profiles from the 'light_profiles (lp)' and
# 'mass_profiles (mp)' modules.
lens_mass_profile = mp.EllipticalIsothermal
source_light_profile = lp.EllipticalSersic
# To setup our model galaxies, we use the GalaxyModel class, representing a galaxy the parameters of
# which are variable and fitted for by the analysis.
lens_galaxy_model = gm.GalaxyModel(mass=lens_mass_profile)
source_galaxy_model = gm.GalaxyModel(light=source_light_profile)
# 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=dict(lens=gm.GalaxyModel(mass=mp.EllipticalIsothermal)),
source_galaxies=dict(source=gm.GalaxyModel(light=lp.EllipticalSersic)),
optimizer_class=nl.MultiNest, phase_name='example/phase_example')
# We run the phase on the ccd data, print the results and plot the fit.
result = phase.run(data=ccd_data)
lens_fit_plotters.plot_fit_subplot(fit=result.most_likely_fit)
Slack
We're building a PyAutoLens community on Slack, so you should contact us on our Slack channel before getting started. 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.
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 - (February 2019) - Adapt the lensing analysis to the features of the observed strong lens imaging.
- Multi-Plane - (April 2019) Model multi-plane lenses, including systems with multiple lensed source galaxies.
HowToLens
Included with PyAutoLens is the HowToLens eBook, which provides an introduction to strong gravitational lens modeling with PyAutoLens. It can be found in the workspace and consists of 4 chapters:
- Introduction - An introduction to strong gravitational lensing and PyAutolens.
- 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.
Workspace
PyAutoLens includes a workspace, which includes template scripts, examples and the HowToLens eBook. If you install PyAutoLens with conda or pip the workspace these should be included, however if not then workspace can be found on the master branch of this git repository.
If you install PyAutoLens with Docker a workspace will be generated for you in the home directory the first time you run the image. After the first time you run docker the workspace will persist any changes you make and won't be updated again.
Depedencies
PyAutoLens requires PyMultiNest and Numba.
Installation with conda
We recommend installation using a conda environment as this circumvents a number of compatibility issues when installing PyMultiNest.
First, install conda.
Create a conda environment:
conda create -n autolens python=3.7 anaconda
Install multinest:
conda install -c conda-forge multinest
Tell matplotlib what backend to use:
echo "backend : TKAgg" > ~/.matplotlib/matplotlibrc
Install autolens:
pip install autolens
Installation with pip
Installation is also available via pip, however there are reported issues with installing PyMultiNest that can make installation difficult, see the file INSTALL.notes
$ pip install autolens
Installation with Docker
An alternative to conda and pip is Docker, which 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 PyAutoLens 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 127.0.0.1)' with '127.0.0.1'. 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.
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.
Publications
The following papers use PyAutoLens:
Novel Substructure and Superfluid Dark Matter
Credits
James Nightingale - Lead developer and PyAutoLens guru.
Richard Hayes - Lead developer and PyAutoFit guru.
Ashley Kelly - Developer of pyquad for fast deflections computations.
Nan Li - Docker integration & support.
Andrew Robertson - Critical curve and caustic calculations.
Andrea Enia - Voronoi source-plane plotting tools.
Metadata
Release files for autolens 0.9.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| autolens-0.9.16.tar.gz | 366.9 kB | Without provenance | Details for autolens-0.9.16.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| autolens-0.9.16-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for autolens-0.9.16-py2.py3-none-any.whl |
Total release size: 933.3 kB
Release files / autolens-0.9.16.tar.gz
| Download URL | autolens-0.9.16.tar.gz |
|---|---|
| Size | 366.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d8304c431f2360a6e74db11371ba2d06dd85f4a4ff1085210ffee2edc83dafb
|
|
BLAKE2b-256 checksum How to use checksums |
9268b3d55ac1bd12f97cf73142b68fe01ed55c33678b8a016ffd5ad82fd851d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/33.1.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15rc1
|
Release files / autolens-0.9.16-py2.py3-none-any.whl
| Download URL | autolens-0.9.16-py2.py3-none-any.whl |
|---|---|
| Size | 566.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
376feb5d85fd15150b3a3baca48c8dab7405b1b2527cc3792afee96d3e9fe185
|
|
BLAKE2b-256 checksum How to use checksums |
c75b4e5edc836daf11b78755c9ce3e0268a05df68c14a8415fc9c7d93bcd0ff4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/33.1.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15rc1
|
Security for autolens 0.9.16
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.