Lazuli3DFlat#

class Lazuli3DFlat(simulation=None)[source]#

Bases: VirtualLazuliTarget, Flat3DCalibration

Lazuli 3D flat-field calibration target.

Combines the Lazuli instrument configuration of VirtualLazuliTarget with the spatially uniform scene of Flat3DCalibration, to simulate the flat-field exposures used to calibrate the wavelength response of the two fields.

The calibration source is the on-board QTH lamp, approximated by a blackbody (see from_qth), optionally seen through the Fabry-Perot etalon that turns its continuum into a comb of spectral features used for wavelength calibration (see from_febryperot).

It is normally built with from_qth or from_febryperot. The spectrograph is set up in the narrow field by default; use change_spectrograph to switch field.

Parameters:

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

Examples

>>> flat = Lazuli3DFlat.from_qth()
>>> cube, varcube = flat.get_cube(which="current")

Methods

change_configuration

Change the Lazuli instrument configuration.

change_detector

Change the detector read-out configuration.

change_properties

Change any mutable parameter of the simulation.

change_spectrograph

Change the spectrograph configuration.

from_blackbody

Build a 3D flat calibration target from a blackbody lamp.

from_febryperot

Initialize the flat as observing the QTH lamp through the Fabry-Perot.

from_qth

Initialize the flat as observing the QTH lamp.

from_scene

Load the instance from a scene configuration.

from_simulation

Load the instance from an already-built simulation.

from_spectrum

Build a 3D flat calibration target from a reference spectrum.

get_band_snr

Get the signal-to-noise ratio over a wavelength range.

get_cube

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

get_data_volume

Get the data volume of the observation.

get_detector_image

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

get_exposure_time

Get the exposure time of the current configuration.

get_properties

Get parameter values of the target's simulation.

get_readout_config

Get the current MACC mode and number of ramps.

get_spectrograph_field

Get the current spectrograph field.

get_spectrum

Not implemented for the generic VirtualFlat class.

get_variance_contribution

Get the contribution of each noise source to the variance.

setup_to_snr

Not implemented for the generic VirtualFlat class.

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.

Attributes

pointsource_properties

Names of the mutable parameters of the point source (list of str).

simulation

The Simulation wrapped by the target.

change_configuration(which)#

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_detector(nmd=None, max_group=None, nramps=None)#

Change the detector read-out configuration.

Parameters set to None are left unchanged.

Parameters:
  • nmd (tuple of int, optional) – MACC mode (n_groups, n_frames_per_group, n_drops). Default is None.

  • max_group (int, optional) – Maximum number of groups in a single ramp. Default is None.

  • nramps (int, optional) – Number of ramps. Default is None.

Returns:

None

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.5 or pointsource__phase=-2).

Returns:

None

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_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_blackbody(temperature, instrument=None, mag=15, band='sdssr', magsys='ab', lbda_range=[3000, 20000], lbda_bin=2000, **kwargs)#

Build a 3D flat calibration target from a blackbody lamp.

Parameters:
  • temperature (float) – Temperature of the blackbody in Kelvin.

  • instrument (str or dict, optional) – Instrument configuration (file name or dict). If None, the class default _INSTRUMENT is used. Default is None.

  • mag (float, optional) – Magnitude the blackbody spectrum is normalised to. Default is 15.

  • band (str, optional) – Name of the bandpass used for the normalisation (any sncosmo bandpass name). Default is "sdssr".

  • magsys (str, optional) – Name of the sncosmo magnitude system. Default is "ab".

  • lbda_range (list of float, optional) – [min, max] wavelength range in Angstrom. Default is [3_000, 20_000].

  • lbda_bin (int, optional) – Number of wavelength samples. Default is 2000.

  • **kwargs – Goes to from_spectrum.

Returns:

Flat3DCalibration – An instance of the class.

Raises:

ValueError – If no instrument is given and the class defines no default _INSTRUMENT.

classmethod from_febryperot(fp_throughput='lazuli_fp_transmission.csv', temperature=None, mag=12, band='sdssr', **kwargs)[source]#

Initialize the flat as observing the QTH lamp through the Fabry-Perot.

Parameters:
  • fp_throughput (str or callable, optional) – Fabry-Perot transmission. If a str, the path to a csv file with the wavelength in Angstrom as index and a "transmission" column; it is looked up in the package config directory when it is not found locally. If a callable, the transmission as a function of wavelength in Angstrom. Default is "lazuli_fp_transmission.csv".

  • temperature (float, optional) – Temperature of the lamp in Kelvin. Currently ignored: the class default _QTH_TEMPERATURE (3000 K) is always used. Default is None.

  • mag (float, optional) – Magnitude the lamp spectrum is normalised to, before the Fabry-Perot transmission is applied. Default is 12.

  • band (str, optional) – Name of the bandpass used for the normalisation (any sncosmo bandpass name). Default is "sdssr".

  • **kwargs – Goes to from_febryperot.

Returns:

Lazuli3DFlat – An instance of the class.

Warns:

UserWarning – When fp_throughput is read from a file, flagging the temporary extrapolation patch that fills wavelengths outside the tabulated range with the first tabulated transmission value.

See also

from_qth

The same lamp, without the Fabry-Perot etalon.

classmethod from_qth(temperature=None, mag=12, band='sdssr', **kwargs)[source]#

Initialize the flat as observing the QTH lamp.

The lamp is modelled as a blackbody (see from_blackbody).

Parameters:
  • temperature (float, optional) – Temperature of the lamp in Kelvin. If None, the class default _QTH_TEMPERATURE (3000 K) is used. Default is None.

  • mag (float, optional) – Magnitude the lamp spectrum is normalised to. Default is 12.

  • band (str, optional) – Name of the bandpass used for the normalisation (any sncosmo bandpass name). Default is "sdssr".

  • **kwargs – Goes to from_blackbody (e.g. magsys, lbda_range, lbda_bin).

Returns:

Lazuli3DFlat – An instance of the class.

See also

from_febryperot

The same lamp seen through the Fabry-Perot etalon.

classmethod from_scene(scene=None, **kwargs)#

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.

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_scene

Build the simulation from a scene configuration.

classmethod from_spectrum(lbda, flux, instrument=None, **kwargs)#

Build a 3D flat calibration target from a reference spectrum.

The spectrum is loaded as a spatially uniform Background, and the scene is built with neither point source nor host, so that the full IFU field is illuminated uniformly.

Parameters:
  • lbda (array_like) – Wavelength array in Angstrom.

  • flux (array_like) – Flux of the reference spectrum in erg/s/cm^2/A.

  • instrument (str or dict, optional) – Instrument configuration (file name or dict). If None, the class default _INSTRUMENT is used. Default is None.

  • **kwargs – Goes to from_spectrum, overriding the defaults mag=None, band="bessellb" and meta={}.

Returns:

Flat3DCalibration – An instance of the class, wrapping the corresponding simulation.

Raises:

ValueError – If no instrument is given and the class defines no default _INSTRUMENT.

Notes

mag defaults to None, so the reference spectrum keeps its native amplitude and is not photometrically renormalised.

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 (tuple of float or list of tuple) – Wavelength range (min, max) in Angstrom (or a list of them).

  • frame (str, optional) – Reference frame of lbda_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 is numpy.nanmean.

  • **kwargs – Goes to get_band_snr (e.g. switch_off).

Returns:

float or numpy.ndarray – The SNR, one per wavelength range if a list is given. If any detector pixel saturates, numpy.inf is returned.

get_cube(which='both', **kwargs)#

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_data_volume(units='GB', per_ramp=False)#

Get the data volume of the observation.

Parameters:
  • units (str, optional) – Unit of the returned volume (any astropy data unit, e.g. "MB" or "GB"). Default is "GB".

  • per_ramp (bool, optional) – If True, return the volume of a single ramp instead of the total volume over all ramps. Default is False.

Returns:

float – Data volume in units.

See also

get_data_volume

The 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_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_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_snr is called with inplace=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 if snr is None.

Returns:

float or dict – Total exposure time in seconds (all ramps included), or, if full is 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 (str or list of str) – 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 when which is a single name that is not found: if True, {which: default} is returned instead of default. Default is True.

Returns:

object or dict – The parameter value if which is 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 the nmd MACC 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 (see spectroconfig_to_fieldname).

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

get_spectrum(*args, **kwargs)#

Not implemented for the generic VirtualFlat class.

Parameters:
  • *args – Ignored.

  • **kwargs – Ignored.

Raises:

NotImplementedError – Always raised; subclasses must override this method.

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 (see variance_sources, e.g. "dark", "ron", "pointsource", "background", "thermal") giving its contribution to the variance in ADU^2.

setup_to_snr(*args, **kwargs)#

Not implemented for the generic VirtualFlat class.

Parameters:
  • *args – Ignored.

  • **kwargs – Ignored.

Raises:

NotImplementedError – Always raised; subclasses must override this method.

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 (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)#

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.

pointsource_properties#

Names of the mutable parameters of the point source (list of str).

simulation#

The Simulation wrapped by the target.