Understanding and using slicersim.scene.Scene#
This notebook explains what a slicersim.scene.Scene is, how to create one, and how to customize it.
1. What is a Scene?#
A Scene represents what the telescope is observing. It is made of up to three elements:
pointsource: a point source, like a supernova, a kilonova or a standard star (its spectral models are in
slicersim.scene.sources);background: a spatially uniform background, like the zodiacal light;
host: a structured background, like the host galaxy of a supernova (see the Host galaxy notebook).
2. Creating a Scene from a configuration dictionary#
The easiest way to get a scene configuration is slicersim.scene.get_scene()
(e.g. get_scene("snia", redshift=0.5)). Here we build it by hand from the
supernova point-source configuration given by get_snia_pointsource().
import numpy as np
import matplotlib.pyplot as plt
from slicersim.scene.scene import Scene
from slicersim.scene.sources.supernovae import get_snia_pointsource
config = {
'pointsource': get_snia_pointsource(source='salt', redshift=0.5, position=(0,0)),
'background': {'name': 'zodi', 'model': 'Aldering01.BB5800'}
}
lbda = np.linspace(4000, 17000, 1000)
scene = Scene.from_config(config, lbda=lbda)
print(scene.pointsource)
print(scene.background)
<slicersim.scene.pointsource.PointSource object at 0x17ec31e80>
<slicersim.scene.background.Background object at 0x17ec32660>
fig, ax = plt.subplots()
ax.plot(lbda, scene.pointsource.get_spectrum(lbda=lbda)[1], label='Point source')
ax.plot(lbda, scene.background.get_spectrum(lbda=lbda)[1], label='Background')
ax.set_xlabel('Wavelength [Å]')
ax.set_ylabel('Flux [erg/s/cm$^2$/Å]')
ax.legend()
plt.show()
3. Creating a Scene manually#
You can also build each scene element yourself, from its model function
(see slicersim.scene.sources for the available point-source models).
from slicersim.scene.pointsource import PointSource
from slicersim.scene.sources.supernovae import get_saltmodel_flux
from slicersim.scene.background import Background, zodiacal_spectrum
pointsource = PointSource(model_func=get_saltmodel_flux,
position=(0,0),
meta={'redshift': 0.5, 'phase': 0})
background = Background(model_func=zodiacal_spectrum,
meta={'model': 'Aldering01.BB5800'})
scene_manual = Scene(pointsource=pointsource, background=background)
fig, ax = plt.subplots()
ax.plot(lbda, scene_manual.pointsource.get_spectrum(lbda=lbda)[1], label='Point source')
ax.plot(lbda, scene_manual.background.get_spectrum(lbda=lbda)[1], label='Background')
ax.set_xlabel('Wavelength [Å]')
ax.set_ylabel('Flux [erg/s/cm$^2$/Å]')
ax.legend()
plt.show()
4. Creating a custom PointSource from a spectrum#
PointSource.from_spectrum() builds a point source from any tabulated spectrum,
optionally rescaled to a given magnitude in a given band.
# a dummy spectrum: a gaussian emission line at 6000 Å
lbda_custom = np.linspace(3000, 9000, 500)
flux_custom = np.exp(-((lbda_custom - 6000) / 100)**2)
custom_target = PointSource.from_spectrum(lbda_custom, flux_custom, mag=20, band='bessellb', position=(0,0))
scene_custom = Scene(pointsource=custom_target, lbda=lbda)
fig, ax = plt.subplots()
ax.plot(lbda, scene_custom.pointsource.get_spectrum(lbda=lbda)[1], label='Custom point source')
ax.set_xlabel('Wavelength [Å]')
ax.set_ylabel('Flux [erg/s/cm$^2$/Å]')
ax.legend()
plt.show()
5. Updating the Scene parameters#
Use update() to change the parameters of the scene elements. Parameters are named
{element}__{parameter}, e.g. pointsource__phase for the phase of the point source.
lbda_plot, flux_before = scene.pointsource.get_spectrum(lbda=lbda)
scene.update(pointsource__phase=10)
lbda_plot, flux_after = scene.pointsource.get_spectrum(lbda=lbda)
fig, ax = plt.subplots()
ax.plot(lbda_plot, flux_before, label='Phase 0')
ax.plot(lbda_plot, flux_after, label='Phase 10')
ax.set_xlabel('Wavelength [Å]')
ax.set_ylabel('Flux [erg/s/cm$^2$/Å]')
ax.legend()
plt.show()