specex.lines module

SPEX - SPectra EXtractor.

Emission and absorption line dictionary

Copyright (C) 2022-2024 Maurizio D’Addona <mauritiusdadd@gmail.com>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class specex.lines.Emission1D(lines_identifications, sigma=3, redshift=0, **kwargs)[source]

Simple model for a flat spectrum with emission lines.

evaluate(lam, redshift)[source]

Evaluate the model.

Parameters

lamnp.ndarray

Array of wavelength.

redshiftfloat, optional

The redshift of the spectrum. The default value is 0.

Returns

resultnp.ndarray

The model values.

param_names = ('redshift',)

Names of the parameters that describe models of this type.

The parameters in this tuple are in the same order they should be passed in when initializing a model of a specific type. Some types of models, such as polynomial models, have a different number of parameters depending on some other property of the model, such as the degree.

When defining a custom model class the value of this attribute is automatically set by the ~astropy.modeling.Parameter attributes defined in the class body.

specex.lines.get_lines(name=None, line_type=None, wrange=None, z=0)[source]

Return line data according to the given line name and types.

Parameters

namestr or None, optional

The name of the line (eg. CaII_H or FeI, etc…). If None, the lines are selected only by type. If both name and type are None, all lines are returned.

line_typestr or None, optional

Type of the line, can be ‘A’ (absorption), ‘E’ (emission) ‘B’ (Broad). If None, then all the line types are returned. The default is None.

wrangetuple/list/np.ndarray of floats or None, optional

The wavelength ragne in which lines should be. If None, no selection according to the line wavelenght is made. The default is None.

zfloat, optional

The redshit of the lines. The default value is 0.

Returns

selected_lineslist

List of line data. Each element of the list is a 3-tuple in the form (wavelenght in Angstrom, Line name, Line type).

specex.lines.get_redshift_from_lines(identifications: tuple | list | array, z_max: float | None = 6, z_min: float | None = 0, z_points: float | None = None, tol: float | None = None)[source]

Get the redshift of a set of line identifications.

Parameters

identificationsUnion[tuple, list, np.array]

A list of identification generated by get_spectrum_lines().

z_maxOptional[float], optional

The maximum redshift. The default is 6.

z_minOptional[float], optional

The minimum redshift. The default is 0.

z_pointsOptional[Union[float, None]], optional

Number of redshift values between z_min and z_max to test. If None, then z_points = 1000*(z_max - z_min). The default is None.

tolOptional[float], optional

The tolerance. If None, it is computed automatically. The default is None.

Returns

z_values

Best estimations of the redshift sorted from the most probable to the least probable.

z_probs

Pseudo-probabilities of the redshift estimations (the higer the better)

specex.lines.get_spectrum_lines(wavelengths: ndarray, flux: ndarray, var: ndarray | None = None, sigma_threshold: float | None = 10.0, smoothing_window: int | None = 51, smoothing_order: int | None = 1, glob_smoothing: int | None = 3)[source]

Identify the position of clear emission or absorption lines.

Parameters

wavelengthsnp.ndarray

The wavelengs corresponding to each flux value.

fluxnumpy.ndarray

The spectrum itself.

varnumpy.ndarray, optional

The variance of the spectrum itself. The default value is None.

sigma_thresholdfloat, optional

The threshold to use for line identification. The default value is 5.0

smoothing_windowint, optional

Parameter to be passed to the smoothing function. The default value is 51.

smoothing_orderint, optional

Parameter to be passed to the smoothing function. The default value is 11.

glob_smoothingint, optional

Parameter used for line identification. The default value is 3

Returns

identificationslist

A list of tuple. Each tuple ha the form of (k, w, l, h) and contains the index k for the wavelenght w of the line, the approximate max width l of the line and a height h of the line. Note that l and h are not actual phisical quantities and should be used with caution when comparing to other values from a different spectrum.