In this demo we show the generation of a dataset for machine learning sporting two SIE lenses.
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 ParametersThe distribution of the dataset is configured as follows.
cfg = csd.readtoml( "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 where is
the Einstein radius and 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/4.599053972655763/4.786001512497096/68.63300204817568/0.6551835795178205/104.74577149253963;SIE/-5.632795172846447/0.9212191596264128/22.132281145749022/0.349253750837405/78.9782656766428)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/7.071062603488723/0.5059257448683713/28.84506316413256/0.16554719300009701/5.665199335758682;SIE/30.09477602396993/19.49882277866697/47.40782371159787/0.8702745305437771/81.08349759203209)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-5.3642912086218075/-4.013873511855304/23.45037083221174/0.26784607215943457/48.08159018156404;SIE/-35.2609355764343/18.824680209210428/42.82774243294795/0.3616235922659813/149.1664842292005)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/1.5245168693734064/0.5934325738402785/8.356472592076948/0.49131663080072074/85.11339244368662;SIE/-24.929961949095667/1.622580558806702/29.446379832074015/0.34557819784464866/68.9801881734085)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-0.3505474983076286/-0.009109933756866929/19.65143624087343/0.10188522078609337/123.7786737149617;SIE/-22.254905921425546/14.965959865510367/29.50895491970399/0.8940506405633369/150.18821760612073)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-9.46315189732123/-10.324341925200299/37.976097087229/0.23453155145236215/117.87332953830412;SIE/-2.7583642809282978/-2.9663728377696263/28.968090798692536/0.21546835389372987/143.8738650459539)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-0.9979493667711546/0.9530879797035549/8.319981599320492/0.7028303497837974/7.8679096823784045;SIE/-13.648759372330538/-38.57192361518582/57.74891063258008/0.7511905684167471/157.64118088340143)
[getline] idx=0
[CosmoSim/py] setCluster(SIE/-16.761837493408112/23.00469826457502/63.19006956238296/0.8597953017085781/23.96381966377183;SIE/-6.765808153285119/-1.0246271341333317/30.186516512303378/0.8447502190160423/41.22535812978929)

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/7.071062603488723/0.5059257448683713/28.84...
source SersicSphere
R 20.515737
phi 66.216595
sigma 33.301107
sigma2 24.563087
theta 136.854238
n_sersic 1.040437
luminosity 20.421918
x 8.273592
y 18.773469
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/7.071062603488723/0.5059257448683713/28.84506316413256/0.16554719300009701/5.665199335758682;SIE/30.09477602396993/19.49882277866697/47.40782371159787/0.8702745305437771/81.08349759203209
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 = [ mkimg(ob) for ob in obs ]
csimg.showImages( ims, size=(2,4), titles=ts )
Closure¶
TODO