VirtualLazuliTarget#

class VirtualLazuliTarget[source]#

Bases: object

Mixin adding the Lazuli instrument and its two fields to a target.

This class is not meant to be used directly: it is combined with one of the generic targets of target (e.g. LazuliSupernova inherits from VirtualLazuliTarget and Supernova). It sets the Lazuli instrument configuration and adds the handling of the narrow and wide fields (change_spectrograph, get_spectrograph_field, get_cube, to_image).

Parameters:

simulation (slicersim.simulation.Simulation, optional) – The simulation the target wraps. Default is None.

Methods

change_configuration

Change the Lazuli instrument configuration.

change_spectrograph

Change the spectrograph configuration.

from_scene

Load the instance from a scene configuration.

get_cube

Get the simulated cubes, for one or both Lazuli fields.

get_detector_image

Project the narrow and wide field cubes onto a single detector image.

get_readout_config

Get the current MACC mode and number of ramps.

get_spectrograph_field

Get the current spectrograph field.

show_cube

Show the narrow and wide field cubes, collapsed over a wavelength range.

to_image

Project the narrow and wide field cubes onto a single detector image.

change_configuration(which)[source]#

Change the Lazuli instrument configuration.

The corresponding configuration file (lazuli_eol.toml or lazuli_cbe.toml) is read and the simulation updated with it.

Parameters:

which (str) – Name of the configuration: "eol" (end of life) or "cbe" (current best estimate); "bol" (beginning of life) is an alias of "cbe".

Returns:

None

change_spectrograph(field=None, spatial_shape=None, spatial_scale=None)[source]#

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_shape and spatial_scale are applied. Default is None.

  • spatial_shape (tuple of int, optional) – Spaxel grid shape (e.g. (40, 40)), overriding that of field if any. Default is None.

  • spatial_scale (float or list of float, optional) – Spaxel size in arcsec, overriding that of field if any. If a float, spaxels are square; if a list, (x, y). Default is None.

Returns:

None

Raises:

ValueError – If field is not a known Lazuli field.

classmethod from_scene(scene=None, **kwargs)[source]#

Load the instance from a scene configuration.

Parameters:
  • scene (dict or str, 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 the scene and the Lazuli instrument configuration.

Returns:

VirtualLazuliTarget – An instance of the class.

get_cube(which='both', **kwargs)[source]#

Get the simulated cubes, for one or both Lazuli fields.

Parameters:
  • which (str, optional) –

    Which cube should be computed:

    • "both": both narrow and wide fields.

    • "current": only the current setup.

    • "narrow": only the narrow field.

    • "wide": only the wide field.

    Default is "both".

  • **kwargs – Goes to get_cube.

Returns:

tuple – (cube, varcube), the cube (ADU) and variance cube (ADU^2) of the requested field, or, if which="both", ((cube_narrow, varcube_narrow), (cube_wide, varcube_wide)).

Raises:
  • ValueError – If which is 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_detector_image(mapper, cubes=None, **kwargs)[source]#

Project the narrow and wide field cubes onto a single detector image.

Deprecated since version 1.1.1: Use to_image instead, which this simply forwards to.

Parameters:
Returns:

numpy.ndarray – 2D detector image.

Warns:

UserWarning – Always, since this method is deprecated in favour of to_image.

get_readout_config()[source]#

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 the nmd MACC mode.

get_spectrograph_field()[source]#

Get the current spectrograph field.

Returns:

  • field (str) – Name of the current field ("narrow" or "wide"), or "unknown" if the spectrograph matches neither (see spectroconfig_to_fieldname).

  • config (dict) – Current "spatial_shape" and "spatial_scale" (arcsec) of the spectrograph.

show_cube(cubes, lbda_range, axes=None, ref_field='narrow', **kwarg)[source]#

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 (tuple of numpy.ndarray) – (cube_narrow, cube_wide), the cubes of each field, with wavelength as first axis (e.g. the cubes returned by get_cube(which="both"), without their variance).

  • lbda_range (list of float) – Wavelength range [min, max] in Angstrom (observer-frame) over which the cubes are summed. Bounds are excluded.

  • axes (tuple of matplotlib.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, aspect and cmap).

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 axes is 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)[source]#

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_narrow slices 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 (tuple of numpy.ndarray, optional) – (cube_narrow, cube_wide) to project, to avoid regenerating them. If None, both are generated with get_cube(which="both"). Default is None.

  • **kwargs – Goes to get_cube. Ignored if cubes is 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.