OpticsThroughput#

class OpticsThroughput(curves, noptics=None, meta={})[source]#

Bases: object

Throughput of the optical elements.

This class handles the throughput of the different optical elements of the spectrograph. The throughput of each element is defined by a curve (throughput vs. wavelength) and a number of optics of that type.

Parameters:
  • curves (dict) – Dictionary of throughput curves for each optical element. The keys are the element names and the values are callables (e.g., interpolators) that return the throughput as a function of wavelength.

  • noptics (int or dict, optional) – Number of optics for each curve (the curve is raised to that power). If a dict, it must have the same keys as curves. If None, it is not set and must be in meta. Default is None.

  • meta (dict, optional) – Metadata dictionary. Default is {}.

Variables:

mutable_parameters (list of str) – List of mutable parameters.

Methods

from_config

Create an OpticsThroughput instance from a configuration dictionary.

from_curves

Create an OpticsThroughput instance from throughput arrays.

from_curvesdf

Create an OpticsThroughput instance from a pandas DataFrame.

from_filename

Create an OpticsThroughput instance from a data file.

get_element_throughput

Get the throughput of a single optical element.

get_throughput

Get the total throughput of the optical system.

show

Show the throughput of the optical system.

update

Update the number of optics for one or more elements.

update_curve

Replace the throughput curve of one optical element.

Attributes

curves

Throughput curve (callable of wavelength in Angstrom) per optical element.

meta

Metadata of the instance.

mutable_parameters

names

Names of the optical elements (dict keys view).

noptics

Number of optics per element (i.e., per curve).

classmethod from_config(config, **kwargs)[source]#

Create an OpticsThroughput instance from a configuration dictionary.

The configuration dictionary must contain a "throughput" key pointing to a file (csv or ecsv) with the throughput curves, see from_filename. An optional "noptics" key (default 1) sets the number of optics per curve. The full configuration is stored as meta.

Parameters:
Returns:

OpticsThroughput – An OpticsThroughput instance.

Raises:

ValueError – If config has no "throughput" entry.

classmethod from_curves(curves, noptics=1, lbda=None, names=None)[source]#

Create an OpticsThroughput instance from throughput arrays.

Parameters:
  • curves (array_like) – 2D array [curve_1, curve_2, ...] of shape (nelements, nlbda): one throughput curve per element, all sampled at lbda.

  • noptics (int or list of int, optional) – Number of optics for each curve. If a list, it must have one entry per curve. None means 1. Default is 1.

  • lbda (array_like, optional) – Wavelengths (in Angstrom) at which the curves are sampled, of shape (nlbda,). Default is None.

  • names (list of str, optional) – Name of each element. Default is None.

Returns:

OpticsThroughput – An OpticsThroughput instance.

Raises:

ValueError – If the number of names or noptics entries does not match the number of curves.

See also

from_curvesdf

Same, from a pandas.DataFrame.

classmethod from_curvesdf(curves, noptics=1, ext='zeros', **kwargs)[source]#

Create an OpticsThroughput instance from a pandas DataFrame.

Parameters:
  • curves (pandas.DataFrame) – DataFrame with wavelength (in Angstrom) as index and one column per optical element.

  • noptics (int, list of int or dict, optional) – Number of optics for each curve. If an int, the same number is applied to all elements. If a dict, it must have the same keys as the columns of curves. Default is 1.

  • ext (str, optional) – Extrapolation method of the interpolators (see chromatic_interpolator). Default is "zeros".

  • **kwargs – Additional arguments passed to the constructor (e.g. meta).

Returns:

OpticsThroughput – An OpticsThroughput instance.

classmethod from_filename(filename, noptics=1, meta={}, **kwargs)[source]#

Create an OpticsThroughput instance from a data file.

A csv file must have a wavelength column (in Angstrom, used as index) and one column per optical element. An ecsv file must have wavelength and throughput columns (single element named "spectro"). The curves are extrapolated outside the tabulated range.

Parameters:
  • filename (str) – Path of the throughput file (.ecsv or .csv). If it does not exist as given, it is looked for in the package configuration directory (see expand_path).

  • noptics (int or dict, optional) – Number of optics associated to each curve. Default is 1.

  • meta (dict, optional) – Metadata stored with the instance. Default is {}.

  • **kwargs – Additional arguments passed to pandas.read_csv (csv files only).

Returns:

OpticsThroughput – An OpticsThroughput instance.

get_element_throughput(which, lbda, incl_noptics=True)[source]#

Get the throughput of a single optical element.

Parameters:
  • which (str) – Name of the element.

  • lbda (array_like) – Wavelength array in Angstrom.

  • incl_noptics (bool, optional) – If True, the curve is raised to the power of the element number of optics. Default is True.

Returns:

numpy.ndarray – Throughput of the element.

Raises:

ValueError – If the stored curve is an array whose length does not match lbda.

get_throughput(lbda, which=None, per_element=False, incl_noptics=True, ignore=None)[source]#

Get the total throughput of the optical system.

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

  • which (str, optional) – If given, only return the throughput of this element (see get_element_throughput). Default is None.

  • per_element (bool, optional) – If True, return the throughput of each element separately. Ignored if which is given. Default is False.

  • incl_noptics (bool, optional) – If True, each curve is raised to the power of its number of optics. Default is True.

  • ignore (list of str, optional) – Element names to ignore. Not used if which is given. Default is None.

Returns:

numpy.ndarray or list of numpy.ndarray – Total throughput (product over the elements), or list of throughputs per element.

show(lbda, ax=None)[source]#

Show the throughput of the optical system.

This method plots the cumulative throughput of each element and the total throughput as a function of wavelength.

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

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

Returns:

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

update(**kwargs)[source]#

Update the number of optics for one or more elements.

Parameters:

**kwargs – Either noptics=value (replaces the whole noptics entry) or noptics.<name>=value to change the number of optics of a single element. The django-like format is accepted, e.g. noptics__mirror=2.

Warns:

UserWarning – If a key cannot be parsed, refers to an unknown element or is not mutable. It is then ignored.

update_curve(name, curve, ext='zeros')[source]#

Replace the throughput curve of one optical element.

Parameters:
  • name (str) – Name of the optical element whose curve is replaced. It must already be known (see names).

  • curve (pandas.Series) – New throughput curve, indexed by wavelength in Angstrom.

  • ext (str, optional) – How to extrapolate outside the tabulated wavelength range ("extrapolate", "zeros", "raise" or "const", see chromatic_interpolator). Default is "zeros".

Raises:

ValueError – If name is not one of the known curves.

Notes

This replaces the curve of an existing element, it cannot add a new one. The number of optics associated to name is left untouched, use update to change it.

curves#

Throughput curve (callable of wavelength in Angstrom) per optical element.

meta#

Metadata of the instance.

mutable_parameters = ['noptics']#
names#

Names of the optical elements (dict keys view).

noptics#

Number of optics per element (i.e., per curve).