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.

The Point Mass Lens

This demo will demonstrate that the different simulation modes for Point Mass lenses are consistent. It may be useful also to look at Pointmass Demo which also includes the closed form simulators in CosmoSim v3.1.

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" : 10, "cropsize" : 256 }
      , 'lens': { 
            'mode' : "PM",
            'einsteinradius': 46 }
      , 'source': {
            'mode': 'SersicSphere',
            'sigma': 20,
            'theta': 45,
            'luminosity' : 20,
            '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 Point Mass")
<Figure size 640x480 with 1 Axes>

Roulette

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

rousim = SimImage( param, verbose=2 )
rouim = rousim.getImage()
csimg.imageCompare( rouim, rayim, "Roulette model", 'Raytrace')
[GenericSim] init (verbose=2) ...
[SimImage] init (verbose=2) ...
[getSource] src=SersicSphere, ltprf0=None, verbose=2
[getSource] Lightprofile: SersicSphere LightProfileSpec.Sersic
[SphericalSource] constructor done
getSource() returns
[getLens] Point Mass Amplitudes
[getLens] instantiated PointMass
[initSim] XY 11.01 0.31
[Source] Constructor Source (Superclass)
[SphericalSource] SERSIC
[Lens] init Lens (Superclass)
[PsiFunctionLens] init PsiFunctionLens
[SimulatorModel] instantiating
Instantiating RouletteModel ... 
[SimulatorModel::setSource] setting source
[SimulatorModel::setNterms] 10 -> 10
[SimulatorModel::update] Lens: PointMass
[PointMass::getXi] [11.01, 0.31] -> [51.8151, 1.45892]
[setNu] etaOffset set to zero.
[SimulatorModel::update] Done updateApparentAbs()
[SimulatorModel::update] thread section
[Source::getImage()]
[SimulatorModel::updateInner()] eta=[11.01, 0.31]
[SimulatorModel::updateInner()] xi=[51.8151, 1.45892]; eta=[11.01, 0.31]; etaOffset=[0, 0]
[SimulatorModel::updateInner()] nu=[51.8151, 1.45892]
[calculateAlphaBeta] [[51.8151, 1.45892]] ... 
[PsiFunctionLens.calculateAlphaBeta()] 10; 46 - [51.8151, 1.45892]
[PsiFunctionLens.calculateAlphaBeta()] done
[calculateAlphaBeta] done
[SimulatorModel::parallelDistort] 4 threads (maskMode=0)
[SimulatorModel::parallelDistort] etaOffset=[0, 0]; nu=[51.8151, 1.45892]; eta[11.01, 0.31]; referenceXi=[51.8151, 1.45892]
[SimulatorModel] No mask 
[SimulatorModel::parallelDistort] lower=0; rng=512; rng1=128
[SimulatorModel::distort] refXi=[51.8151, 1.45892] begin=0; end=128
[SimulatorModel::distort] refXi=[51.8151, 1.45892] begin=128; end=256
[SimulatorModel::distort] refXi=[51.8151, 1.45892] begin=256; end=384
[SimulatorModel::distort] refXi=[51.8151, 1.45892] begin=384; end=512
Time to update(): 190 milliseconds
[Simulator] Centre Point (48.08,0.12) (Centre of Luminence in Planar Co-ordinates)
[getImage] centring from parameters: None
[crop] cropsize=256
<Figure size 1500x500 with 3 Axes>

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

Sampling

param["simulator"]["sampled"] = True
imsim05 = SimImage( param, verbose=0 )
im05 = imsim05.getImage()
csimg.imageCompare( rayim, im05, "Raytrace", 'Sampled Roulette')
csimg.imageCompare( rouim, im05, "Roulette", 'Sampled Roulette')
[SimulatorModel::getDistorted()]
[setDebug] 0
<Figure size 1500x500 with 3 Axes>
<Figure size 1500x500 with 3 Axes>

Closure

Each lens model can be simulated in four different ways. We can use raytrace, which is exact, or the roulette formalism. In addition to the direct implementation of analytic derivation of the lens potential, it is also possible to use a sampled model, where the lens potential is sampled and the distortion and roulette amplitudes are computed by numeric differentiation. The present demo show that these are consistent for point mass lenses.