Skip to main content

PyPI codecov Run unit tests Documentation Status

slicersim

Simulation of Slicer observations


reference

See the dedicated paper: Rigault et al. (2026)


Installation

pip install slicersim

Top level ETC

>>> import slicersim
>>> import numpy as np

Any spectra

Compute the exposure time needed any input spectrum:

>>> lbda_ref = np.linspace(3000, 20_000, 500) # larger than lazuli bandpass
>>> flux_ref = np.ones(lbda_ref.shape) # flat spectrum
>>> exptime, lazulitarget = slicersim.lazuli_etc(lbda_ref, flux_ref, snr=20, mag=21, band="bessellb")
>>> print(exptime)
237.72

Supernova

Compute the exposure time needed to observe a Supernovae:

>>> exptime, snia_target = slicersim.lazuli_sn_etc(snr=20, model="salt", redshift=1.2, x1=1.5, c=0.2, phase=-2.2)
>>> print(exptime)
5795.84

Quick look

import slicersim
# load a SN Ia (see also: `slicersim.LazuliTarget(lbda, flux)`)
snia = slicersim.LazuliSN(redshift=0.8, c=0.2, x1=-1.2, phase=1.5)

# update configuration to reach a signal-to-noise of 20
_ = snia.setup_to_snr(20)

# grab the expected observed spectrum
lbda, flux_1, variance_1 = snia.get_spectrum(unit="adu")

# change the target property
# warning: without updating the setting, this new target won't have a snr=20
snia.set_properties(redshift=1.2)
lbda, flux_2, variance_2 = snia.get_spectrum(unit="adu")

and show your simulated spectra

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=[7,3])

ax.plot(lbda, flux_1)
ax.fill_between(lbda, 
                flux_1-np.sqrt(variance_1),
                flux_1+np.sqrt(variance_1), alpha=0.3,
               label="z=0.8")

ax.plot(lbda, flux_2)
ax.fill_between(lbda, 
                flux_2-np.sqrt(variance_2),
                flux_2+np.sqrt(variance_2), alpha=0.3,
               label="z=1.2")
ax.legend(frameon=False, fontsize="small")
ax.set(xlabel=r"wavelength [$\AA$]", ylabel="flux [ADU]")

readme example


Tutorials

Beginner

Advanced

Experts

  • Noise Equivalent area
  • Build you own “scene”
  • Build your own configuration

Lower-level: Simulator & config.

Example: Study origin of variance

You can load a slicersim object at a lower level than an lazuli object: a Simulator. This object is at the core of slicersim and combines information of all sources needed to simulate our observations: a scene (what is observed), a mirror, a spectrograph and a detector.

The Simulator combine these to be able to generate a datacube with realistic noise, and extract a realistic spectrum from it.

Once your simulator is loaded, you have several method to check the variance origin.

  • estimate_variance_contribution: that probe the variance origin for a given wavelength rate
  • estimate_variance_contribution_spectra: similar but for whole spectrum
  • show_variance_sources: plotting function associated to estimate_variance_contribution_spectra
import slicersim
# load the correct simulator
config = slicersim.iotools.get_config(instrument='lazuli.toml')
sim = slicersim.Simulation.from_config(config)

# Set the target you want
sim.update(target__redshift=1., target__x1=0, target__c=0)

# look for the config needed to get an average SNR of 20 in [4000, 6800] rest-frame
new_config, snr, integration_time = sim.fetch_snr(20, lbda_range=[4000, 6800], frame='rest')
sim.update(**new_config) # let's set it

# get the expected spectrum (in ADU)
lbda, flux, variance = sim.get_spectrum()

# Show details
fig = sim.show_variance_sources(flux_calibrated=False)

readme example


PSF & Noise equivalent area

by default, the code assumes gaussian PSF both for spatial (at the slicer/mla) and cross-dispersion (at pixels) level.

slicersim.profiles contains additional PSF model (from astropy.modeling that can be used to build 2D model or estimate the PSF noise equivalent area (nea).

(more to come..., see: slicersim.profiles.get_2dpsf_nea())


Credits

Developped by M. Rigault ; adapted from the original MLAPerf v:0.18.0 developed by Y. Copin and M. Rigault

Metadata

Release files for slicersim 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slicersim 1.2.0
File Size Uploaded
slicersim-1.2.0.tar.gz 730.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for slicersim 1.2.0
File Interpreter ABI Platform
slicersim-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.5 MB

Release files / slicersim-1.2.0.tar.gz

Download URL slicersim-1.2.0.tar.gz
Size 730.1 kB
Tags Source
SHA-256 checksum
How to use checksums
780bf88913db47b358512e924bf81140c2ced2e91215ec1f7be3caa868b222be
BLAKE2b-256 checksum
How to use checksums
e63691f5eda139d6a0911152c08868942989bdeb83c4cadf763b9fe611bb5a16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / slicersim-1.2.0-py3-none-any.whl

Download URL slicersim-1.2.0-py3-none-any.whl
Size 729.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99a856e6db16284baa08b71ff441e31ce2ca6e0cfad62ee52ab13166e531510d
BLAKE2b-256 checksum
How to use checksums
ffc3db7e7fcec981751c69955a7e2f1e4b029f5e5fae7085bdc37b7f22ce96ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.4.0

2 release files

1.3.4

2 release files

1.3.0

2 release files

This release

1.2.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page