Skip to main content

PyPI codecov Run unit tests Documentation Status

slicersim

Simulation of Slicer observations

📖 Documentation: https://slicersim.readthedocs.io


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.LazuliSupernova(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.change_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.get_config(instrument='lazuli_cbe.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.3.4

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.3.4
File Size Uploaded
slicersim-1.3.4.tar.gz 751.0 kB Details

Built distribution (wheel)

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

Total release size: 1.5 MB

Release files / slicersim-1.3.4.tar.gz

Download URL slicersim-1.3.4.tar.gz
Size 751.0 kB
Tags Source
SHA-256 checksum
How to use checksums
273f661e4d4447d7f4f75f314fa4c1546de7eb6f7b595ead1898661f870a7bde
BLAKE2b-256 checksum
How to use checksums
ac69773b8c867752f3273efcb0dc9340e322dfdd539c8c9318f3610337afe5e9
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.3.4-py3-none-any.whl

Download URL slicersim-1.3.4-py3-none-any.whl
Size 754.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f51c6e6bd10ca567b0effec91431431e290a2f2e761c3fbe567be8169adbe0f
BLAKE2b-256 checksum
How to use checksums
db1e0cc87a5ba241d4b2a4f98c338588723a51bc7633eb37547caffeebd17c7c
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

This release

1.3.4 This release

2 release files

1.3.0

2 release files

1.2.0

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