Main routines

Main routines are the heart of spexxy, describing a specific process that should be run on the data.

There is one pre-defined main routine in spexxy:

  • ParamsFit takes one or more spectrum components and finds the best parameter combination to match a given spectrum.

MainRoutine

class spexxy.main.MainRoutine(*args, **kwargs)

MainRoutine is the base class for all main routines.

__call__()

Start the routine.

__init__(*args, **kwargs)

Initialize a new MainRoutine object

FilesRoutine

class spexxy.main.FilesRoutine(*args, **kwargs)

FilesRoutine is the base class for all routines fitting files.

__call__(filename: str) → List[float]

Start the routine on the given file.

Parameters:filename – Name of file to process.
Returns:List of final values of parameters, ordered in the same way as the return value of parameters()
__init__(*args, **kwargs)

Initialize a new MainRoutine object

columns() → List[str]

Get list of columns returned by __call__.

The returned list shoud include the list from parameters().

Returns:List of columns returned by __call__.
parameters() → List[str]

Get list of parameters fitted by this routine.

Returns:List of parameter names (including prefix) fitted by this routine.

ParamsFit

class spexxy.main.ParamsFit(components: List[spexxy.component.component.Component] = None, tellurics: spexxy.component.component.Component = None, masks: List[spexxy.mask.mask.Mask] = None, weights: List[spexxy.weight.weight.Weight] = None, fixparams: List[str] = None, poly_degree: int = 40, maxfev: int = 500, ftol: float = 1.49012e-08, xtol: float = 1.49012e-08, factor: float = 100.0, epsfcn: float = 1e-07, min_valid_pixels: float = 0.5, plot_iterations: bool = False, *args, **kwargs)

ParamsFit is a fitting routine for spexxy that uses a Levenberg-Marquardt optimization to fit a set of model spectra (components) to a given spectrum.

__call__(filename: str) → List[float]

Start the fitting procedure on the given file.

Parameters:filename – Name of file to fit.
Returns:List of final values of parameters, ordered in the same way as the return value of parameters()
__init__(components: List[spexxy.component.component.Component] = None, tellurics: spexxy.component.component.Component = None, masks: List[spexxy.mask.mask.Mask] = None, weights: List[spexxy.weight.weight.Weight] = None, fixparams: List[str] = None, poly_degree: int = 40, maxfev: int = 500, ftol: float = 1.49012e-08, xtol: float = 1.49012e-08, factor: float = 100.0, epsfcn: float = 1e-07, min_valid_pixels: float = 0.5, plot_iterations: bool = False, *args, **kwargs)

Initialize a new ParamsFit object

Parameters:
  • components – List of components (or descriptions to create them) to fit to the spectrum
  • tellurics – Tellurics component to add to the fit.
  • masks – List of mask objects to use for masking the spectrum.
  • weights – List of weight objects to use for creating weights for the spectrum.
  • fixparams – List of names of parameters to fix during the fit.
  • poly_degree – Number of coefficients for the multiplicative polynomial.
  • maxfev – The maximum number of calls to the function (see scipy documentation).
  • ftol – Relative error desired in the sum of squares (see scipy documentation).
  • xtol – Relative error desired in the approximate solution (see scipy documentation).
  • factor – A parameter determining the initial step bound (factor * || diag * x||) (see scipy documentation).
  • epsfcn – A variable used in determining a suitable step length for the forward- difference approximation of the Jacobian (see scipy documentation)
  • min_valid_pixels – Fraction of minimum number of required pixels to continue with fit.
  • plot_iterations – Plot all iterations into a PDF file.
columns() → List[str]

Get list of columns returned by __call__.

The returned list shoud include the list from parameters().

Returns:List of columns returned by __call__.
components

Returns all components used in this fit.

Returns:List of all components.
fit_parameters() → List[str]

Get list of parameters fitted by this routine. Exclude fixed parameters.

Returns:List of parameter names (including prefix) fitted by this routine.
parameters() → List[str]

Get list of parameters fitted by this routine.

Returns:List of parameter names (including prefix) fitted by this routine.

MultiMain

class spexxy.main.MultiMain(routines: List[T] = None, iterations: int = None, max_iterations: int = 8, threshold: Dict[str, float] = None, poly_degree: int = 40, damped: bool = True, factors: list = (0.7, 0.3), *args, **kwargs)

MultiRun iterates over a given set of main routines and runs them sequentially.

__call__(filename: str) → List[float]

Process the given file.

Parameters:filename – Name of file to process.
Returns:List of final values of parameters, ordered in the same way as the return value of parameters()
__init__(routines: List[T] = None, iterations: int = None, max_iterations: int = 8, threshold: Dict[str, float] = None, poly_degree: int = 40, damped: bool = True, factors: list = (0.7, 0.3), *args, **kwargs)

Initialize a new MultiMain object

Parameters:
  • routines – List of main routines to run.
  • iterations – Number of iterations for the whole cycle.
  • max_iterations – If set to a value >=2, the fit runs until it converges or until the number of iterations reaches max_iterations.
  • threshold – Dictionary that contains the absolute values for each fit parameter below which the fit is considered as converged.
  • poly_degree – Degree of Legendre polynomial used for the continuum fit.
  • damped – If True the fit is repeated with a damping factor in case the fit does not converge.
  • factors – List of damping factors used if the fit does not converge.
columns() → List[str]

Get list of columns returned by __call__.

The returned list should include the list from parameters().

Returns:List of columns returned by __call__.
convergence(results)

Returns true if the fit satisfies the convergence criteria for all fit parameters.

parameters() → List[str]

Get list of parameters fitted by this routine.

Returns:List of parameter names (including prefix) fitted by this routine.