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.

CosmoSim SIE Demo

This demo will demonstrate that the different simulation modes for SIE lenses are consistent.

Preparation

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import toml
from copy import deepcopy

import CosmoSim as cs
from CosmoSim import Parameters
from CosmoSim.datagen import SimImage
import CosmoSim.Image as csimg

print( "CosmoSim version:", cs.__version__ )
CosmoSim version: 3.3.0

Raytrace

We can define the configuration as a dict using the nested (TOML) structure.

cfg = { 'simulator' : { "model" : "Raytrace", "nterms" : 5, "cropsize" : 256 }
      , 'lens': { 
            'mode' : "SIE",
            'einsteinradius': 46 }
      , 'source': {
            'mode': 'SersicSphere',
            'sigma': 20,
            'theta': 45,
            'luminosity' : 70,
            'position': 'cartesian'}
      , 'position': {'x': 11.01, 'y': 0.31}
      }
param = Parameters(cfg)
raysim = SimImage( param, verbose=0 )
rayim = raysim.getImage()
csimg.imshow( rayim, title="Raytrace SIE")
<Figure size 640x480 with 1 Axes>

Roulette

param["simulator"]["model"] = "Roulette"

rousim = SimImage( param, verbose=0 )
rouim = rousim.getImage()
csimg.imageCompare( rouim, rayim, "Roulette model", 'Raytrace')
<Figure size 1500x500 with 3 Axes>

This looks perfect inside the convergence ring, as it should.

Sampling

param["simulator"]["sampled"] = True
im05 = SimImage( param, verbose=0 ).getImage()
param["simulator"]["model"] = "Raytrace"
im06 = SimImage( param, verbose=0 ).getImage()

csimg.imageCompare( rayim, im06, "Raytrace", 'Sampled Raytrace')
csimg.imageCompare( rouim, im05, "Roulette", 'Sampled Roulette')
<Figure size 1500x500 with 3 Axes>
<Figure size 1500x500 with 3 Axes>

As for SIS, we see minor discrepancy in the sampled roulette. The sampled raytrace, in contrast, looks perfect.

Conclusion

We can see that the different simulation models give consistent results. The minor discrepancy in the sampled roulette simulation may be due to numeric approximation.