autolens


Nameautolens JSON
Version 2024.11.13.2 PyPI version JSON
download
home_pagehttps://github.com/Jammy2211/PyAutoLens
SummaryOpen-Source Strong Lensing
upload_time2024-11-13 13:50:46
maintainerNone
docs_urlNone
authorJames Nightingale and Richard Hayes
requires_pythonNone
licenseMIT License
keywords cli
VCS
bugtrack_url
requirements nautilus-sampler
Travis-CI No Travis.
coveralls test coverage No coveralls.
            PyAutoLens: Open-Source Strong Lensing
======================================

.. |nbsp| unicode:: 0xA0
    :trim:

.. |binder| image:: https://mybinder.org/badge_logo.svg
   :target: https://mybinder.org/v2/gh/Jammy2211/autolens_workspace/HEAD

.. |RTD| image:: https://readthedocs.org/projects/pyautolens/badge/?version=latest
    :target: https://pyautolens.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status

.. |Tests| image:: https://github.com/Jammy2211/PyAutoLens/actions/workflows/main.yml/badge.svg
   :target: https://github.com/Jammy2211/PyAutoLens/actions

.. |Build| image:: https://github.com/Jammy2211/PyAutoBuild/actions/workflows/release.yml/badge.svg
   :target: https://github.com/Jammy2211/PyAutoBuild/actions

.. |code-style| image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

.. |JOSS| image:: https://joss.theoj.org/papers/10.21105/joss.02825/status.svg
   :target: https://doi.org/10.21105/joss.02825

.. |arXiv| image:: https://img.shields.io/badge/arXiv-1708.07377-blue
    :target: https://arxiv.org/abs/1708.07377

|binder| |RTD| |Tests| |Build| |code-style| |JOSS| |arXiv|

`Installation Guide <https://pyautolens.readthedocs.io/en/latest/installation/overview.html>`_ |
`readthedocs <https://pyautolens.readthedocs.io/en/latest/index.html>`_ |
`Introduction on Binder <https://mybinder.org/v2/gh/Jammy2211/autolens_workspace/release?filepath=start_here.ipynb>`_ |
`HowToLens <https://pyautolens.readthedocs.io/en/latest/howtolens/howtolens.html>`_

.. image:: https://github.com/Jammy2211/PyAutoLogo/blob/main/gifs/pyautolens.gif?raw=true
  :width: 900

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 and **PyAutoLens** makes it simple to model strong gravitational lenses.

Getting Started
---------------

The following links are useful for new starters:

- `The PyAutoLens readthedocs <https://pyautolens.readthedocs.io/en/latest>`_: which includes `an overview of PyAutoLens's core features <https://pyautolens.readthedocs.io/en/latest/overview/overview_1_start_here.html>`_, `a new user starting guide <https://pyautolens.readthedocs.io/en/latest/overview/overview_2_new_user_guide.html>`_ and `an installation guide <https://pyautolens.readthedocs.io/en/latest/installation/overview.html>`_.

- `The introduction Jupyter Notebook on Binder <https://mybinder.org/v2/gh/Jammy2211/autolens_workspace/release?filepath=start_here.ipynb>`_: try **PyAutoLens** in a web browser (without installation).

- `The autolens_workspace GitHub repository <https://github.com/Jammy2211/autolens_workspace>`_: example scripts and the HowToLens Jupyter notebook lectures.

Support
-------

Support for installation issues, help with lens modeling and using **PyAutoLens** is available by
`raising an issue on the GitHub issues page <https://github.com/Jammy2211/PyAutoLens/issues>`_.

We also offer support on 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.

HowToLens
---------

For users less familiar with gravitational lensing, Bayesian inference and scientific analysis
you may wish to read through the **HowToLens** lectures. These teach you the basic principles of gravitational lensing
and Bayesian inference, with the content pitched at undergraduate level and above.

A complete overview of the lectures `is provided on the HowToLens readthedocs page <https://pyautolens.readthedocs.io/en/latest/howtolens/howtolens.html>`_

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 ``Isothermal`` ``MassProfile`` lenses a background source at redshift 1.0 with an
``Exponential`` ``LightProfile`` representing a disk.

.. code-block:: python

    import autolens as al
    import autolens.plot as aplt
    from astropy import cosmology as cosmo

    """
    To describe the deflection of light by mass, two-dimensional grids of (y,x) Cartesian
    coordinates are used.
    """
    grid = al.Grid2D.uniform(
        shape_native=(50, 50),
        pixel_scales=0.05,  # <- Conversion from pixel units to arc-seconds.
    )

    """
    The lens galaxy has an elliptical isothermal mass profile and is at redshift 0.5.
    """
    mass = al.mp.Isothermal(
        centre=(0.0, 0.0), ell_comps=(0.1, 0.05), einstein_radius=1.6
    )

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

    """
    The source galaxy has an elliptical exponential light profile and is at redshift 1.0.
    """
    disk = al.lp.Exponential(
        centre=(0.3, 0.2),
        ell_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(
        galaxies=[lens_galaxy, source_galaxy], 
        cosmology = al.cosmo.Planck15()
    )

    """
    We can use the Grid2D and Tracer to perform many lensing calculations, for example
    plotting the image of the lensed source.
    """
    tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid)
    tracer_plotter.figures_2d(image=True)

With **PyAutoLens**, you can begin modeling a lens in minutes. The example below demonstrates a simple analysis which
fits the lens galaxy's mass with an ``Isothermal`` and the source galaxy's light with a ``Sersic``.

.. code-block:: python

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

    """
    Load Imaging data of the strong lens from the dataset folder of the workspace.
    """
    dataset = al.Imaging.from_fits(
        data_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 imaging data, which we setup as a 3.0" circle, and apply it.
    """
    mask = al.Mask2D.circular(
        shape_native=dataset.shape_native,
        pixel_scales=dataset.pixel_scales,
        radius=3.0
    )
    dataset = dataset.apply_mask(mask=mask)

    """
    We model the lens galaxy using an elliptical isothermal mass profile and
    the source galaxy using an elliptical sersic light profile.

    To setup these profiles as model components whose parameters are free & fitted for
    we set up each Galaxy as a `Model` and define the model as a `Collection` of all galaxies.
    """
    # Lens:

    mass = af.Model(al.mp.Isothermal)
    lens = af.Model(al.Galaxy, redshift=0.5, mass=lens_mass_profile)

    # Source:

    disk = af.Model(al.lp.Sersic)
    source = af.Model(al.Galaxy, redshift=1.0, disk=disk)

    # Overall Lens Model:
    model = af.Collection(galaxies=af.Collection(lens=lens, source=source))

    """
    We define the non-linear search used to fit the model to the data (in this case, Dynesty).
    """
    search = af.Nautilus(name="search[example]", n_live=50)

    """
    We next set up the `Analysis`, which contains the `log likelihood function` that the
    non-linear search calls to fit the lens model to the data.
    """
    analysis = al.AnalysisImaging(dataset=dataset)

    """
    To perform the model-fit we pass the model and analysis to the search's fit method. This will
    output results (e.g., dynesty samples, model parameters, visualization) to hard-disk.
    """
    result = search.fit(model=model, analysis=analysis)

    """
    The results contain information on the fit, for example the maximum likelihood
    model from the Dynesty parameter space search.
    """
    print(result.samples.max_log_likelihood())

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Jammy2211/PyAutoLens",
    "name": "autolens",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "cli",
    "author": "James Nightingale and Richard Hayes",
    "author_email": "james.w.nightingale@durham.ac.uk",
    "download_url": "https://files.pythonhosted.org/packages/e7/95/42d72b2a245149542e5494bf48aaf50caa6e0b41b6dd77700b08830b6425/autolens-2024.11.13.2.tar.gz",
    "platform": null,
    "description": "PyAutoLens: Open-Source Strong Lensing\n======================================\n\n.. |nbsp| unicode:: 0xA0\n    :trim:\n\n.. |binder| image:: https://mybinder.org/badge_logo.svg\n   :target: https://mybinder.org/v2/gh/Jammy2211/autolens_workspace/HEAD\n\n.. |RTD| image:: https://readthedocs.org/projects/pyautolens/badge/?version=latest\n    :target: https://pyautolens.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\n.. |Tests| image:: https://github.com/Jammy2211/PyAutoLens/actions/workflows/main.yml/badge.svg\n   :target: https://github.com/Jammy2211/PyAutoLens/actions\n\n.. |Build| image:: https://github.com/Jammy2211/PyAutoBuild/actions/workflows/release.yml/badge.svg\n   :target: https://github.com/Jammy2211/PyAutoBuild/actions\n\n.. |code-style| image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n\n.. |JOSS| image:: https://joss.theoj.org/papers/10.21105/joss.02825/status.svg\n   :target: https://doi.org/10.21105/joss.02825\n\n.. |arXiv| image:: https://img.shields.io/badge/arXiv-1708.07377-blue\n    :target: https://arxiv.org/abs/1708.07377\n\n|binder| |RTD| |Tests| |Build| |code-style| |JOSS| |arXiv|\n\n`Installation Guide <https://pyautolens.readthedocs.io/en/latest/installation/overview.html>`_ |\n`readthedocs <https://pyautolens.readthedocs.io/en/latest/index.html>`_ |\n`Introduction on Binder <https://mybinder.org/v2/gh/Jammy2211/autolens_workspace/release?filepath=start_here.ipynb>`_ |\n`HowToLens <https://pyautolens.readthedocs.io/en/latest/howtolens/howtolens.html>`_\n\n.. image:: https://github.com/Jammy2211/PyAutoLogo/blob/main/gifs/pyautolens.gif?raw=true\n  :width: 900\n\nWhen two or more galaxies are aligned perfectly down our line-of-sight, the background galaxy appears multiple times.\n\nThis is called strong gravitational lensing and **PyAutoLens** makes it simple to model strong gravitational lenses.\n\nGetting Started\n---------------\n\nThe following links are useful for new starters:\n\n- `The PyAutoLens readthedocs <https://pyautolens.readthedocs.io/en/latest>`_: which includes `an overview of PyAutoLens's core features <https://pyautolens.readthedocs.io/en/latest/overview/overview_1_start_here.html>`_, `a new user starting guide <https://pyautolens.readthedocs.io/en/latest/overview/overview_2_new_user_guide.html>`_ and `an installation guide <https://pyautolens.readthedocs.io/en/latest/installation/overview.html>`_.\n\n- `The introduction Jupyter Notebook on Binder <https://mybinder.org/v2/gh/Jammy2211/autolens_workspace/release?filepath=start_here.ipynb>`_: try **PyAutoLens** in a web browser (without installation).\n\n- `The autolens_workspace GitHub repository <https://github.com/Jammy2211/autolens_workspace>`_: example scripts and the HowToLens Jupyter notebook lectures.\n\nSupport\n-------\n\nSupport for installation issues, help with lens modeling and using **PyAutoLens** is available by\n`raising an issue on the GitHub issues page <https://github.com/Jammy2211/PyAutoLens/issues>`_.\n\nWe also offer support on the **PyAutoLens** `Slack channel <https://pyautolens.slack.com/>`_, where we also provide the\nlatest updates on **PyAutoLens**. Slack is invitation-only, so if you'd like to join send\nan `email <https://github.com/Jammy2211>`_ requesting an invite.\n\nHowToLens\n---------\n\nFor users less familiar with gravitational lensing, Bayesian inference and scientific analysis\nyou may wish to read through the **HowToLens** lectures. These teach you the basic principles of gravitational lensing\nand Bayesian inference, with the content pitched at undergraduate level and above.\n\nA complete overview of the lectures `is provided on the HowToLens readthedocs page <https://pyautolens.readthedocs.io/en/latest/howtolens/howtolens.html>`_\n\nAPI Overview\n------------\n\nLensing calculations are performed in **PyAutoLens** by building a ``Tracer`` object from ``LightProfile``,\n``MassProfile`` and ``Galaxy`` objects. Below, we create a simple strong lens system where a redshift 0.5\nlens ``Galaxy`` with an ``Isothermal`` ``MassProfile`` lenses a background source at redshift 1.0 with an\n``Exponential`` ``LightProfile`` representing a disk.\n\n.. code-block:: python\n\n    import autolens as al\n    import autolens.plot as aplt\n    from astropy import cosmology as cosmo\n\n    \"\"\"\n    To describe the deflection of light by mass, two-dimensional grids of (y,x) Cartesian\n    coordinates are used.\n    \"\"\"\n    grid = al.Grid2D.uniform(\n        shape_native=(50, 50),\n        pixel_scales=0.05,  # <- Conversion from pixel units to arc-seconds.\n    )\n\n    \"\"\"\n    The lens galaxy has an elliptical isothermal mass profile and is at redshift 0.5.\n    \"\"\"\n    mass = al.mp.Isothermal(\n        centre=(0.0, 0.0), ell_comps=(0.1, 0.05), einstein_radius=1.6\n    )\n\n    lens_galaxy = al.Galaxy(redshift=0.5, mass=mass)\n\n    \"\"\"\n    The source galaxy has an elliptical exponential light profile and is at redshift 1.0.\n    \"\"\"\n    disk = al.lp.Exponential(\n        centre=(0.3, 0.2),\n        ell_comps=(0.05, 0.25),\n        intensity=0.05,\n        effective_radius=0.5,\n    )\n\n    source_galaxy = al.Galaxy(redshift=1.0, disk=disk)\n\n    \"\"\"\n    We create the strong lens using a Tracer, which uses the galaxies, their redshifts\n    and an input cosmology to determine how light is deflected on its path to Earth.\n    \"\"\"\n    tracer = al.Tracer(\n        galaxies=[lens_galaxy, source_galaxy], \n        cosmology = al.cosmo.Planck15()\n    )\n\n    \"\"\"\n    We can use the Grid2D and Tracer to perform many lensing calculations, for example\n    plotting the image of the lensed source.\n    \"\"\"\n    tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid)\n    tracer_plotter.figures_2d(image=True)\n\nWith **PyAutoLens**, you can begin modeling a lens in minutes. The example below demonstrates a simple analysis which\nfits the lens galaxy's mass with an ``Isothermal`` and the source galaxy's light with a ``Sersic``.\n\n.. code-block:: python\n\n    import autofit as af\n    import autolens as al\n    import autolens.plot as aplt\n\n    \"\"\"\n    Load Imaging data of the strong lens from the dataset folder of the workspace.\n    \"\"\"\n    dataset = al.Imaging.from_fits(\n        data_path=\"/path/to/dataset/image.fits\",\n        noise_map_path=\"/path/to/dataset/noise_map.fits\",\n        psf_path=\"/path/to/dataset/psf.fits\",\n        pixel_scales=0.1,\n    )\n\n    \"\"\"\n    Create a mask for the imaging data, which we setup as a 3.0\" circle, and apply it.\n    \"\"\"\n    mask = al.Mask2D.circular(\n        shape_native=dataset.shape_native,\n        pixel_scales=dataset.pixel_scales,\n        radius=3.0\n    )\n    dataset = dataset.apply_mask(mask=mask)\n\n    \"\"\"\n    We model the lens galaxy using an elliptical isothermal mass profile and\n    the source galaxy using an elliptical sersic light profile.\n\n    To setup these profiles as model components whose parameters are free & fitted for\n    we set up each Galaxy as a `Model` and define the model as a `Collection` of all galaxies.\n    \"\"\"\n    # Lens:\n\n    mass = af.Model(al.mp.Isothermal)\n    lens = af.Model(al.Galaxy, redshift=0.5, mass=lens_mass_profile)\n\n    # Source:\n\n    disk = af.Model(al.lp.Sersic)\n    source = af.Model(al.Galaxy, redshift=1.0, disk=disk)\n\n    # Overall Lens Model:\n    model = af.Collection(galaxies=af.Collection(lens=lens, source=source))\n\n    \"\"\"\n    We define the non-linear search used to fit the model to the data (in this case, Dynesty).\n    \"\"\"\n    search = af.Nautilus(name=\"search[example]\", n_live=50)\n\n    \"\"\"\n    We next set up the `Analysis`, which contains the `log likelihood function` that the\n    non-linear search calls to fit the lens model to the data.\n    \"\"\"\n    analysis = al.AnalysisImaging(dataset=dataset)\n\n    \"\"\"\n    To perform the model-fit we pass the model and analysis to the search's fit method. This will\n    output results (e.g., dynesty samples, model parameters, visualization) to hard-disk.\n    \"\"\"\n    result = search.fit(model=model, analysis=analysis)\n\n    \"\"\"\n    The results contain information on the fit, for example the maximum likelihood\n    model from the Dynesty parameter space search.\n    \"\"\"\n    print(result.samples.max_log_likelihood())\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Open-Source Strong Lensing",
    "version": "2024.11.13.2",
    "project_urls": {
        "Homepage": "https://github.com/Jammy2211/PyAutoLens"
    },
    "split_keywords": [
        "cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e889b7821099860dca5725170eacc69464a17e540353699692728bcd7eae9b20",
                "md5": "30004017a7900d13b1812e1c199ac84b",
                "sha256": "f369e56f19af075c3e6ad6ff2eb7cff3ecbb4806fb20bdfe78bc587874fb4480"
            },
            "downloads": -1,
            "filename": "autolens-2024.11.13.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "30004017a7900d13b1812e1c199ac84b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 139973,
            "upload_time": "2024-11-13T13:50:42",
            "upload_time_iso_8601": "2024-11-13T13:50:42.244225Z",
            "url": "https://files.pythonhosted.org/packages/e8/89/b7821099860dca5725170eacc69464a17e540353699692728bcd7eae9b20/autolens-2024.11.13.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e79542d72b2a245149542e5494bf48aaf50caa6e0b41b6dd77700b08830b6425",
                "md5": "cbcade662d4677447d1bc2d5568eae64",
                "sha256": "0d12746d6d4dcebe7835532807beb25e7991c1ce3bf8a665b6868ebc1281c025"
            },
            "downloads": -1,
            "filename": "autolens-2024.11.13.2.tar.gz",
            "has_sig": false,
            "md5_digest": "cbcade662d4677447d1bc2d5568eae64",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 102051,
            "upload_time": "2024-11-13T13:50:46",
            "upload_time_iso_8601": "2024-11-13T13:50:46.921486Z",
            "url": "https://files.pythonhosted.org/packages/e7/95/42d72b2a245149542e5494bf48aaf50caa6e0b41b6dd77700b08830b6425/autolens-2024.11.13.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-13 13:50:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Jammy2211",
    "github_project": "PyAutoLens",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "nautilus-sampler",
            "specs": [
                [
                    "==",
                    "1.0.4"
                ]
            ]
        }
    ],
    "lcname": "autolens"
}
        
Elapsed time: 0.98009s