Function

class gdt.core.spectra.functions.Function[source]

Bases: ABC

Abstract class for a 1-D function (e.g. photon model).

Sub-classes should be designed with the following requirements:

  1. Attribute nparams containing the total number of parameters of the function (even parameters that are fixed to a particular value during fitting)

  2. Method eval() that accepts two arguments: an array of parameter values of length nparams; and the array of abscissa values.

Subclasses can optionally add the following for complete and enhanced functionality:

  1. Attribute param_list that is a list of parameter names in the order they are accepted in the eval() method. Each entry in param_list is a tuple of the form (<param_name>, <units>, <description>). If no units or description are needed, those fields should be a null string ‘’. If omitted, these will be filled to default values (‘param0’, ‘’, ‘’), etc.

  2. Attribute default_values that is a list of default parameter values. This is primarily used for parameter estimation. Default is 1.0 for each parameter

  3. Attribute delta_abs that is a list of max absolute fitting step for each parameter. This is used for parameter estimation. Default is 0.1 for each parameter.

  4. Attribute delta_rel that is a list of max relative fitting step for each parameter. This is used for paramter estimation. Default is 0.01 for each parameter.

  5. Attribute min_values that is a list of minimum values each parameter can take. This is used primarily for parameter estimation. Default is -np.inf for each parameter.

  6. Attribute max_values that is a list of maximum values each parameter can take. This is used primarily for parameter estimation. Default is np.inf for each parameter.

  7. Attribute free that is a boolean list indicating if each parameter is allowed to be free for fitting. False indicates that the parameter will be fixed at its default value. This is used for parameter estimation. Default is True for each parameter.

Attributes Summary

default_values

The default parameter values.

delta_abs

The maximum absolute fitting step size for each parameter.

delta_rel

The maximum relative fitting step size for each parameter.

free

For each parameter, mark True if left free for fitting, otherwise mark False to fix at the default value.

max_values

The maximum possible value for each parameter.

min_values

The minimum possible value for each parameter.

name

The name of the function.

nparams

Number of parameters in the function.

num_components

Number of function components.

param_list

The list of parameters.

Methods Summary

add(func1, func2)

Add two Functions.

eval(params, x)

Evaluate the function.

fit_eval(params, x, **kwargs)

Evaluate the function for a fit.

integrate(params, erange[, num_points, log, ...])

Integrate the function over energy to produce a flux.

multiply(func1, func2)

Multiply two Functions.

parameter_bounds([apply_state])

The valid parameter bounds in the form [(min, max), ...]

Attributes Documentation

default_values: List[float] = None

The default parameter values. If not defined, each defaults to 1.0

delta_abs: List[float] = None

The maximum absolute fitting step size for each parameter. If not defined, each default to 0.1

delta_rel: List[float] = None

The maximum relative fitting step size for each parameter. If not defined, each default to 0.01

free: List[bool] = None

For each parameter, mark True if left free for fitting, otherwise mark False to fix at the default value. If not defined, each default to True.”””

max_values: List[float] = None

The maximum possible value for each parameter. If not defined, each default to np.inf

min_values: List[float] = None

The minimum possible value for each parameter. If not defined, each default to -np.inf

name: str = None

The name of the function.

nparams: int = None

Number of parameters in the function.

num_components

Number of function components. For a normal function this is one, for a SuperFunction, this can be > 1.

Type:

(int)

param_list: List[Tuple[str, str, str]] = None

The list of parameters. Each element is of form (parameter name, units, short description)

Methods Documentation

classmethod add(func1, func2)[source]

Add two Functions. Can also use the + operator.

Parameters:
  • func1 (Function) – A function

  • func2 (Function) – A function to add to func1.

Returns:

(SuperFunction)

abstract eval(params, x)[source]

Evaluate the function.

Parameters:
  • params (iterable) – The parameter vector of the free parameters

  • x (np.array) – The values at which to evaluate the function

Returns:

(np.array)

fit_eval(params, x, **kwargs)[source]

Evaluate the function for a fit. This differs from eval() because the params vector should only contain the free fit parameters. The parameters that are set to fixed will automatically be passed to eval() at their fixed value. This enables a fit to be performed with fixed parameters and the associated jacobian and covariance matrices will have the appropriate shape.

Parameters:
  • params (iterable) – The parameter vector of the free parameters

  • x (np.array) – The values at which to evaluate the function

Returns:

(np.array)

integrate(params, erange, num_points=1000, log=True, energy=False)[source]

Integrate the function over energy to produce a flux.

Parameters:
  • params (iterable) – The parameter vector, which can be of length nparams or equal to the length of the non-fixed (free) parameters.

  • erange (float, float) – The energy range over which to integrate

  • num_points (int, optional) – The number of points used for integration. Default is 1000.

  • log (bool, optional) – If True, the integration grid is made in log-space, otherwise it is linear. Default is True.

  • energy (bool, optional) – If True, perform integration of E*F(E) to produce an energy flux, otherwise integration is over F(E) to produce a photon flux. Default is False.

Returns:

(float)

classmethod multiply(func1, func2)[source]

Multiply two Functions. Can also use the * operator.

Parameters:
  • func1 (Function) – A function

  • func2 (Function) – A function to multiply to func1.

Returns:

(SuperFunction)

parameter_bounds(apply_state=True)[source]

The valid parameter bounds in the form [(min, max), …]

Parameters:

apply_state (bool, optional) – If True, will only return the bounds for free parameters. Default is True.

Returns:

([(float, float), …])