Skip to main content

Simulating Transient in the sky and how to observe them

Project description

codecov Run unit tests

slicersim

Simulation of Slicer observations


Installation

git clone https://github.com/MickaelRigault/slicersim.git
cd slicersim
pip install .

or

pip install git+https://github.com/MickaelRigault/slicersim.git

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slicersim-1.0.0.tar.gz (328.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slicersim-1.0.0-py3-none-any.whl (329.5 kB view details)

Uploaded Python 3

File details

Details for the file slicersim-1.0.0.tar.gz.

File metadata

  • Download URL: slicersim-1.0.0.tar.gz
  • Upload date:
  • Size: 328.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for slicersim-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ac525547db4726ceade0502e4af8b9901963403f7bf4d603679fd58291a1c892
MD5 5babcb38f421817e276496cbaa474bb9
BLAKE2b-256 17e1922ff1d1b37c10e0e20232bd8119c80621f3ce1398fb0602bc06d9d54c5d

See more details on using hashes here.

File details

Details for the file slicersim-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: slicersim-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 329.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for slicersim-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41329543bf5c931390a590f835e8fcfeb858240e6d0566644c6f17b06e978a6e
MD5 aaccc89076b1d3188a0d177619057723
BLAKE2b-256 ffa8724ce66b8e21bd3f9588c14f77ed637bf1e160f2e4ea882cf411759ba215

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page