Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Cluster Dataset (2x SIE)

In this demo we show the generation of a dataset for machine learning sporting two SIE lenses. To run the notebook, you will have to download several datafiles from Experiment 2 (2xSIE).

Preparation

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import json
from CosmoSim.datagen import SimImage
import CosmoSim.Image as csimg
import CosmoSim.dataset as csd
from CosmoSim import Parameters

The distribution of the dataset is configured as follows.

cfg = csd.readtoml( "cluster2-dataset.toml" )
display( json.dumps( cfg ) )
'{"simulator": {"model": "Raytrace", "size": 15000, "nterms": 4, "imagesize": 512, "cropsize": 256, "centred": true}, "dataset": {"directory": "images"}, "lens": {"mode": "SIE", "einstein-min": 3, "einstein-max": 75, "orientation-min": 0, "orientation-max": 180, "ellipseratio-min": 0.1, "ellipseratio-max": 0.9}, "cluster": {"count": 2, "maxrelativelocation": 1.2}, "source": {"mode": "SersicSphere", "n_sersic-min": 1, "n_sersic-max": 5, "luminosity-min": 20, "luminosity-max": 80, "luminosity-lambda": 2.0, "sigma-min": 5, "sigma-max": 50, "position": "critical"}, "position": {"phi-min": 0, "phi-max": 360, "r-relativemax": 1.2}}'

Each constituent lens is placed in a random direction from the origin, at a random distance upper bounded as cθEc\theta_E where θE\theta_E is the Einstein radius and cc is the constant given as cluster.maxrelativelocation.

We can draw a random object as before.

A sample

Let us make a random sample for review. Firstly, we make a convenience function to run one simulation and retrieve the image.

def mkimg(ob):
      p0 = Parameters( )
      p0.setRow( ob )
      sim = SimImage( p0, verbose=0 )
      return sim.getImage()

Using this function, we can make a list of simulations, and plot the results.

obs = [ csd.getline( cfg ) for _ in range(8) ]
ims = [ mkimg(ob) for ob in obs ]
ts = [ f"Image {i}" for i in range(8) ]
csimg.showImages( ims, size=(2,4), titles=ts )
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-29.139584873284292/-34.84177995627497/52.966880303724324/0.7373886754237825/53.99927627388847;SIE/13.958713903567148/4.603461291649108/17.067130655725236/0.5642716893118186/77.23707179316307)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-1.106220748160589/-0.9808368410967336/20.75641153015302/0.8191017312400032/168.70390330099707;SIE/13.15953945868276/20.688072844900667/30.758282222137407/0.719692010932701/42.873751694339425)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/10.125258014958376/15.30300499573612/44.8778823382277/0.5761066077779383/162.86238700428405;SIE/1.5707238179529572/-38.13799860284304/73.29576811033495/0.371432059579454/110.79432733162022)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-5.260365464687968/-7.323859505066482/22.868472656285284/0.44152140055752054/105.63345419882559;SIE/28.253262614366168/-34.22424196839154/58.17293697075803/0.28443045498152025/36.02136541635229)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-4.692779852780665/3.167865285259208/6.107142220095383/0.30448267447741795/109.70908232878621;SIE/-14.454164164589356/-29.092335328712405/57.95499870106224/0.7823078509881412/179.28430780835222)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-10.042685447647045/0.7968178565764963/54.211526962696794/0.7749999257333141/129.0540756611564;SIE/33.78566756277067/-14.733066285985808/45.82321355638151/0.7680746289000594/56.05376065334334)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/26.643401376947416/-41.254374542140404/68.4526746010708/0.47576045704984804/6.859611499667972;SIE/10.48405604286299/2.7737327320061844/22.51502225429615/0.408671026888758/132.52424252444868)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-50.08486605825176/-0.5777751700405931/65.99678672113089/0.28032778922869483/127.65187137727763;SIE/-3.306342381421589/-20.397208936010284/46.97849504730647/0.6523346631906504/11.109239009827846)
<Figure size 2000x1000 with 8 Axes>

If we take a particular interest in one particular image, say no 1, we can easily inspect its parameters.

print( obs[1] )
index                                                         0
filename                                       image-000000.png
model                                                  Raytrace
cluster       SIE/-1.106220748160589/-0.9808368410967336/20....
source                                             SersicSphere
R                                                     14.572594
phi                                                  322.635644
sigma                                                 14.279314
sigma2                                                 6.667787
theta                                                 99.730079
n_sersic                                               4.414119
luminosity                                            76.523552
x                                                     11.582186
y                                                     -8.843838
dtype: object

The cluser specification does not show in the row view, but we can single that one out to see properly.

print( obs[1]["cluster"] )
SIE/-1.106220748160589/-0.9808368410967336/20.75641153015302/0.8191017312400032/168.70390330099707;SIE/13.15953945868276/20.688072844900667/30.758282222137407/0.719692010932701/42.873751694339425

Annotations

It may be interesting to look at the Critical Curves, to get an idea of the shape of the lenses. Instead of mkimg() we make a function to get annotated images.

def mkannotation(ob):
      p0 = Parameters( )
      p0.setRow( ob )
      sim = SimImage( p0, verbose=0 )
      return sim.getAnnotated()

We use the same datasets as before, but generate new and annotated images.

ims = [ mkannotation(ob) for ob in obs ]
csimg.showImages( ims, size=(2,4), titles=ts )
<Figure size 2000x1000 with 8 Axes>

The yellow curve is the Critical Curve, and the blue circle is the convergence ring of the roulette formalism. The red point is the centre of light.

Closure

We have attemmpted to design the dataset so that it displays interesting samples of strong lensing.
More research is needed on actual distributions of observed lenses, and how a representative sample can be designed for machine learning.