Components

A “Component” in spexxy describes a component in a fit, which in general is a collection of parameters and a method to fetch data for a given set of parameter values. Typically, a component build on top of a Grid or an interpolator.

spexxy comes with a few pre-defined grids:

  • SpectrumComponent is the base class for all components that serve spectra.
  • StarComponent contains a single spectrum and adds LOSVD parameters.
  • GridComponent wraps a grid or an interpolator into a component and adds LOSVD parameters.
  • TelluricsComponent is just a convenient class derived from GridComponent <spexxy.component.GridComponent> that changes the default’s component name.

Component

class spexxy.component.Component(name: str, init: list = None, prefix: str = None, normalize: bool = False, *args, **kwargs)

Base class for all Components in spexxy.

__call__(**params) → Any

Model function, must be implemented.

Parameters:params – Parameters to retrieve model for
Returns:The model from the component
__getitem__(name: str) → float

Returns the value for an existing parameter.

Parameters:name – Name of parameter for which to return the value
Returns:Value of given parameter
Raises:KeyError – If given parameter does not exist
__init__(name: str, init: list = None, prefix: str = None, normalize: bool = False, *args, **kwargs)

Initialize a new component.

Parameters:
  • name – Name of component
  • init – List of Init objects for initializing the component
  • prefix – Prefix for parameter name when combined in other model. Automatically derived from name if None.
  • normalize – Whether or not to normalize parameters to 0..1 range
__setitem__(name: str, value: float)

Returns the value for an existing parameter.

Parameters:
  • name – Name of parameter to set
  • value – New value for parameter
denorm_param(name: str, value: float, stderr: float = None) -> (<class 'float'>, <class 'float'>)

De-Normalize the value of the parameter with the given name to its real value.

Parameters:
  • name – Name of parameter to de-normalize.
  • value – Value to normalize.
  • stderr – If given, standard deviation of value.
Returns:

Normalized value and its standard deviation, if given.

dtype

alias of numpy.float64

init(filename: str)

Calls all Init objects with the given filename in order to initialize this component.

Parameters:filename – File to initialize with, may be optional for some Init objects
make_params(**kwargs) → lmfit.parameter.Parameters

Creates a Parameters object with a Parameter for each parameter of this component.

Parameters:kwargs – Values to overwrite in parameters
Returns:List of Parameters for this component
norm_param(name: str, value: float) → float

Normalize the value of the parameter with the given name to 0..1 range defined by its min/max.

Parameters:
  • name – Name of parameter to normalize.
  • value – Value to normalize.
Returns:

Normalized value.

parse_params(params: lmfit.parameter.Parameters)

Loop all Parameters in a Parameters object and set the values of this component accordingly.

Parameters:params – Parameters objects, usually return from a lmfit optimization
set(name, **kwargs)

Adds a new parameter with the given name or changes values of an existing one.

Parameters:
  • name (str) – Parameter name.
  • value (float) – (Initial) Value of parameter
  • stderr (float) – Standard deviation after fit
  • vary (bool) – Whether or not to vary the parameter in the fit
  • min (float) – Lower bound for fit (default is -numpy.inf, no lower bound)
  • max (float) – Upper bound for value (default is numpy.inf, no upper bound)
  • kwargs – Passed to set_param_hint()
write_results_to_file(fits_file: spexxy.data.fitsspectrum.FitsSpectrum)

Write results of this component into a given SpectrumFile

Parameters:fits_file – Opened FitsSpectrum to write results into

SpectrumComponent

class spexxy.component.SpectrumComponent(name: str, losvd_hermite: bool = False, vac_to_air: bool = False, lsf: Union[spexxy.data.lsf.LSF, str, dict] = None, *args, **kwargs)

SpectrumComponent is the base Component class for all components that deal with spectra.

__call__(**kwargs)

Model function that creates a spectrum with the given parameters and shift/convolve it using the given LOSVD.

Parameters:kwargs – Values to overwrite
Returns:The model from the component
__init__(name: str, losvd_hermite: bool = False, vac_to_air: bool = False, lsf: Union[spexxy.data.lsf.LSF, str, dict] = None, *args, **kwargs)

Initializes a new SpectrumComponent.

Parameters:
  • name – Name of new component
  • losvd_hermite – Whether or not Hermite polynomials should be used for the LOSVD
  • vac_to_air – If True, vac_to_air() is called on spectra returned from the model_func
  • lsf – LSF to apply to spectrum

StarComponent

class spexxy.component.StarComponent(spec: Union[spexxy.data.spectrum.Spectrum, str], name: str = 'STAR', *args, **kwargs)
__init__(spec: Union[spexxy.data.spectrum.Spectrum, str], name: str = 'STAR', *args, **kwargs)

Initializes a new Star component that just serves a single given spectrum.

Parameters:
  • spec (SpectrumComponent | str) – A Spectrum object or the filename of a spectrum to load
  • name (str) – Name of new component

GridComponent

class spexxy.component.GridComponent(interpolator: spexxy.interpolator.interpolator.Interpolator, name: str = 'STAR', *args, **kwargs)

A Grid component takes an interpolator and adds LOSVD parameters.

__init__(interpolator: spexxy.interpolator.interpolator.Interpolator, name: str = 'STAR', *args, **kwargs)

Initializes a new Grid component.

Parameters:
  • interpolator (Interpolator) – The interpolator to use for the component
  • name (str) – Name of the component

TelluricsComponent

class spexxy.component.TelluricsComponent(interpolator: spexxy.interpolator.interpolator.Interpolator, name: str = 'TELLURICS', *args, **kwargs)

A Component for serving tellurics spectra from a given interpolator.

__init__(interpolator: spexxy.interpolator.interpolator.Interpolator, name: str = 'TELLURICS', *args, **kwargs)

Initializes a new Grid component.

Parameters:
  • interpolator (Interpolator) – The interpolator to use for the component
  • name (str) – Name of the component