Spectrograph#

class Spectrograph(lbda, telescope=None, spaxels={}, throughput=None, spatial_psf={}, lbda_edges=None, optics={}, dispersion_resolution=2, meta={})[source]#

Bases: object

Generic integral field spectrograph.

It holds the wavelength sampling, the spaxel grid, the spatial PSF, the throughput and the internal (thermal) optics of the spectrograph, and converts scene spectra (in erg/s/cm²/Å) into photon flux cubes (in ph/s/spaxel), see e.g. generate_pointsource.

You likely want to create it using the from_config constructor.

Parameters:
  • lbda (array_like) – Mid-bin wavelengths, in Angstrom.

  • telescope (Telescope, optional) – Telescope feeding the spectrograph. Default is None.

  • spaxels (dict, optional) – Spaxel information, passed to set_spaxels: {"shape": (ny, nx), "spx_scale": float} with spx_scale in arcsec. Default is {}.

  • throughput (float, callable or OpticsThroughput, optional) – Throughput of the spectrograph, see set_throughput. Default is None.

  • spatial_psf (dict, optional) – Spatial PSF information, with keys "sigma_spectral" (chromatic sigma in arcsec at lbda_ref), "guiding_sigma" (in arcsec) and "profile". Default is {}.

  • lbda_edges (array_like, optional) – Wavelength bin edges, in Angstrom (len(lbda) + 1 entries). Default is None.

  • optics (ThermalOptics, optional) – Internal optics of the spectrograph (thermal emission). Default is {}.

  • dispersion_resolution (float, optional) – Number of pixels per spectral resolution element (spot size), see dispersion_resolution. Default is 2.

  • meta (dict, optional) – Metadata (typically the input configuration). Default is {}.

Methods

aperture_extraction

Extracted signal and variance of an extended source within an aperture.

apply_line_spread_function

Apply the line spread function to a flux cube.

build_lbda_from_config

Build wavelength coordinates from a configuration dictionary.

chromatic_average

Compute the chromatic average of a quantity.

cube_to_slice

Collapse a cube into images over wavelength ranges.

from_config

Create a spectrograph from a configuration dictionary.

generate_background

Generate a photon flux cube from uniform scene background spectrum.

generate_fullof_cube

Project an array as a cube (not implemented).

generate_pointsource

Generate a photon flux cube from a point source spectrum.

generate_structured_background

Generate a photon flux cube from a structured background scene.

generate_thermal_signal

Get the dispersed thermal signal, in ph/s/spx/Δλ.

get_additonal_spatial_scatter

Get the scatter induced by the telescope jitter and instrumental PSF.

get_aperture

Spaxels within a circular (or elliptical) aperture.

get_array_as_cube

Broadcast an array into a spectrograph-shaped cube.

get_dispersion_resolution

Get the effective dispersion resolution, in pixels.

get_empty_cube

Get a uniform data cube.

get_fieldname

Get the name of the field matching the spaxel configuration.

get_instrumental_psf

Get the contribution of the spectrograph to the total spot size.

get_lbda

Get the wavelength array.

get_lsf_dispersion

Get the Gaussian LSF dispersion, in wavelength bins (pixels).

get_nea

Noise Equivalent Area (PSF -> Spaxel -> detector).

get_nea_spatial

Get the noise equivalent area of the spatial PSF.

get_nea_telescope_airy

Get the noise equivalent area of the telescope Airy disk.

get_psf_sigma_spectral

Get the spatial PSF standard deviation (in arcsec or in spaxels).

get_resolving_power

Get the resolving power \(\mathcal{R} = \lambda/\Delta\lambda\).

get_spatial_psf

Get the normalized 2D spatial PSF on the spaxel grid.

get_spaxel_centroids

Get the spaxel centroid coordinates.

get_spectrograph_shape

Get the spatial shape of the spaxel grid.

get_throughput

Get the spectrograph throughput.

pointsource_variance

Point-source extracted variance from variance cube.

set_spaxels

Set the spaxel information.

set_throughput

Set the throughput of the spectrograph.

show_fwhm

Show the full width at half maximum (FWHM) of the spatial PSF.

show_nea

Show the total noise equivalent area as a function of wavelength.

show_nea_spatial

Show the spatial noise equivalent area as a function of wavelength.

show_psf

Show the spatial PSF, integrated over a wavelength range.

update

Update any mutable attribute of the spectrograph.

update_lbda

Update the wavelength coordinates.

Attributes

dispersion_resolution

Effective dispersion resolution (spot size), in pixels.

flambda2photon

Chromatic conversion factor from erg/s/cm²/Å to ph/s.

lbda_bin

Wavelength bins (lbda_min, lbda_max), of shape (nlbda, 2), in Angstrom.

lbda_ref

Reference wavelength of the chromatic PSF, in Angstrom (default 10000).

meta

Metadata of the instance.

mutable_parameters

Mutable parameters (list)

name

Name of the spectrograph (empty string if not set).

nlbda

Number of spectral pixels (wavelength bins).

omega

Spaxel solid angle, in steradians.

psf_sigma_spectral

Chromatic PSF sigma at lbda_ref, in arcsec.

skyarea

Full sky area covered by the spaxels (not implemented, always None).

spaxel_extent

Extent [-hx, hx, -hy, hy] of the spaxel grid, in spaxels.

spaxels

Spaxel coordinates and properties (see build_pixels).

spx_area

Area of a spaxel, in arcsec².

spx_centroids

Spaxel (x, y) centroid coordinates, in spaxels.

spx_edges

Spaxel (x, y) edge coordinates, in spaxels.

spx_shape

Shape (ny, nx) of the spaxel grid.

spx_spatial_scale

Spatial scale of a spaxel, in arcsec.

type

Type of the spectrograph (e.g. "slicer" or "mla").

aperture_extraction(cube, varcube, position=(0, 0), radius=5, psf_profile='default', optimal=False)[source]#

Extracted signal and variance of an extended source within an aperture.

Contrary to pointsource_variance, the signal is measured from the (noise-free) signal cube, using the same weights as the variance:

  • plain summation (optimal=False): signal = sum(cube) and variance = sum(varcube) over the aperture;

  • optimal extraction (optimal=True): inverse-variance weighted least-square fit of the PSF profile, i.e. the flux of the point source that best matches the cube at position: signal = sum(psf*cube/var) / sum(psf**2/var) and variance = 1 / sum(psf**2/var).

Parameters:
  • cube (array_like) – Signal cube, of shape (nlbda, ny, nx).

  • varcube (array_like) – Variance cube, of shape (nlbda, ny, nx), in the square of the cube unit.

  • position (tuple of float, optional) – (x, y) aperture center, in spaxels. Default is (0, 0).

  • radius (float or tuple of float, optional) – Aperture radius in spaxels, see get_aperture. Default is 5.

  • psf_profile (str, optional) – PSF profile used for the optimal extraction (see get_spatial_psf). Default is "default".

  • optimal (bool, optional) – If True, use optimal extraction, otherwise plain summation. Default is False.

Returns:

signal, variance (numpy.ndarray) – Extracted signal and variance, of shape (nlbda,).

See also

pointsource_variance

Variance of a point source.

apply_line_spread_function(fluxes, **kwargs)[source]#

Apply the line spread function to a flux cube.

The LSF is a Gaussian of sigma get_lsf_dispersion(as_="scale") wavelength bins.

Parameters:
Returns:

numpy.ndarray – Fluxes convolved with the LSF, with the same shape as fluxes.

static build_lbda_from_config(config)[source]#

Build wavelength coordinates from a configuration dictionary.

Parameters:

config (dict) – Configuration dictionary.

Returns:

See also

slicersim.spectrograph.build_lbda_from_config

The function called.

chromatic_average(quantity)[source]#

Compute the chromatic average of a quantity.

The average is weighted by the wavelength bin widths, i.e. averaged over wavelength rather than over pixels.

Parameters:

quantity (array_like) – Chromatic quantity, of shape (nlbda,).

Returns:

float – Chromatic average.

cube_to_slice(cube, lbda_range, func=<function nansum>, squeeze=False)[source]#

Collapse a cube into images over wavelength ranges.

Parameters:
  • cube (array_like) – Data cube of shape (nlbda, ny, nx).

  • lbda_range (tuple of float or list of tuple) – Wavelength range(s) (wmin, wmax), in Angstrom (bounds included).

  • func (callable, optional) – Function merging the wavelengths of a range into one image, called as func(subcube, axis=0). Default is numpy.nansum.

  • squeeze (bool, optional) – If True, squeeze the output array. Default is False.

Returns:

numpy.ndarray – Images, of shape (n_ranges, ny, nx).

classmethod from_config(config, telescope=None)[source]#

Create a spectrograph from a configuration dictionary.

Parameters:
  • config (dict) – Spectrograph configuration dictionary (e.g. the "spectrograph" entry of get_config). It must contain the "throughput", "optics" and "psf" entries, and the wavelength and spaxel information (see build_lbda_from_config and build_spaxels_from_config).

  • telescope (Telescope, optional) – Telescope feeding the spectrograph. Default is None.

Returns:

Spectrograph – An instance of the calling class.

generate_background(spectrum, oversampling=None, apply_lsf=True)[source]#

Generate a photon flux cube from uniform scene background spectrum.

Parameters:
  • spectrum (array_like) – Uniform scene background spectrum, of shape (nlbda,), in erg/s/cm²/Å/arcsec².

  • oversampling (int, optional) – Spatial oversampling factor of the output cube. Default is None.

  • apply_lsf (bool, optional) – If True, apply the line spread function. Default is True.

Returns:

numpy.ndarray – Photon flux cube, of shape (nlbda, ny, nx), in ph/s/spx.

generate_fullof_cube(array, oversample=True)[source]#

Project an array as a cube (not implemented).

Placeholder: this currently does nothing and returns None. See get_array_as_cube instead.

Parameters:
  • array (array_like) – Array to project.

  • oversample (bool, optional) – Unused. Default is True.

generate_pointsource(spectrum, position=(0, 0), psf_profile='default', oversampling=None, as_oversampled=False, apply_lsf=True, **kwargs)[source]#

Generate a photon flux cube from a point source spectrum.

Parameters:
  • spectrum (array_like) – Point source spectrum, of shape (nlbda,), in erg/s/cm²/Å.

  • position (tuple of float, optional) – (x, y) point source position, in spaxels. Default is (0, 0).

  • psf_profile (str, optional) – PSF profile to use (see get_spatial_psf). Default is "default".

  • oversampling (int, optional) – Spatial oversampling factor of the PSF (see get_spatial_psf). Default is None.

  • as_oversampled (bool, optional) – If True, return the oversampled cube. Default is False.

  • apply_lsf (bool, optional) – If True, apply the line spread function. Default is True.

  • **kwargs – Goes to get_spatial_psf.

Returns:

numpy.ndarray – Photon flux cube, of shape (nlbda, ny, nx), in ph/s/spx.

generate_structured_background(cube, psf_profile='default', apply_lsf=True, **kwargs)[source]#

Generate a photon flux cube from a structured background scene.

The input cube is converted into photons and convolved, wavelength per wavelength, by the spatial PSF (see get_spatial_psf).

Parameters:
  • cube (array_like) – (nlbda, ny, nx) structured background (e.g. host) flux per spaxel in erg/s/cm²/Å, on the spaxel grid (see spx_shape).

  • psf_profile (str, optional) – PSF profile to use. Default is “default”.

  • apply_lsf (bool, optional) – If True, apply the line spread function. Default is True.

  • **kwargs – Goes to get_spatial_psf.

Returns:

numpy.ndarray – Photon flux cube, of shape (nlbda, ny, nx), in ph/s/spx.

generate_thermal_signal(lbda_bin=None, as_cube=False, oversampling=None, apply_lsf=True, as_sum=True)[source]#

Get the dispersed thermal signal, in ph/s/spx/Δλ.

This is the thermal emission that goes through the disperser: the telescope mirrors and the spectrograph optical surfaces located before the disperser.

Parameters:
  • lbda_bin (array_like, optional) – (nlbda, 2) list of spectral domains in Angstrom. If None, lbda_bin is used. Default is None.

  • as_cube (bool, optional) – If True, return a (nlbda, ny, nx) cube, otherwise a (nlbda,) spectrum. Default is False.

  • oversampling (int, optional) – Spatial oversampling factor, used if as_cube is True. Default is None.

  • apply_lsf (bool, optional) – If True, apply the line spread function. Default is True.

  • as_sum (bool, optional) – Unused: the contributions are always summed. Default is True.

Returns:

numpy.ndarray – Thermal signal in ph/s/spx/Δλ, of shape (nlbda,) or (nlbda, ny, nx) (see as_cube).

get_additonal_spatial_scatter(guiding_sigma=None, incl_instrument=True, in_spaxels=True)[source]#

Get the scatter induced by the telescope jitter and instrumental PSF.

The current implementation assumes Gaussian scatter.

Parameters:
  • guiding_sigma (float, optional) – Gaussian sigma (in arcsec) of the jitter. If None, the internally stored spatial_psf["guiding_sigma"] is used. Set guiding_sigma=0 for no guiding scatter. Default is None.

  • incl_instrument (bool, optional) – If True, also include the instrumental PSF (see get_instrumental_psf) along the y (slice) direction. This only applies to slicer spectrographs. Default is True.

  • in_spaxels (bool, optional) – If True, return the scatter in spaxels, otherwise in arcsec. Default is True.

Returns:

numpy.ndarray or None – (sigma_x, sigma_y) Gaussian sigma, in spaxels or in arcsec (see in_spaxels). None if there is no scatter.

get_aperture(position=(0, 0), radius=5)[source]#

Spaxels within a circular (or elliptical) aperture.

Parameters:
  • position (tuple of float, optional) – (x, y) aperture center, in spaxels. Default is (0, 0).

  • radius (float or tuple of float, optional) – Aperture radius in spaxels, either a float (circular aperture) or (radius_y, radius_x) (elliptical aperture). Default is 5.

Returns:

numpy.ndarray – (ny, nx) boolean mask, True for the spaxels whose centroid is within the aperture.

Raises:

ValueError – If radius cannot be parsed.

get_array_as_cube(array, oversampling=None)[source]#

Broadcast an array into a spectrograph-shaped cube.

Parameters:
  • array (float or array_like) – Value(s) filling the cube. Accepted shapes are a scalar (uniform cube), (nlbda, ) (a spectrum, spatially uniform) or the spatial shape (ny, nx) (an image, uniform in wavelength).

  • oversampling (int, optional) – Spatial oversampling factor of the output cube. Default is None, i.e. the native spaxel shape.

Returns:

numpy.ndarray – Cube of shape (nlbda, ny, nx).

Raises:

ValueError – If array has more than 3 dimensions, or if its shape matches neither (nlbda, ) nor the spatial shape of the spectrograph.

See also

get_spectrograph_shape

The spatial shape the cube is built on.

get_dispersion_resolution(which=None)[source]#

Get the effective dispersion resolution, in pixels.

Parameters:

which (str, optional) –

Which axis to return:

  • None: the resolution as stored.

  • "wavelength", "lsf", "wave", "lbda" or "y": the spectral axis.

  • "spatial", "psf" or "x": the spatial axis.

Default is None.

Returns:

float or dict – The dispersion resolution in pixels. If which is None, the value as stored, which may be a float, a 2-element array or a dict with the "wavelength" and "spatial" entries. Otherwise, the resolution of the requested axis.

Raises:

ValueError – If the stored dispersion resolution can be parsed neither as a scalar nor as a 2-element array, or if which is not one of the accepted names.

Notes

2 pixels is optimal: below that the PSF is unresolved, above it the PSF is oversampled and adds unnecessary pixel noise.

When the stored resolution is a 2-element array and which is given, the full {"wavelength", "spatial"} dict is returned instead of the requested axis alone.

get_empty_cube(filled=0, oversampling=None)[source]#

Get a uniform data cube.

Parameters:
  • filled (float, optional) – Value to fill the cube with. Default is 0.

  • oversampling (int, optional) – Spatial oversampling factor. Default is None.

Returns:

numpy.ndarray – Cube of shape (nlbda, ny, nx) filled with filled.

get_fieldname()[source]#

Get the name of the field matching the spaxel configuration.

The field is inferred from the current spatial_shape and spatial_scale of the spectrograph (see meta).

Returns:

str – Field name (e.g. "narrow" or "wide" for Lazuli), or "unknown" if the configuration does not match any known field.

Raises:

NotImplementedError – If the spectrograph is not Lazuli (see name).

get_instrumental_psf(spotsize=None, expected_size=2, in_spaxels=True)[source]#

Get the contribution of the spectrograph to the total spot size.

This contribution is null if spotsize <= expected_size. Otherwise, it is the Gaussian sigma extra_pixels = np.sqrt(spotsize**2 - expected_size**2) / 2, further divided by the anamorphosis factor for slicer spectrographs.

Parameters:
  • spotsize (float, optional) – Total size (in pixels) of a point source on the detector, i.e. the total contribution of telescope and spectrograph. If None, get_dispersion_resolution is used. Default is None.

  • expected_size (float, optional) – Expected geometric footprint (in pixels) of the PSF on the detector. Default is 2.

  • in_spaxels (bool, optional) – If True, return the extra scattering in spaxels (spaxel = pixel for a slicer along the slice), otherwise in arcsec. Default is True.

Returns:

float or numpy.ndarray or None – Extra scattering (Gaussian sigma), in spaxels or arcsec. None if spotsize <= expected_size.

get_lbda(units=None, oversample=None)[source]#

Get the wavelength array.

Parameters:
  • units (str or astropy.units.Unit, optional) – Unit of the returned array. None (default) means Angstrom.

  • oversample (int, optional) – Oversampling factor of the wavelength binning (linear interpolation between the native wavelengths). Default is None.

Returns:

numpy.ndarray – Wavelength array, in Angstrom unless units is given.

get_lsf_dispersion(as_='scale')[source]#

Get the Gaussian LSF dispersion, in wavelength bins (pixels).

Parameters:

as (str or None, optional) –

How the dispersion is defined:

Default is "scale".

Returns:

float – LSF dispersion in wavelength bins.

Raises:

NotImplementedError – If as_ is not one of the accepted values.

get_nea(position=(0, 0), nea_spatial=None, nea_pixels=None)[source]#

Noise Equivalent Area (PSF -> Spaxel -> detector).

Parameters:
  • position (tuple of float, optional) – Position of the PSF in spaxels. Ignored if nea_spatial is given. Default is (0, 0).

  • nea_spatial (float or array_like, optional) – Noise equivalent area of the spatial PSF (in spaxels). If None, get_nea_spatial is used. Default is None.

  • nea_pixels (float or array_like, optional) – Noise equivalent area of a spaxel/slice caused by the cross-dispersion (in pixels). If None, get_nea_pixels() is used (only defined for SlicerSpectrograph and MLASpectrograph). Default is None.

Returns:

float or numpy.ndarray – Total noise equivalent area, in pixels.

get_nea_spatial(position=(0, 0), in_spaxels=True, guiding_sigma=None)[source]#

Get the noise equivalent area of the spatial PSF.

That is, the equivalent number of spaxels contributing noise.

Parameters:
  • position (tuple of float, optional) – Position of the PSF, in spaxels. Default is (0, 0).

  • in_spaxels (bool, optional) – If True, return the area in spaxels, otherwise in arcsec². Default is True.

  • guiding_sigma (float, optional) – Guiding sigma override in arcsec (see get_psf_sigma_spectral). Default is None.

Returns:

numpy.ndarray – Noise equivalent area as a function of wavelength.

Raises:

NotImplementedError – If the spatial PSF profile is not Gaussian.

get_nea_telescope_airy(position=(0, 0), in_spaxels=True)[source]#

Get the noise equivalent area of the telescope Airy disk.

Parameters:
  • position (tuple of float, optional) – Position of the PSF in spaxels. Default is (0, 0).

  • in_spaxels (bool, optional) – If True, return the NEA in spaxels. Only True is currently supported. Default is True.

Returns:

numpy.ndarray – NEA of the Airy disk as a function of wavelength.

See also

slicersim.telescope.Telescope.get_nea_airy

The method called.

get_psf_sigma_spectral(guiding_sigma=None, incl_telescope=True, in_spaxels=False, lbda=None)[source]#

Get the spatial PSF standard deviation (in arcsec or in spaxels).

The total (Gaussian) spatial PSF is the quadratic sum of two components:

  • the optical (chromatic) component, with stddev proportional to wavelength, normalized at lbda_ref (see psf_sigma_spectral),

  • the guiding (achromatic) component, with constant stddev.

Parameters:
  • guiding_sigma (float, optional) – Guiding sigma override in arcsec. If None, self.spatial_psf["guiding_sigma"] is used. Set guiding_sigma=0 for no guiding contribution. Default is None.

  • incl_telescope (bool, optional) – If True, include the optical (chromatic) component. If False, only the guiding component remains. Default is True.

  • in_spaxels (bool, optional) – If True, return sigma in spaxels, otherwise in arcsec. Default is False.

  • lbda (array_like, optional) – Wavelength array in Angstrom. If None, self.lbda is used. Default is None.

Returns:

numpy.ndarray – Total sigma in arcsec or spaxels, of shape (nlbda, 1, 1).

get_resolving_power()[source]#

Get the resolving power \(\mathcal{R} = \lambda/\Delta\lambda\).

It is computed as lbda / np.diff(lbda_edges) / dispersion_resolution, i.e. the resolution element is dispersion_resolution pixels wide.

Returns:

numpy.ndarray – Resolving power, of shape (nlbda,).

get_spatial_psf(profile='default', position=(0, 0), guiding_sigma=None, oversampling=5, as_oversampled=False, incl_instrument=True, incl_telescope=True, **kwargs)[source]#

Get the normalized 2D spatial PSF on the spaxel grid.

This takes the PSF generated by the telescope, includes the jitter and adds the contribution of the instrument internal optics.

Parameters:
  • profile (str, optional) –

    Profile to be used:

    • "default", "gaussian", "normal" or "norm": Gaussian profile using exact erf integration over the spaxels.

    • "airy", "mirror", "telescope" or "airydisk": Airy disk generated by the telescope mirror.

    • "Gaussian2D" or "gaussian2d": Gaussian profile evaluated on the oversampled grid.

    Default is "default".

  • position (tuple of float, optional) – (x, y) location of the point source with respect to the grid center, in spaxels. Default is (0, 0).

  • guiding_sigma (float, optional) – Gaussian sigma (in arcsec) of the jitter. If None, the stored spatial_psf["guiding_sigma"] is used. Default is None.

  • oversampling (int, optional) – Oversampling factor used to evaluate the PSF (not used by the erf-integrated Gaussian profiles unless as_oversampled is True). If None, 3 is used. Set oversampling=1 for no oversampling. Default is 5.

  • as_oversampled (bool, optional) – If True, return the PSF on the oversampled grid. Default is False.

  • incl_instrument (bool, optional) – If True, include the instrumental PSF contribution (see get_additonal_spatial_scatter). Default is True.

  • incl_telescope (bool, optional) – If True, include the telescope PSF and jitter. If False, the guiding sigma is forced to 0. Default is True.

  • **kwargs – For the Gaussian (erf) profile, additional arguments passed to get_gaussian2d. Ignored otherwise.

Returns:

numpy.ndarray – Normalized PSF, of shape (nlbda, ny, nx).

Raises:

ValueError – If profile is not implemented.

Warns:

UserWarning – If incl_telescope is False while guiding_sigma is positive.

get_spaxel_centroids(in_arcsec=False, squeeze=False, oversampling=None)[source]#

Get the spaxel centroid coordinates.

Parameters:
  • in_arcsec (bool, optional) – If True, return centroids in arcsec, otherwise in spaxels. Default is False.

  • squeeze (bool, optional) – If True, squeeze the output arrays. Default is False.

  • oversampling (int or list of int, optional) – Spatial oversampling factor. Default is None (native grid).

Returns:

get_spectrograph_shape(oversampling=None)[source]#

Get the spatial shape of the spaxel grid.

Parameters:

oversampling (int, optional) – Spatial oversampling factor. Default is None (no oversampling).

Returns:

tuple of int or numpy.ndarray – Spaxel grid shape (ny, nx), multiplied by oversampling if given.

get_throughput(lbda=None, **kwargs)[source]#

Get the spectrograph throughput.

When the throughput is callable (e.g. OpticsThroughput), it is called with a which argument set to:

  • meta["which_throughput"] if given (see update);

  • otherwise, for Lazuli, the current field name (see get_fieldname);

  • otherwise None, i.e. the product of all throughput curves.

Parameters:
  • lbda (array_like, optional) – Wavelength array in Angstrom. If None, self.lbda is used. Ignored if the throughput is not callable. Default is None.

  • **kwargs – Goes to the throughput call (e.g. OpticsThroughput.get_throughput). A given which overrides the one described above.

Returns:

numpy.ndarray or float – Throughput as a function of wavelength, or the constant throughput.

Warns:

UserWarning – If lbda is given while the throughput is not callable.

pointsource_variance(varcube, position=(0, 0), radius=5, psf_profile='default', optimal=True, verbose=False)[source]#

Point-source extracted variance from variance cube.

It is evaluated from a plain summation over the aperture, or from an optimal extraction, i.e. inverse-variance weighted least-square fit of the PSF profile (assumed Gaussian). As the extraction is assumed to do a perfect job on the signal, only the variance depends on instrumental parameters and aperture definition.

Parameters:
  • varcube (array_like) – Variance cube, of shape (nlbda, ny, nx), in ADU².

  • position (tuple of float, optional) – (x, y) point source position, in spaxels. Default is (0, 0).

  • radius (float or tuple of float, optional) – Aperture radius in spaxels, either a float (circular aperture) or (radius_y, radius_x) (elliptical aperture). Default is 5.

  • psf_profile (str, optional) – PSF profile to use (see get_spatial_psf). Default is "default".

  • optimal (bool, optional) – If True, use optimal extraction, otherwise plain summation. Default is True.

  • verbose (bool, optional) – If True, print the number of spaxels in the aperture. Default is False.

Returns:

numpy.ndarray – Extracted variance spectrum, of shape (nlbda,), in ADU².

Raises:

ValueError – If radius cannot be parsed.

set_spaxels(shape, spx_scale)[source]#

Set the spaxel information.

Parameters:
  • shape (tuple of int) – Spaxel grid shape (ny, nx).

  • spx_scale (float or tuple of float) – Spaxel size in arcsec, either a float or (scale_y, scale_x).

set_throughput(throughput)[source]#

Set the throughput of the spectrograph.

Parameters:

throughput (float, array_like, callable, pandas.Series, pandas.DataFrame or OpticsThroughput) –

Throughput of the system (between 0 and 1):

  • float: constant throughput.

  • array_like: must broadcast with self.lbda.

  • callable: such that throughput(lbda) returns the throughput at lbda (in Angstrom).

  • pandas.Series: throughput with wavelength (in Angstrom) as index. It is converted into a cubic interpolator (zero outside the given range).

  • pandas.DataFrame: its first column is used as a pandas.Series.

  • OpticsThroughput: detailed per-element throughput.

show_fwhm(ax=None, legend=True, guiding_arcsec=None, in_arcsec=False, show_band=True)[source]#

Show the full width at half maximum (FWHM) of the spatial PSF.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, a new figure and axes are created. Default is None.

  • legend (bool, optional) – If True, show the legend. Default is True.

  • guiding_arcsec (float, optional) – Guiding sigma in arcsec. If None, the stored spatial_psf["guiding_sigma"] is used. Default is None.

  • in_arcsec (bool, optional) – If True, show the FWHM in arcsec, otherwise in spaxels. Default is False.

  • show_band (bool, optional) – If True, highlight the under-sampled (FWHM < 2 spaxels) region. Default is True.

Returns:

matplotlib.figure.Figure – The figure containing the plot.

show_nea(ax=None, position=(0, 0), legend=True)[source]#

Show the total noise equivalent area as a function of wavelength.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, a new figure and axes are created. Default is None.

  • position (tuple of float, optional) – Position of the PSF in spaxels. Default is (0, 0).

  • legend (bool, optional) – If True, show the legend. Default is True.

Returns:

matplotlib.figure.Figure – The figure containing the plot.

show_nea_spatial(ax=None, position=(0, 0), legend=True)[source]#

Show the spatial noise equivalent area as a function of wavelength.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, a new figure and axes are created. Default is None.

  • position (tuple of float, optional) – Position of the PSF in spaxels. Default is (0, 0).

  • legend (bool, optional) – If True, show the legend. Default is True.

Returns:

matplotlib.figure.Figure – The figure containing the plot.

show_psf(lbda_range, profile='default', guiding_arcsec=None, axes=None, position=(0, 0), oversampling=5, in_arcsec=False, norm='log', **kwargs)[source]#

Show the spatial PSF, integrated over a wavelength range.

Three panels are shown: the oversampled PSF without guiding, the oversampled PSF with guiding, and the PSF on the spaxel grid.

Parameters:
  • lbda_range (tuple of float) – Wavelength range (wmin, wmax) to integrate over, in Angstrom.

  • profile (str, optional) – PSF profile to use (see get_spatial_psf). Default is "default".

  • guiding_arcsec (float, optional) – Guiding sigma in arcsec. If None, the stored spatial_psf["guiding_sigma"] is used. Default is None.

  • axes (list of matplotlib.axes.Axes, optional) – List of 3 axes to plot on. If None, a new figure and axes are created. Default is None.

  • position (tuple of float, optional) – Position of the PSF in spaxels. Default is (0, 0).

  • oversampling (int, optional) – Oversampling factor. Default is 5.

  • in_arcsec (bool, optional) – If True, show the extent in arcsec, otherwise in spaxels. Default is False.

  • norm (str, optional) – Normalization for the color scale ("linear" or "log"). Default is "log".

  • **kwargs – Additional arguments passed to matplotlib.axes.Axes.imshow.

Returns:

matplotlib.figure.Figure – The figure containing the plot.

update(reset_others=False, **kwargs)[source]#

Update any mutable attribute of the spectrograph.

The method accepts the django-like format, such that a__b is understood as a.b. For instance, update(optics__temperature=220) is equivalent to update(**{'optics.temperature': 220}).

Notes on the wavelength sampling (lbda):

  • changing dispersion_resolution redefines self.lbda such that the resolving power is unchanged;

  • changing spotsize updates self.dispersion_resolution without updating lbda, effectively changing the resolving power.

Parameters:
  • reset_others (bool, optional) – If True, the parameters not given are reset to their initial values (meta and telescope). Default is False.

  • **kwargs – Parameters to update, e.g. any of mutable_parameters, or telescope.<param>, optics.<param>, throughput.<param>. throughput itself replaces the throughput (see OpticsThroughput.from_config). None values are ignored.

Returns:

list of str – Names of the components that changed, among "telescope", "optics", "throughput", "psf", "spaxels", "lbda" and "meta".

Warns:

UserWarning – If a parameter is not mutable or cannot be parsed. It is then ignored.

update_lbda(lbda, lbda_edges)[source]#

Update the wavelength coordinates.

Parameters:
  • lbda (array_like) – Mid-bin wavelengths, in Angstrom.

  • lbda_edges (array_like) – Bin edge wavelengths, in Angstrom.

dispersion_resolution#

Effective dispersion resolution (spot size), in pixels.

2 is optimal: below that, the PSF is unresolved; above it, the PSF is oversampled, hence producing unnecessary pixel noise.

flambda2photon#

Chromatic conversion factor from erg/s/cm²/Å to ph/s.

It includes the telescope collecting surface, the spectrograph throughput (see get_throughput) and the wavelength bin widths.

lbda_bin#

Wavelength bins (lbda_min, lbda_max), of shape (nlbda, 2), in Angstrom.

lbda_ref#

Reference wavelength of the chromatic PSF, in Angstrom (default 10000).

meta#

Metadata of the instance.

mutable_parameters = ['dispersion_resolution', 'spotsize', 'dispersion_scale', 'which_throughput', 'xdisp_sigma_spectral', 'xdisp_sigma', 'psf_sigma_spectral', 'guiding_sigma', 'spatial_scale', 'spatial_shape', 'spx_scale', 'spx_shape']#

Mutable parameters (list)

name#

Name of the spectrograph (empty string if not set).

nlbda#

Number of spectral pixels (wavelength bins).

omega#

Spaxel solid angle, in steradians.

psf_sigma_spectral#

Chromatic PSF sigma at lbda_ref, in arcsec.

If not set (None or "default"), it is derived from the telescope Airy radius at lbda_ref.

skyarea#

Full sky area covered by the spaxels (not implemented, always None).

spaxel_extent#

Extent [-hx, hx, -hy, hy] of the spaxel grid, in spaxels.

spaxels#

Spaxel coordinates and properties (see build_pixels).

spx_area#

Area of a spaxel, in arcsec².

spx_centroids#

Spaxel (x, y) centroid coordinates, in spaxels.

spx_edges#

Spaxel (x, y) edge coordinates, in spaxels.

spx_shape#

Shape (ny, nx) of the spaxel grid.

spx_spatial_scale#

Spatial scale of a spaxel, in arcsec.

If not set, it is derived from the telescope Airy radius at lbda_ref.

type#

Type of the spectrograph (e.g. "slicer" or "mla").