Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ AUTO-GENERATED by PyAutoHands — do not edit by hand; regenerate with generate.

## chapter_1_introduction

- [Tutorial 0: Visualization](scripts/chapter_1_introduction/tutorial_0_visualization.py): In this tutorial, we quickly cover visualization in **PyAutoLens** and make sure images display clearly in your Jupyter notebook and on your computer screen.
- [Tutorial 0: Visualization](scripts/chapter_1_introduction/tutorial_0_visualization.py): Plot a simulated image with **PyAutoLens**, compare views of the dataset, and adjust the display so you can inspect its structure. This tutorial introduces the plotting tools used throughout the course.
- Contents: Directories, Dataset, Dataset Auto-Simulation, Subplots, Plot Customization, Overlays, Wrap Up
- [HowToLens: Introduction](scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py): A strong gravitational lens is a system where two (or more) galaxies align perfectly down our line of sight from Earth such that the foreground galaxy's mass curves space-time in on itself, such that the light of a background source galaxy is deflected and magnified. This means we can see the background source galaxy multiple times, as multiple arcs or rings, because multiple paths through the foreground galaxy's mass are taken by the source's light.
- [HowToLens: Introduction](scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py): A distant galaxy can appear as multiple images, stretched arcs or a ring when its light passes a sufficiently well-aligned foreground galaxy. The foreground galaxy’s gravity deflects the light, allowing it to reach us along different paths. This is strong gravitational lensing.
- Contents: Grids, Geometry, Light Profiles, One Dimension Projection, Galaxies, Units, Wrap Up, Advanced Topics, Other Unit Conversion, Over Sampling
- [Tutorial 2: Ray Tracing](scripts/chapter_1_introduction/tutorial_2_ray_tracing.py): Strong gravitational lensing occurs when the mass of a foreground galaxy (or galaxies) curves space-time around it, causing light rays from a background source to appear deflected.
- Contents: Grid, Mass Profiles, Ray Tracing Grids, Ray Tracing Images, Galaxies, Tracer, Mappings, Wrap Up
- [Tutorial 2: Ray Tracing](scripts/chapter_1_introduction/tutorial_2_ray_tracing.py): Strong gravitational lensing occurs when the mass of a foreground galaxy curves space-time, bending the paths of light rays from a background source galaxy. The source can then appear as arcs, a ring or multiple images.
- Contents: Grid, Mass Profiles, Ray Tracing Grids, Mappings, Ray Tracing Images, Galaxies, Tracer, Wrap Up, Env
- [Tutorial 3: More Ray Tracing](scripts/chapter_1_introduction/tutorial_3_more_ray_tracing.py): We'll now reinforce the ideas that we learnt about ray-tracing in the previous tutorial and introduce the following new concepts:
- Contents: Initial Setup, Concise Code, Critical Curves, Caustics, Units, More Complexity, Multi Galaxy Ray Tracing, Wrap Up
- [Tutorial 4: Point Sources](scripts/chapter_1_introduction/tutorial_4_point_sources.py): In the previous tutorials, the background sources we lensed were galaxies: extended objects whose light spreads over many thousands of light years. When lensed, their light is warped into the arcs and Einstein rings we produced with the `Tracer`, spread across many pixels of the image.
Expand Down
169 changes: 100 additions & 69 deletions notebooks/chapter_1_introduction/tutorial_0_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
"metadata": {},
"source": [
"Tutorial 0: Visualization\n",
"=========================\n",
"========================\n",
"\n",
"In this tutorial, we quickly cover visualization in **PyAutoLens** and make sure images display\n",
"clearly in your Jupyter notebook and on your computer screen.\n",
"Plot a simulated image with **PyAutoLens**, compare views of the dataset, and adjust the display so you\n",
"can inspect its structure. This tutorial introduces the plotting tools used throughout the course.\n",
"\n",
"__Contents__\n",
"\n",
"- **Directories:** **HowToLens** assumes the working directory is the `HowToLens` repository root on your hard-disk.\n",
"- **Dataset:** Load and plot the strong lens dataset.\n",
"- **Dataset Auto-Simulation:** Create the dataset via its simulator script if it is not on your hard-disk.\n",
"- **Subplots:** In addition to plotting individual figures, **PyAutoLens** can plot `subplots` which show multiple.\n",
"- **Plot Customization:** Does the figure display correctly on your computer screen?\n",
"- **Overlays:** Overlays such as critical curves and image positions are added using the `lines=` and `positions=`.\n",
"- **Wrap Up:** Summary of the script and next steps."
"- **Directories:** Check where the tutorial looks for files.\n",
"- **Dataset:** Identify the simulated image we will use.\n",
"- **Dataset Auto-Simulation:** Generate the example if needed, load it and plot the image.\n",
"- **Subplots:** Compare several views of the dataset.\n",
"- **Plot Customization:** Adjust colour scaling and figure size.\n",
"- **Overlays:** Draw a model-derived curve on an unblurred lensed image.\n",
"- **Wrap Up:** Review the plotting tools and continue to Tutorial 1."
]
},
{
Expand Down Expand Up @@ -77,31 +77,39 @@
"source": [
"__Directories__\n",
"\n",
"**HowToLens** assumes the working directory is the `HowToLens` repository root on your hard-disk. This setup\n",
"allows **PyAutoLens** to:\n",
"Run this tutorial from the `HowToLens` repository folder, which contains `config/`, `dataset/` and `scripts/`.\n",
"Relative paths in the tutorial are resolved from your current working directory.\n",
"\n",
"- Load configuration settings from the config files in the `config/` folder.\n",
"The next cell prints that directory. Check that it points to your `HowToLens` folder before continuing.\n",
"\n",
"- Load the example strong lens datasets in the `dataset/` folder.\n",
"\n",
"- Write the results of model-fits to your hard-disk in the `output/` folder.\n",
"\n",
"If you do not have a clone of **HowToLens** on your computer, you can download it here:\n",
"\n",
" https://github.com/PyAutoLabs/HowToLens\n",
"If you have not downloaded the tutorials, get them from [the HowToLens repository](https://github.com/PyAutoLabs/HowToLens)."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"from pathlib import Path\n",
"\n",
"If your working directory does not match this path on your computer, you can manually set it as follows (the\n",
"example below shows the path I would use on my laptop. The code is commented out so you do not use this path in\n",
"this tutorial!"
"print(Path.cwd())"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If the directory is incorrect, replace the example path below with the location of your repository and uncomment\n",
"the two lines. Then rerun the cell above to check the directory."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"# workspace_path = \"/Users/Jammy/Code/PyAuto/HowToLens\"\n",
"# #%cd $workspace_path\n",
"# print(f\"Working Directory has been set to `{workspace_path}`\")"
"# import os\n",
"# os.chdir(\"/path/to/HowToLens\")"
],
"outputs": [],
"execution_count": null
Expand All @@ -112,19 +120,17 @@
"source": [
"__Dataset__\n",
"\n",
"The `dataset_path` specifies where the dataset is located, which is the\n",
"directory `dataset/imaging/simple__no_lens_light` of the HowToLens repository.\n",
"We will use a simulated image of a gravitationally lensed galaxy. This example omits light from the foreground\n",
"lens galaxy so that we can focus on the lensed source.\n",
"\n",
"The simulated images of strong lenses used throughout the **HowToLens** lectures are written to the `dataset`\n",
"directory at runtime by the simulator scripts in `scripts/simulator/`."
"The following path identifies the dataset folder within `HowToLens`. If the data are missing, the next section\n",
"generates them."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"from pathlib import Path\n",
"\n",
"import autolens as al\n",
"import autolens.plot as aplt\n",
"\n",
Expand All @@ -139,8 +145,8 @@
"source": [
"__Dataset Auto-Simulation__\n",
"\n",
"If the dataset does not already exist on your system, it is created by running the corresponding\n",
"simulator script. This ensures every example script can be run without manually simulating data first."
"The next cell runs the simulator if the example dataset needs to be generated. You do not need to run the\n",
"simulator separately."
]
},
{
Expand All @@ -151,6 +157,7 @@
" import subprocess\n",
" import sys\n",
"\n",
" # Use the same Python interpreter as this tutorial.\n",
" subprocess.run(\n",
" [sys.executable, \"scripts/simulator/no_lens_light.py\"],\n",
" check=True,\n",
Expand All @@ -163,7 +170,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We now load this dataset from .fits files and create an instance of an `Imaging` object."
"We now load three FITS files into an `Imaging` object: the image, its noise map and the point-spread function\n",
"(PSF). The noise map describes the uncertainty in each pixel; the PSF describes how the image of a point source\n",
"is blurred.\n",
"\n",
"Each pixel spans 0.1 arcseconds on each side, matching the simulator settings. Loading these files does not\n",
"fit a model to the image."
]
},
{
Expand All @@ -184,7 +196,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can plot an image with `aplt.plot_array()`, passing the data array and a title."
"Plot the simulated image using `aplt.plot_array()`. Look for the background galaxy\u2019s light distorted into bright\n",
"features around the centre of the lens. The foreground galaxy contributes no light in this example.\n",
"\n",
"The simulation includes blurring by the PSF and noise, so the image includes both instrumental blurring and random fluctuations."
]
},
{
Expand All @@ -202,10 +217,14 @@
"source": [
"__Subplots__\n",
"\n",
"In addition to plotting individual figures, **PyAutoLens** can plot `subplots` which show multiple\n",
"views of the dataset at once.\n",
"A subplot brings several views of the dataset into one figure. The next cell displays the image, noise map,\n",
"PSF and signal-to-noise map, alongside additional diagnostic panels.\n",
"\n",
"Compare the image with its logarithmic view, labelled \u201cData (log10)\u201d. The different colour scaling helps\n",
"reveal faint structure alongside bright features; it does not change the underlying data.\n",
"\n",
"The `aplt.subplot_imaging_dataset()` function plots the data, noise-map and PSF together."
"For now, focus on these image panels and the noise map. We will introduce the numerical settings shown in\n",
"the other panels as they become relevant."
]
},
{
Expand All @@ -223,43 +242,63 @@
"source": [
"__Plot Customization__\n",
"\n",
"Does the figure display correctly on your computer screen?\n",
"\n",
"If not, the default matplotlib settings can be customized via the config files in:\n",
"\n",
" config/visualize/\n",
"\n",
"Key config entries:\n",
"Change a figure's appearance by passing options to `aplt.plot_array()`. Here we use a logarithmic colour\n",
"scale to make faint structure easier to see. We create a 7-by-7-inch figure with Matplotlib and pass its axes\n",
"to the plotting function.\n",
"\n",
" - `mat_wrap.yaml` -> Figure -> figure: -> figsize\n",
" - `mat_wrap.yaml` -> YLabel -> figure: -> fontsize\n",
" - `mat_wrap.yaml` -> XLabel -> figure: -> fontsize\n",
" - `mat_wrap.yaml` -> TickParams -> figure: -> labelsize\n",
" - `mat_wrap.yaml` -> YTicks -> figure: -> labelsize\n",
" - `mat_wrap.yaml` -> XTicks -> figure: -> labelsize\n",
"\n",
"For quick one-off adjustments you can pass `title=`, `colormap=`, and `use_log10=` directly:"
"Compare this plot with the first image. Logarithmic scaling changes how positive pixel values map to colours;\n",
"it does not change the image or make faint features more statistically significant."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"aplt.plot_array(array=dataset.data, title=\"Dataset Image (Log10)\", use_log10=True)"
"import matplotlib.pyplot as plt\n",
"\n",
"fig, ax = plt.subplots(figsize=(7, 7))\n",
"aplt.plot_array(\n",
" array=dataset.data,\n",
" title=\"Dataset Image (Log10)\",\n",
" use_log10=True,\n",
" ax=ax,\n",
")\n",
"plt.show()\n",
"plt.close(fig)"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Try changing `use_log10=True` to `False` and rerun the cell to return to a linear colour scale. To enlarge\n",
"the figure, change `figsize=(7, 7)` to `(9, 9)`. Restore the starting values to reproduce the plot above.\n",
"\n",
"You can also set `colormap=\"gray\"` to display the image in greyscale. For persistent defaults, explore\n",
"`config/visualize/general.yaml`; its `colormap` entry sets the default colour map and\n",
"`subplot_shape_to_figsize_factor` controls subplot sizes. The per-call options above are enough for this lesson.\n",
"\n",
"**\ud83e\udd16 Ask AI:** Why can logarithmic colour scaling make faint structure easier to see without increasing its\n",
"signal-to-noise ratio?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Overlays__\n",
"\n",
"Overlays such as critical curves and image positions are added using the `lines=` and `positions=`\n",
"keyword arguments.\n",
"Overlays place reference curves or positions on an image. The `lines=` argument draws curves, while\n",
"`positions=` marks coordinates.\n",
"\n",
"Here we create a new, illustrative lens model and plot its unblurred lensed image with a tangential critical curve.\n",
"This curve is calculated from the model; it is not a feature measured directly from the image. Later tutorials\n",
"explain its lensing meaning.\n",
"\n",
"For example, we can compute the critical curves of a tracer and overlay them on the image."
"This model differs from the one used to simulate the dataset above. We evaluate its image at fixed parameters,\n",
"without adding a PSF or noise and without fitting the dataset. Look for the curve drawn over the unblurred lensed image."
]
},
{
Expand Down Expand Up @@ -301,18 +340,10 @@
"source": [
"__Wrap Up__\n",
"\n",
"Throughout the lectures you'll see lots more visuals plotted on figures and subplots.\n",
"\n",
"The key plotting functions you'll use are:\n",
"\n",
" - `aplt.plot_array(array, title, ...)` \u2014 plot any 2D array.\n",
" - `aplt.plot_grid(grid, title, ...)` \u2014 plot a 2D grid of coordinates.\n",
" - `aplt.subplot_imaging_dataset(dataset)` \u2014 multi-panel dataset overview.\n",
" - `aplt.subplot_tracer(tracer, grid)` \u2014 multi-panel tracer overview.\n",
" - `aplt.subplot_fit_imaging(fit)` \u2014 multi-panel fit overview.\n",
"You have plotted an image, compared dataset panels and changed the display without changing the pixel values.\n",
"Use `aplt.plot_array()` for an individual image and `aplt.subplot_imaging_dataset()` for a dataset overview.\n",
"\n",
"Great! Hopefully, visualization in **PyAutoLens** is displaying nicely for us to get on with the\n",
"**HowToLens** lecture series."
"Next, open Tutorial 1: Grids and Galaxies to learn how coordinates and light profiles produce a galaxy image."
]
}
],
Expand Down
Loading
Loading