spyctral
Spyctral.
Implementation of astronomical objects spectral analisys.
- class spyctral.SpectralPlotter(summary)[source]
A class for generating plots from spectral data provided by a ‘SpectralSummary’ object. It offers methods for visualizing one or multiple spectra in a customizable manner.
- _summary
An object containing the spectral data and additional information about the observed object.
- Type:
- all_spectra(ax=None, **kwargs)[source]
Plots all spectra stored in the ‘spectra’ attribute of the associated object. Each spectrum is represented on the same plot with a legend.
- Parameters:
ax (matplotlib.axes.Axes or None) – The axis where the spectra will be plotted. If None, the current axis (‘plt.gca()’) is used.
**kwargs – Additional parameters to customize the plot style (e.g., color, line type, etc.).
- Returns:
The axis containing the plot of all spectra.
- Return type:
matplotlib.axes.Axes
- single(spectrum_name, ax=None, **kwargs)[source]
Plots a single spectrum identified by its name. The spectrum is retrieved from the ‘spectra’ attribute and displayed on the specified axis.
- Parameters:
spectrum_name (str) – The name of the spectrum to be plotted.
ax (matplotlib.axes.Axes or None) – The axis where the spectrum will be plotted. If None, the current axis (‘plt.gca()’) is used.
**kwargs –
- Additional parameters to customize the plot style
(e.g., color, line type, etc.).
- Returns:
The axis containing the plot of the requested spectrum.
- Return type:
matplotlib.axes.Axes
- split(offset=0.1, ax=None, **kwargs)[source]
Plots multiple spectra, applying an incremental vertical offset to each spectrum (except for residual spectra) to facilitate comparative visualization.
- Parameters:
offset (float, optional) – The vertical offset applied between spectra. Default is 0.1.
ax (matplotlib.axes.Axes or None) – The axis where the spectra will be plotted. If None, the current axis (‘plt.gca()’) is used.
**kwargs – Additional parameters to customize the plot style (e.g., color, line type, etc.).
- Returns:
The axis containing the plotted offset spectra.
- Return type:
matplotlib.axes.Axes
Notes
This method is useful for highlighting differences between spectra by reducing overlapping curves.
- subplots(ax=None, **kwargs)[source]
Creates individual subplots for each spectrum, allowing separate visualization for each one. All subplots share the same x-axis (wavelength).
- Parameters:
ax (matplotlib.axes.Axes or None) – The set of axes where the spectra will be plotted. If None, new subplots are automatically created.
**kwargs –
- Additional parameters to customize the plot style
(e.g., color, line type, etc.).
- Returns:
An array of ‘Axes’ objects corresponding to the subplots.
- Return type:
numpy.ndarray
Notes
This method enables the individual analysis of each spectrum in separate plots, which is useful for examining specific details without overlapping others.
- class spyctral.SpectralSummary(obj_name, header, data, age, err_age, reddening, av_value, normalization_point, z_value, spectra, extra_info)[source]
Class that encapsulates all the data obtained from an input file.
- obj_name
Object name.
- Type:
str
- header
Header information from the input file.
- Type:
dict
- data
Spectra information in QTable format.
- Type:
dict
- age
Object’s age.
- Type:
float
- err_age
Error associated with the age.
- Type:
float
- reddening
Value of reddening
- Type:
float
- av_value
Extinction value.
- Type:
float
- normalization_point
Value of the normalization point.
- Type:
float
- z_value
Metallicity value.
- Type:
float
- spectra
Set of spectra extracted from the input file.
- Type:
dict
- extra_info
Additional information.
- Type:
dict
- property feh_ratio
Calculates the metallicity ratio [Fe/H] using the instance’s Z value and the solar constant (‘Z_SUN’).
- Returns:
Metallicity ratio [Fe/H].
- Return type:
float
- property get_all_properties: DataFrame
Creates a DataFrame containing all relevant parameters of the instance. Numerical values are formatted to display in scientific notation where necessary.
- Returns:
A DataFrame with two columns: “Property” and “Value”.
- Return type:
pandas.DataFrame
- get_spectrum(name: str)[source]
Retrieves a specific spectrum from the ‘spectra’ attribute.
- Parameters:
name (str) – The Name of the spectrum to retrieve.
- Returns:
The spectrum corresponding to the specified name.
- Return type:
Spectrum
- property header_info_df: DataFrame
Converts the information stored in the ‘header’ attribute into a pandas DataFrame.
- Returns:
A DataFrame containing the header information, where the header keys are the index and the values are stored in a column named “value”.
- Return type:
pandas.DataFrame
- property plot
Generates a ‘SpectralPlotter’ object for plotting the spectra stored in the instance. Uses the ‘SpectralPlotter’ class to handle plotting functionalities.
- Returns:
Object that enables generating plots of the spectra.
- Return type:
- spyctral.read_fisa(path_or_buffer, *, age_map=None, error_age_map=None, rv=3.1, z_map=None, object_name='object_1')[source]
Reads a FISA file and extracts the spectral data, including the header and data columns.
- Parameters:
path_or_buffer (str) – Path and name of the FISA file to read.
age_map (dict or None, optional) – Mapping dictionary for age values. If None, defaults to FISA_DEFAULT_AGE_MAP. (default: None)
rv (float, optional) – Reddening value to use for calculations. (default: 3.1)
z_map (dict or None, optional) – Mapping dictionary for metallicity values. If None, defaults to FISA_DEFAULT_Z_MAP. (default: None)
- Returns:
SpectralSummary – An object containing encapsulated data extracted from the FISA file.
dict – A dictionary with the following keys:
’header’ (list): Lines of the file’s header.
’data’ (ndarray): Spectral data in NumPy array format.
’reddening’ (float): Reddening value extracted from the header.
- ’template’ (str): Path of the template used, extracted from the
header.
- ’norm_point’* (float): Normalization point extracted from the
header.
Notes
Function that processes a FISA file, extracting header information and spectral blocks. It computes age, reddening, AV value, normalization point, and metallicity values based on the provided or default mappings.
- spyctral.read_starlight(path, *, xj_percent=5, age_decimals=2, rv=3.1, z_decimals=3, object_name='object_1')[source]
Processes a Starlight file, extracting the header, data tables, and key values such as age, metallicity, and reddening. Returns a spectral summary with all processed information.
- Parameters:
path (str) – Path to the Starlight file to process.
xj_percent (float, optional) – Minimum SSP contribution percentage to include in the calculation. Default: 5.
age_decimals (int, optional) – Number of decimals to round age calculations. Default: 2.
rv (float, optional) – Reddening parameter (R_v). Default: 3.1.
z_decimals (int, optional) – Number of decimal places to round metallicity calculations. Default: 3.
object_name (str, optional) – Name of the analyzed object. Default: “object_1”.
- Returns:
An object encapsulating the spectral summary, including:
Processed header.
Generated ‘Spectrum1D’ spectra.
Key values such as age, metallicity, and reddening.
Processed tables with results.
- Return type: