OpticsThroughput#
- class OpticsThroughput(curves, noptics=None, meta={})[source]#
Bases:
objectThroughput 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 (
intordict, optional) – Number of optics for each curve (the curve is raised to that power). If a dict, it must have the same keys ascurves. If None, it is not set and must be inmeta. Default is None.meta (
dict, optional) – Metadata dictionary. Default is{}.
- Variables:
mutable_parameters (
listofstr) – List of mutable parameters.
Methods
Create an OpticsThroughput instance from a configuration dictionary.
Create an OpticsThroughput instance from throughput arrays.
Create an OpticsThroughput instance from a pandas DataFrame.
Create an OpticsThroughput instance from a data file.
Get the throughput of a single optical element.
Get the total throughput of the optical system.
Show the throughput of the optical system.
Update the number of optics for one or more elements.
Replace the throughput curve of one optical element.
Attributes
Throughput curve (callable of wavelength in Angstrom) per optical element.
Metadata of the instance.
Names of the optical elements (dict keys view).
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, seefrom_filename. An optional"noptics"key (default 1) sets the number of optics per curve. The full configuration is stored asmeta.- Parameters:
config (
dict) – Configuration dictionary.**kwargs – Goes to
from_filename.
- Returns:
OpticsThroughput– An OpticsThroughput instance.- Raises:
ValueError – If
confighas 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 atlbda.noptics (
intorlistofint, 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 (
listofstr, optional) – Name of each element. Default is None.
- Returns:
OpticsThroughput– An OpticsThroughput instance.- Raises:
ValueError – If the number of
namesornopticsentries does not match the number of curves.
See also
from_curvesdfSame, 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,listofintordict, 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 ofcurves. Default is 1.ext (
str, optional) – Extrapolation method of the interpolators (seechromatic_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
wavelengthcolumn (in Angstrom, used as index) and one column per optical element. An ecsv file must havewavelengthandthroughputcolumns (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 (seeexpand_path).noptics (
intordict, 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 (seeget_element_throughput). Default is None.per_element (
bool, optional) – If True, return the throughput of each element separately. Ignored ifwhichis 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 (
listofstr, optional) – Element names to ignore. Not used ifwhichis given. Default is None.
- Returns:
numpy.ndarrayorlistofnumpy.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 wholenopticsentry) ornoptics.<name>=valueto 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 (seenames).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", seechromatic_interpolator). Default is"zeros".
- Raises:
ValueError – If
nameis 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
nameis left untouched, useupdateto 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).