LazuliKilonova#
- class LazuliKilonova(model='bulla23', host=None, **kwargs)[source]#
Bases:
VirtualLazuliTarget,KilonovaA kilonova observed with Lazuli.
The spectrum comes from the POSSIS radiative transfer models (Bulla 2019, 2023) for a given viewing angle, see
get_kilonova_flux.- Parameters:
model (
str, optional) –"bulla23"[default] or"bulla19".**kwargs – Point source parameters, mainly
redshift,phase(days since merger),theta(viewing angle in degrees),magabs(peak absolute magnitude inband) ormag(peak observed magnitude) andposition(spaxels).
Examples
>>> kn = LazuliKilonova(redshift=0.05, phase=1.4, theta=30)
Methods
Change the Lazuli instrument configuration.
Change the detector read-out configuration.
Change any mutable parameter of the simulation.
Change the spectrograph configuration.
Load the instance from a scene configuration.
Load the instance from an already-built simulation.
Get the signal-to-noise ratio over a wavelength range.
Get the simulated cubes, for one or both Lazuli fields.
Get the data volume of the observation.
Project the narrow and wide field cubes onto a single detector image.
Get the exposure time of the current configuration.
Get parameter values of the target's simulation.
Get the current MACC mode and number of ramps.
Get the current spectrograph field.
Get the simulated spectrum of the point source (or of the galaxy).
Get the contribution of each noise source to the variance.
Find the detector read-out configuration reaching a target SNR.
Show the narrow and wide field cubes, collapsed over a wavelength range.
Project the narrow and wide field cubes onto a single detector image.
Attributes
Names of the mutable parameters of the point source (list of str).
The
Simulationwrapped by the target.- change_configuration(which)#
Change the Lazuli instrument configuration.
The corresponding configuration file (
lazuli_eol.tomlorlazuli_cbe.toml) is read and the simulation updated with it.
- change_detector(nmd=None, max_group=None, nramps=None)#
Change the detector read-out configuration.
Parameters set to None are left unchanged.
- change_properties(**kwargs)#
Change any mutable parameter of the simulation.
Shortcut to
update.- Parameters:
**kwargs – The parameters to change, as
name=value(e.g.redshift=0.5orpointsource__phase=-2).- Returns:
- change_spectrograph(field=None, spatial_shape=None, spatial_scale=None)#
Change the spectrograph configuration.
- Parameters:
field (
str, optional) –Lazuli field to use (see
SPECTROGRAPH_FIELD):"narrow": finely sampled field, with 0.04 arcsec spaxels."wide": coarser field, with 0.08 arcsec spaxels.
If None, only
spatial_shapeandspatial_scaleare applied. Default is None.spatial_shape (
tupleofint, optional) – Spaxel grid shape (e.g.(40, 40)), overriding that offieldif any. Default is None.spatial_scale (
floatorlistoffloat, optional) – Spaxel size in arcsec, overriding that offieldif any. If a float, spaxels are square; if a list,(x, y). Default is None.
- Returns:
- Raises:
ValueError – If
fieldis not a known Lazuli field.
- classmethod from_scene(scene=None, **kwargs)#
Load the instance from a scene configuration.
- Parameters:
scene (
dictorstr, optional) –Scene configuration (see
get_scene), in the format:scene = {"scene": {"pointsource": {}, # PSF "background": {}, # spatially flat "host": {}}} # structured background
or the name of a scene configuration file. Default is None.
**kwargs – Goes to
get_config, overriding thesceneand the Lazuliinstrumentconfiguration.
- Returns:
VirtualLazuliTarget– An instance of the class.
- classmethod from_simulation(simulation)#
Load the instance from an already-built simulation.
- Parameters:
simulation (
slicersim.simulation.Simulation) – The simulation the target wraps.- Returns:
VirtualTarget– An instance of the class.
See also
from_sceneBuild the simulation from a scene configuration.
- get_band_snr(lbda_range, frame='obs', per_resolution=True, statistic=<function nanmean>, **kwargs)#
Get the signal-to-noise ratio over a wavelength range.
- Parameters:
lbda_range (
tupleoffloatorlistoftuple) – Wavelength range(min, max)in Angstrom (or a list of them).frame (
str, optional) – Reference frame oflbda_range:"rest"or"obs". Default is"obs".per_resolution (
bool, optional) – If True, return the SNR per spectral resolution element, otherwise per wavelength bin. Default is True.statistic (callable, optional) – Function used to summarise the signal and variance over
lbda_range. Default isnumpy.nanmean.**kwargs – Goes to
get_band_snr(e.g.switch_off).
- Returns:
floatornumpy.ndarray– The SNR, one per wavelength range if a list is given. If any detector pixel saturates,numpy.infis returned.
- get_cube(which='both', **kwargs)#
Get the simulated cubes, for one or both Lazuli fields.
- Parameters:
- Returns:
tuple–(cube, varcube), the cube (ADU) and variance cube (ADU^2) of the requested field, or, ifwhich="both",((cube_narrow, varcube_narrow), (cube_wide, varcube_wide)).- Raises:
ValueError – If
whichis not"current"while the spectrograph is set up neither as the narrow nor the wide field.NotImplementedError – If the scene contains a host (not yet supported).
Notes
When switching field, the point source position is converted to the spaxel units of the other field. The original spectrograph setup and position are restored afterwards.
- get_data_volume(units='GB', per_ramp=False)#
Get the data volume of the observation.
- Parameters:
- Returns:
float– Data volume inunits.
See also
get_data_volumeThe underlying method.
- get_detector_image(mapper, cubes=None, **kwargs)#
Project the narrow and wide field cubes onto a single detector image.
Deprecated since version 1.1.1: Use
to_imageinstead, which this simply forwards to.- Parameters:
mapper (
slicersim.mapper.SlicerMapper) – Mapper describing where each slice falls on the detector.cubes (
tupleofnumpy.ndarray, optional) –(cube_narrow, cube_wide)to project. Default is None.**kwargs – Goes to
to_image.
- Returns:
numpy.ndarray– 2D detector image.- Warns:
UserWarning – Always, since this method is deprecated in favour of
to_image.
- get_exposure_time(snr=None, full=False, **kwargs)#
Get the exposure time of the current configuration.
- Parameters:
snr (
float, optional) – Currently has no effect on the returned time:setup_to_snris called withinplace=False, so the configuration used for the exposure time remains the current one. Default is None.full (
bool, optional) – If True, return all timing details; otherwise only the total exposure time. Default is False.**kwargs – Goes to
setup_to_snr. Ignored ifsnris None.
- Returns:
floatordict– Total exposure time in seconds (all ramps included), or, iffullis True, a dict of times in seconds with keys"integration_time","exposure_time"(one ramp),"tframe","tgroup"and"total_exptime".
- get_properties(which, default=None, as_dict=True)#
Get parameter values of the target’s simulation.
Shortcut to
get_parameter.- Parameters:
which (
strorlistofstr) – Name(s) of the parameter(s), e.g."redshift"or["nmd", "nramps"].default (
object, optional) – Value returned if a parameter is not found. Default is None.as_dict (
bool, optional) – Only used whenwhichis a single name that is not found: if True,{which: default}is returned instead ofdefault. Default is True.
- Returns:
objectordict– The parameter value ifwhichis a str, a dict{name: value}if it is a list.
- get_readout_config()#
Get the current MACC mode and number of ramps.
- Returns:
dict– Read-out configuration, with keys:"nmd":(n_groups, n_frames_per_group, n_drops)."nramps": number of ramps, each ramp following thenmdMACC mode.
- get_spectrograph_field()#
Get the current spectrograph field.
- Returns:
field (
str) – Name of the current field ("narrow"or"wide"), or"unknown"if the spectrograph matches neither (seespectroconfig_to_fieldname).config (
dict) – Current"spatial_shape"and"spatial_scale"(arcsec) of the spectrograph.
- get_spectrum(unit='adu', incl_error=True, **kwargs)#
Get the simulated spectrum of the point source (or of the galaxy).
The spectrum is extracted from the simulation in ADU and converted to
unit. Without point source (or withof_host=True), it is the host spectrum within theaperture(seeget_aperture).- Parameters:
unit (
str, optional) –Unit of the returned flux (and of the variance, squared):
"adu": total ADU integrated over all ramps."flambda": erg/s/cm^2/A."fphoton": photon/s."rate": ADU/s."framerate": ADU/frame.
Default is
"adu".incl_error (
bool, optional) – If True, the returned flux is randomly scattered according to the variance (hence realistic). If False, the noise-free flux is returned. Default is True.**kwargs – Goes to
get_spectrum(e.g.switch_off,of_hostormethod:"optimal"or"aperture"photometry).
- Returns:
lbda (
numpy.ndarray) – Wavelengths in Angstrom.flux (
numpy.ndarray) – Flux inunit.variance (
numpy.ndarray) – Variance of the flux, inunitsquared.
- get_variance_contribution()#
Get the contribution of each noise source to the variance.
- Returns:
pandas.DataFrame– One row per wavelength, with columns"lbda"(Angstrom),"flux"and"variance"(ADU, ADU^2), and one column per variance source (seevariance_sources, e.g."dark","ron","pointsource","background","thermal") giving its contribution to the variance in ADU^2.
- setup_to_snr(snr, per_resolution=True, lbda_range=[4000, 6800], frame='rest', statistic=<function nanmean>, inplace=True, **kwarg)#
Find the detector read-out configuration reaching a target SNR.
The MACC mode and number of ramps are varied until the signal-to-noise ratio over
lbda_rangereachessnr(seefetch_snr).- Parameters:
snr (
float) – Target signal-to-noise ratio.per_resolution (
bool, optional) – If True,snris given per spectral resolution element and is converted into a SNR per wavelength bin,snr / sqrt(dispersion_resolution), before being passed tofetch_snr. If False,snris per wavelength bin. Default is True.lbda_range (
listoffloat, optional) – Wavelength range[min, max]in Angstrom over which the SNR is computed. Default is[4000, 6800].frame (
str, optional) – Reference frame oflbda_range:"rest"(rest-frame) or"obs"(observer-frame). Default is"rest".statistic (callable, optional) – Function used to summarise the SNR over
lbda_range. Default isnumpy.nanmean.inplace (
bool, optional) – If True, the simulation is updated to the returned configuration. Default is True.**kwarg – Goes to
fetch_snr(e.g.max_grouporndrop).nframe_per_groupis set to 8 and cannot be given.
- Returns:
- show_cube(cubes, lbda_range, axes=None, ref_field='narrow', **kwarg)#
Show the narrow and wide field cubes, collapsed over a wavelength range.
Each cube is summed over the wavelength bins within
lbda_range, and the two resulting images are displayed following the Lazuli layout: the narrow field on top of the wide field, separated by the gap between the two fields (SPECTROGRAPH_FIELD["hspace"]).- Parameters:
cubes (
tupleofnumpy.ndarray) –(cube_narrow, cube_wide), the cubes of each field, with wavelength as first axis (e.g. the cubes returned byget_cube(which="both"), without their variance).lbda_range (
listoffloat) – Wavelength range[min, max]in Angstrom (observer-frame) over which the cubes are summed. Bounds are excluded.axes (
tupleofmatplotlib.axes.Axes, optional) –(ax_narrow, ax_wide), the axes to draw the narrow and wide fields into. If None, a new figure is created with the Lazuli layout (see_get_fieldlayout_). Default is None.ref_field (
str, optional) – Field whose image sets the colour normalisation (99.8 percentile interval with an asinh stretch) shared by both images:"narrow"or"wide". Default is"narrow".**kwarg – Goes to
matplotlib.axes.Axes.imshow, overriding the default display properties (origin,norm,interpolation,aspectandcmap).
- Returns:
matplotlib.figure.Figure– The figure containing the axes.
Notes
The wide field axes is repositioned right below the narrow field axes, so its original position is changed even when
axesis given.Examples
>>> (cube_n, _), (cube_w, _) = target.get_cube(which="both") >>> fig = target.show_cube((cube_n, cube_w), lbda_range=[5000, 6000])
- to_image(mapper, cubes=None, **kwargs)#
Project the narrow and wide field cubes onto a single detector image.
Both fields are generated, then each is projected onto the slices it occupies: the narrow field fills the first
nslices_narrowslices and the wide field the ones immediately above. The two projections are summed into one image.- Parameters:
mapper (
slicersim.mapper.SlicerMapper) – Mapper describing where each slice falls on the detector.cubes (
tupleofnumpy.ndarray, optional) –(cube_narrow, cube_wide)to project, to avoid regenerating them. If None, both are generated withget_cube(which="both"). Default is None.**kwargs – Goes to
get_cube. Ignored ifcubesis given.
- Returns:
numpy.ndarray– 2D detector image, summing the narrow and wide field contributions.
Notes
The slice identifiers are reversed (
[::-1]) before being handed to the mapper, because the mapper numbers slices from the top of the detector while the cubes are ordered from the bottom.
- pointsource_properties#
Names of the mutable parameters of the point source (list of str).
- simulation#
The
Simulationwrapped by the target.