Skip to main content

Automated Strong Gravitational Lens Modeling

Project description

PyAutoLens

When two or more galaxies are aligned perfectly down our line-of-sight, the background galaxy appears multiple times. This is called strong gravitational lensing, & PyAutoLens makes it simple to model strong gravitational lenses, like this one:

.. image:: https://github.com/Jammy2211/PyAutoLens/blob/development/imageaxis.png

Installation

PyAutoLens requires Python 3.6+ and you can install it via pip or conda (see this link <https://pyautolens.readthedocs.io/en/latest/general/installation.html#installation-with-conda>_ for conda instructions).

.. code-block:: bash

pip install autolens

Next, clone the autolens_workspace <https://github.com/Jammy2211/autolens_workspace>_, which includes PyAutoLens configuration files, example scripts and more!

.. code-block:: bash

cd /path/on/your/computer/you/want/to/put/the/autolens_workspace git clone https://github.com/Jammy2211/autolens_workspace --depth 1 cd autolens_workspace

Finally, run welcome.py in the autolens_workspace to get started!

.. code-block:: bash

python3 welcome.py

If your installation had an error, check the troubleshooting section <https://pyautolens.readthedocs.io/en/latest/general/installation.html#trouble-shooting>_ on our readthedocs.

If you would prefer to Fork or Clone the PyAutoLens GitHub repo, checkout the cloning section <https://pyautolens.readthedocs.io/en/latest/general/installation.html#forking-cloning>_ on our readthedocs.

API Overview

Lensing calculations are performed in PyAutoLens by building a Tracer object from LightProfile, MassProfile and Galaxy objects. Below, we create a simple strong lens system where a redshift 0.5 lens Galaxy with an EllipticalIsothermal MassProfile lenses a background source at redshift 1.0 with an EllipticalExponential LightProfile representing a disk.

.. code-block:: python

import autolens as al
import autolens.plot as aplt

"""
To describe the deflection of light by mass, two-dimensional grids of (y,x) Cartesian
coordinates are used.
"""

grid = al.Grid.uniform(
    shape_2d=(50, 50),
    pixel_scales=0.05,  # <- Conversion from pixel units to arc-seconds.
)

"""The lens galaxy has an EllipticalIsothermal MassProfile and is at redshift 0.5."""

mass = al.mp.EllipticalIsothermal(
    centre=(0.0, 0.0), elliptical_comps=(0.1, 0.05), einstein_radius=1.6
)

lens_galaxy = al.Galaxy(redshift=0.5, mass=mass)

"""The source galaxy has an EllipticalExponential LightProfile and is at redshift 1.0."""

disk = al.lp.EllipticalExponential(
    centre=(0.3, 0.2),
    elliptical_comps=(0.05, 0.25),
    intensity=0.05,
    effective_radius=0.5,
)

source_galaxy = al.Galaxy(redshift=1.0, disk=disk)

"""
We create the strong lens using a Tracer, which uses the galaxies, their redshifts
and an input cosmology to determine how light is deflected on its path to Earth.
"""

tracer = al.Tracer.from_galaxies(
    galaxies=[lens_galaxy, source_galaxy], cosmology=cosmo.Planck15
)

"""
We can use the Grid and Tracer to perform many lensing calculations, for example
plotting the image of the lensed source.
"""

aplt.Tracer.image(tracer=tracer, grid=grid)

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

.. code-block:: python

import autofit as af
import autolens as al
import autolens.plot as aplt

"""Use the dataset path and lens name to load the imaging data."""

imaging = al.Imaging.from_fits(
    image_path="/path/to/dataset/image.fits",
    noise_map_path="/path/to/dataset/noise_map.fits",
    psf_path="/path/to/dataset/psf.fits",
    pixel_scales=0.1,
)

"""Create a mask for the data, which we setup as a 3.0" circle."""

mask = al.Mask2D.circular(
    shape_2d=imaging.shape_2d, pixel_scales=imaging.pixel_scales, radius=3.0
)

"""
We model our lens galaxy using an EllipticalIsothermal MassProfile &
our source galaxy as an EllipticalSersic LightProfile.
"""

lens_mass_profile = al.mp.EllipticalIsothermal
source_light_profile = al.lp.EllipticalSersic

"""
To setup our model galaxies, we use the GalaxyModel class, which represents a
galaxy whose parameters are free & fitted for by PyAutoLens.
"""

lens_galaxy_model = al.GalaxyModel(redshift=0.5, mass=lens_mass_profile)
source_galaxy_model = al.GalaxyModel(redshift=1.0, disk=source_light_profile)

"""
To perform the analysis we set up a phase, which takes our galaxy models & fits
their parameters using a `NonLinearSearch` (in this case, Dynesty).
"""

phase = al.PhaseImaging(
    search=af.DynestyStatic(name="phase[example]",n_live_points=50),
    galaxies=dict(lens=lens_galaxy_model, source=source_galaxy_model),
)

"""
We pass the imaging `data` and `mask` to the phase, thereby fitting it with the lens
model & plot the resulting fit.
"""

result = phase.run(dataset=imaging, mask=mask)
aplt.FitImaging.subplot_fit_imaging(fit=result.max_log_likelihood_fit)

Getting Started

To get started checkout our readthedocs <https://pyautolens.readthedocs.io/>, where you'll find the installation guide, a complete overview of PyAutoLens's features, examples scripts and tutorials, detailed API documentation and the HowToLens Jupyter notebook lecture series <https://pyautolens.readthedocs.io/en/latest/howtolens/howtolens.html> on which introduces new users to strong gravitational lensing with PyAutoLens.

Support

Support for installation issues, help with lens modeling and using PyAutoLens is available by raising an issue on the autolens_workspace GitHub page <https://github.com/Jammy2211/autolens_workspace/issues>. or joining the PyAutoLens Slack channel <https://pyautolens.slack.com/>, where we also provide the latest updates on PyAutoLens.

Slack is invitation-only, so if you'd like to join send an email <https://github.com/Jammy2211>_ requesting an invite.

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

autolens-1.7.1.tar.gz (119.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autolens-1.7.1-py3-none-any.whl (231.5 kB view details)

Uploaded Python 3

File details

Details for the file autolens-1.7.1.tar.gz.

File metadata

  • Download URL: autolens-1.7.1.tar.gz
  • Upload date:
  • Size: 119.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.9

File hashes

Hashes for autolens-1.7.1.tar.gz
Algorithm Hash digest
SHA256 90226033e19ac8f2671f95bb9a3adbcbc0626fa4d800c9e647e2d000a6b9ed96
MD5 4521350725ec97bba16c193b4a488c15
BLAKE2b-256 69198a8cd6cc1c438e0f24cf96997695e8ec756b015dd38dd2b8d40d66dbb3af

See more details on using hashes here.

File details

Details for the file autolens-1.7.1-py3-none-any.whl.

File metadata

  • Download URL: autolens-1.7.1-py3-none-any.whl
  • Upload date:
  • Size: 231.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.9

File hashes

Hashes for autolens-1.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32b2cad4cf358d8055a44f7e075ff8fb9ec1847e01e433df8c6f8e77f9558a25
MD5 66a0bb6575fb7ad171d32277b6b2d5db
BLAKE2b-256 04db1597d721bdef9de7dd7bbd903075e9a550271531d903600a81d1e75349aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page