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 Lenses (Demo n° 2)

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 Parameters

The 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}, "lens": {"mode": "SIS", "einstein-min": 20, "einstein-max": 75}, "cluster": {"count": 4, "maxrelativelocation": 1.2}, "source": {"mode": "SersicSphere", "n_sersic-min": 1, "n_sersic-max": 5, "luminosity-min": 20, "luminosity-max": 100, "luminosity-lambda": 2.0, "sigma-min": 1, "sigma-max": 4, "position": "critical"}, "position": {"phi-min": 0, "phi-max": 360, "r-relativemax": 0.4}}'

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(SIS/35.6616825994021/-57.012965430610606/58.059629595662635;SIS/-1.7674184459557993/6.694478263167608/37.27584509280463;SIS/63.8126983799238/1.7020222116128305/69.25303438787523;SIS/-14.292288309341288/-5.556674569664927/23.66123516173481)
[getline] idx=0
[CosmoSim/py] setCluster(SIS/72.84936630544034/8.214762524504298/69.54616160973853;SIS/10.472900138594603/26.749652370476287/27.60286029880546;SIS/-18.369477543124816/18.21376181207568/49.87667755720103;SIS/-22.178912411835476/-59.76018829859655/63.10329390661543)
[getline] idx=0
[CosmoSim/py] setCluster(SIS/0.20668003200374285/0.9200104450208816/67.25953896099861;SIS/-27.729920710543627/-17.314179710702305/41.567476767872435;SIS/-52.81048820533387/-12.190962616190795/62.192974078284294;SIS/62.611946533585225/-29.50906932247472/67.1460793262692)
[getline] idx=0
[CosmoSim/py] setCluster(SIS/-16.745285940826182/-14.570772704897719/22.819460356182844;SIS/-0.4625897680399825/1.3632135063012587/46.56060343321787;SIS/4.5741772668933915/-9.070675275201886/26.581112796564483;SIS/-0.4708902058978665/31.485305061894515/35.310605622405376)
[getline] idx=0
[CosmoSim/py] setCluster(SIS/-17.493278144780415/-6.90696427052396/42.02499311891644;SIS/70.51052758198043/-9.703888642622964/59.39486250585616;SIS/-0.0036952784135277352/5.012995586665652/33.165703838157995;SIS/25.83529892542645/-35.35661607917157/50.16332877609891)
[getline] idx=0
[CosmoSim/py] setCluster(SIS/11.991791555488778/25.410987430274083/49.13667640812196;SIS/-30.320932971767906/16.719975640924936/63.872221871997425;SIS/1.5577067600136916/-40.94000237346642/57.20452212321236;SIS/21.199605944442347/-30.081468886755726/65.95779515029048)
[getline] idx=0
[CosmoSim/py] setCluster(SIS/-25.077147777437922/-29.499765179086456/33.6115174095075;SIS/48.006317538087686/45.909359977540454/56.32949726494492;SIS/10.228963623951362/37.82938171036706/34.98784002438144;SIS/-74.24854910125794/-4.672819621572078/73.37640914248419)
[getline] idx=0
[CosmoSim/py] setCluster(SIS/-0.957488365869709/19.625692596875673/32.04064327457192;SIS/-10.479926685014384/14.675256201013484/66.5800353652877;SIS/2.055617864742721/24.555242120569776/33.10953561464453;SIS/-0.8037474421318181/3.0701473243277286/32.023372444534075)
<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       SIS/72.84936630544034/8.214762524504298/69.546...
source                                             SersicSphere
R                                                     27.256018
phi                                                  306.846075
sigma                                                  1.068294
sigma2                                                30.662604
theta                                                 91.380863
n_sersic                                               1.124029
luminosity                                            69.023999
x                                                     16.344543
y                                                    -21.811612
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"] )
SIS/72.84936630544034/8.214762524504298/69.54616160973853;SIS/10.472900138594603/26.749652370476287/27.60286029880546;SIS/-18.369477543124816/18.21376181207568/49.87667755720103;SIS/-22.178912411835476/-59.76018829859655/63.10329390661543

Closure

TODO