{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Overview: Simulate\n", "------------------\n", "\n", "**PyAutoLens** provides tool for simulating strong lens data-sets, which can be used to test lens modeling pipelines\n", "and train neural networks to recognise and analyse images of strong lenses." ] }, { "cell_type": "code", "metadata": {}, "source": [ "%matplotlib inline\n", "from pyprojroot import here\n", "workspace_path = str(here())\n", "%cd $workspace_path\n", "print(f\"Working Directory has been set to `{workspace_path}`\")\n", "\n", "import autolens as al\n", "import autolens.plot as aplt" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Grid And Lens__\n", "\n", "In this overview we use a tracer and grid to create an image of a strong lens.\n", "\n", "Everything below has been covered in previous overview examples, so if any code doesn't make sense you should go back \n", "and checkout the appropriate example!" ] }, { "cell_type": "code", "metadata": {}, "source": [ "grid = al.Grid2D.uniform(\n", " shape_native=(80, 80),\n", " pixel_scales=0.1, # <- The pixel-scale describes the conversion from pixel units to arc-seconds.\n", ")\n", "\n", "lens_galaxy = al.Galaxy(\n", " redshift=0.5,\n", " mass=al.mp.Isothermal(centre=(0.0, 0.0), ell_comps=(0.1, 0.0), einstein_radius=1.6),\n", ")\n", "\n", "source_galaxy = al.Galaxy(\n", " redshift=1.0,\n", " bulge=al.lp.Exponential(\n", " centre=(0.3, 0.2),\n", " ell_comps=(0.1, 0.0),\n", " intensity=0.1,\n", " effective_radius=0.5,\n", " ),\n", ")\n", "\n", "tracer = al.Tracer(galaxies=[lens_galaxy, source_galaxy], cosmology=al.cosmo.Planck15())\n", "\n", "tracer_plotter = aplt.TracerPlotter(tracer=tracer, grid=grid)\n", "tracer_plotter.figures_2d(image=True)" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Simulator__\n", "\n", "Simulating strong lens images uses a `SimulatorImaging` object, which simulates the process that an instrument like the\n", "Hubble Space Telescope goes through when it acquires imaging of a strong lens, including:\n", "\n", " - Using for the exposure time to determine the signal-to-noise of the data by converting the simulated image from\n", " electrons per second to electrons. \n", "\n", " - Blurring the observed light of the strong lens with the telescope optics via its point spread function (psf). \n", " \n", " - Accounting for the background sky in the exposure which adds Poisson noise." ] }, { "cell_type": "code", "metadata": {}, "source": [ "psf = al.Kernel2D.from_gaussian(\n", " shape_native=(11, 11), sigma=0.1, pixel_scales=grid.pixel_scales\n", ")\n", "\n", "simulator = al.SimulatorImaging(\n", " exposure_time=900.0, background_sky_level=1.0, psf=psf, add_poisson_noise=True\n", ")" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once we have a simulator, we can use it to create an imaging dataset which consists of image data, a noise-map and a\n", "Point Spread Function (PSF). \n", "\n", "We do this by passing it a tracer and grid, where it uses the tracer above to create the image of the strong lens and \n", "then add the effects that occur during data acquisition." ] }, { "cell_type": "code", "metadata": {}, "source": [ "dataset = simulator.via_tracer_from(tracer=tracer, grid=grid)" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "By plotting a subplot of the `Imaging` dataset, we can see this object includes the observed image of the strong lens\n", "(which has had noise and other instrumental effects added to it) as well as a noise-map and PSF:" ] }, { "cell_type": "code", "metadata": {}, "source": [ "dataset_plotter = aplt.ImagingPlotter(dataset=dataset)\n", "dataset_plotter.subplot_dataset()" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Wrap Up__\n", "\n", "The `autolens_workspace` includes many example simulators for simulating strong lenses with a range of different \n", "physical properties, for example lenses without any lens light, with multiple lens galaxies, and double Einstein\n", "ring lenses.\n", " \n", "There are also tools for making datasets for a variety of telescopes (e.g. Hubble, Euclid) and interferometer datasets\n", "(e.g. ALMA)." ] }, { "cell_type": "code", "metadata": {}, "source": [], "outputs": [], "execution_count": null } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 4 }