Package ComboCode :: Package cc :: Package tools :: Package numerical :: Module Interpol
[hide private]
[frames] | no frames]

Module Interpol

source code

Tools for inter- and extrapolation.

Author: R. Lombaert

Functions [hide private]
array
getResiduals(p, x, y, func='power')
Calculate residuals between function evaluation and given y-values.
source code
array
pEval(x, p, func='power', x_unit=None)
Evaluate a function prescription.
source code
list/array
fitFunction(x_in, y_in, x_out, show=0, func='linear', initial=[1, 0, 0.5, -1.5], maxfev=20000)
Fit a template function to input data.
source code
float/array
linInterpol(x_in, y_in, x)
Linear interpolation between two points.
source code
Variables [hide private]
  __package__ = 'ComboCode.cc.tools.numerical'
Function Details [hide private]

getResiduals(p, x, y, func='power')

source code 

Calculate residuals between function evaluation and given y-values.

Parameters:
  • p (list) - parameters for function evaluation
  • x (array) - the x-grid evaluated by function
  • y (array) - The given y-values
  • func (string) - type of function f(x), can be ['power','exp','power10', 'square','linear'] for now.

    (default: 'power')

Returns: array
residuals as a function of the x-grid

pEval(x, p, func='power', x_unit=None)

source code 

Evaluate a function prescription.

Parameters:
  • x (array) - The x-grid for function evaluation
  • p (list) - parameters for function evaluation
  • func (string) - type of function f(x), can be ['power','exp','power10', 'square','linear'] for now.

    (default: 'power')

  • x_unit (string) - the unit of the x array, only relevant if func=='planck'. Units other than micron not yet available.

    (default: None)

Returns: array
f(x)

fitFunction(x_in, y_in, x_out, show=0, func='linear', initial=[1, 0, 0.5, -1.5], maxfev=20000)

source code 

Fit a template function to input data.

Parameters:
  • x_in (list/array) - The input x values
  • y_in (list/array) - The input y values
  • x_out (list/array) - The output x grid
  • show (bool) - show the fit result

    (default: 0)

  • func (string) - The function template (see pEval)

    (default: 'linear')

  • initial (list(float)) - initialisation parameters for your function, number of parameters depends on type of function (see pEval)

    (default: [1,0,0.5,-1.5])

  • maxfev - Maximum number of calls to the function for the leastsq method. Zero means (1+number of elements in x_in)*100

    (default: 20000)

Returns: list/array
The output y values

linInterpol(x_in, y_in, x)

source code 

Linear interpolation between two points.

Parameters:
  • x_in (list) - 2 x-points for interpolation
  • y_in (list) - 2 y-points for interpolation corresponding to x_in
  • x (float/array) - x value for interpolation
Returns: float/array
f(x), where f is linear interpolation from x_in and y_in