Arrhenius

class Stoner.analysis.fitting.models.thermal.Arrhenius(*args, **kwargs)[source]

Bases: lmfit.model.Model

Arrhenius Equation without T dependendent prefactor.

Parameters
  • x (array) – temperatyre data in K

  • A (float) – Prefactor - temperature independent. See :py:func:modArrhenius for temperaure dependent version.

  • DE (float) – Energy barrier in eV.

Returns

Typically a rate corresponding to the given temperature values.

The Arrhenius function is defined as \(\tau=A\exp\left(\frac{-\Delta E}{k_B x}\right)\) where \(k_B\) is Boltzmann’s constant.

Example

"""Example of Arrhenius Fit."""
from numpy import linspace, ceil, log10, abs as np_abs
from numpy.random import normal

from Stoner import Data
from Stoner.analysis.fitting.models.thermal import Arrhenius, arrhenius

# Make some data
T = linspace(200, 350, 101)
R = arrhenius(T + normal(size=len(T), scale=3.0, loc=0.0), 1e6, 0.5)
E = 10 ** ceil(log10(np_abs(R - arrhenius(T, 1e6, 0.5))))
d = Data(T, R, E, setas="xye", column_headers=["T", "Rate"])

# Curve_fit on its own
d.curve_fit(arrhenius, p0=(1e6, 0.5), result=True, header="curve_fit")
d.setas = "xyey"
d.plot(fmt=["r.", "b-"])
d.annotate_fit(
    arrhenius,
    x=0.5,
    y=0.5,
    mode="eng",
    fontdict={"size": "x-small", "color": "blue"},
)

# lmfit using lmfit guesses
fit = Arrhenius()
d.setas = "xye"
d.lmfit(fit, result=True, header="lmfit")
d.setas = "x...y"
d.plot(fmt="g-")
d.annotate_fit(
    Arrhenius,
    x=0.5,
    y=0.35,
    prefix="Arrhenius",
    mode="eng",
    fontdict={"size": "x-small", "color": "green"},
)

d.setas = "xye"
res = d.odr(Arrhenius, result=True, header="odr", prefix="ODR")
d.setas = "x....y"
d.plot(fmt="m-")
d.annotate_fit(
    Arrhenius,
    x=0.5,
    y=0.2,
    prefix="ODR",
    mode="eng",
    fontdict={"size": "x-small", "color": "magenta"},
)


d.title = "Arrhenius Test Fit"
d.ylabel = "Rate"
d.xlabel = "Temperature (K)"
d.yscale = "log"

(png, hires.png, pdf)

../_images/arrhenius-class.png

Attributes Summary

components

Return components for composite model.

display_names

name

Return Model name.

param_names

Return the parameter names of the Model.

prefix

Return Model prefix.

valid_forms

Methods Summary

copy(**kwargs)

DOES NOT WORK.

dump(fp, **kws)

Dump serialization of Model to a file.

dumps(**kws)

Dump serialization of Model as a JSON string.

eval([params])

Evaluate the model with supplied parameters and keyword arguments.

eval_components([params])

Evaluate the model with the supplied parameters.

fit(data[, params, weights, method, ...])

Fit the model to the data using the supplied Parameters.

guess(data[, x])

Estimate fitting parameters from data.

load(fp[, funcdefs])

Load JSON representation of Model from a file-like object.

loads(s[, funcdefs])

Load Model from a JSON string.

make_funcargs([params, kwargs, strip])

Convert parameter values and keywords to function arguments.

make_params([verbose])

Create a Parameters object for a Model.

print_param_hints([colwidth])

Print a nicely aligned text-table of parameter hints.

set_param_hint(name, **kwargs)

Set hints to use when creating parameters with make_params().

Attributes Documentation

components

Return components for composite model.

display_names = ['A', '\\Delta E']
name

Return Model name.

param_names

Return the parameter names of the Model.

prefix

Return Model prefix.

valid_forms = ()

Methods Documentation

copy(**kwargs)

DOES NOT WORK.

dump(fp, **kws)

Dump serialization of Model to a file.

fpfile-like object

An open and .write()-supporting file-like object.

**kwsoptional

Keyword arguments that are passed to json.dumps.

int

Return value from fp.write(): the number of characters written.

dumps, load, json.dump

dumps(**kws)

Dump serialization of Model as a JSON string.

**kwsoptional

Keyword arguments that are passed to json.dumps.

str

JSON string representation of Model.

loads, json.dumps

eval(params=None, **kwargs)

Evaluate the model with supplied parameters and keyword arguments.

paramsParameters, optional

Parameters to use in Model.

**kwargsoptional

Additional keyword arguments to pass to model function.

numpy.ndarray, float, int or complex

Value of model given the parameters and other arguments.

1. if params is None, the values for all parameters are expected to be provided as keyword arguments. If params is given, and a keyword argument for a parameter value is also given, the keyword argument will be used.

2. all non-parameter arguments for the model function, including all the independent variables will need to be passed in using keyword arguments.

3. The return type depends on the model function. For many of the built-models it is a numpy.ndarray, with the exception of ConstantModel and ComplexConstantModel, which return a float/int or complex value.

eval_components(params=None, **kwargs)

Evaluate the model with the supplied parameters.

paramsParameters, optional

Parameters to use in Model.

**kwargsoptional

Additional keyword arguments to pass to model function.

dict

Keys are prefixes for component model, values are value of each component.

fit(data, params=None, weights=None, method='leastsq', iter_cb=None, scale_covar=True, verbose=False, fit_kws=None, nan_policy=None, calc_covar=True, max_nfev=None, **kwargs)

Fit the model to the data using the supplied Parameters.

dataarray_like

Array of data to be fit.

paramsParameters, optional

Parameters to use in fit (default is None).

weightsarray_like, optional

Weights to use for the calculation of the fit residual (default is None). Must have the same size as data.

methodstr, optional

Name of fitting method to use (default is ‘leastsq’).

iter_cbcallable, optional

Callback function to call at each iteration (default is None).

scale_covarbool, optional

Whether to automatically scale the covariance matrix when calculating uncertainties (default is True).

verbosebool, optional

Whether to print a message when a new parameter is added because of a hint (default is True).

fit_kwsdict, optional

Options to pass to the minimizer being used.

nan_policy{‘raise’, ‘propagate’, ‘omit’}, optional

What to do when encountering NaNs when fitting Model.

calc_covarbool, optional

Whether to calculate the covariance matrix (default is True) for solvers other than ‘leastsq’ and ‘least_squares’. Requires the numdifftools package to be installed.

max_nfevint or None, optional

Maximum number of function evaluations (default is None). The default value depends on the fitting method.

**kwargsoptional

Arguments to pass to the model function, possibly overriding parameters.

ModelResult

1. if params is None, the values for all parameters are expected to be provided as keyword arguments. If params is given, and a keyword argument for a parameter value is also given, the keyword argument will be used.

2. all non-parameter arguments for the model function, including all the independent variables will need to be passed in using keyword arguments.

3. Parameters (however passed in), are copied on input, so the original Parameter objects are unchanged, and the updated values are in the returned ModelResult.

Take t to be the independent variable and data to be the curve we will fit. Use keyword arguments to set initial guesses:

>>> result = my_model.fit(data, tau=5, N=3, t=t)

Or, for more control, pass a Parameters object.

>>> result = my_model.fit(data, params, t=t)

Keyword arguments override Parameters.

>>> result = my_model.fit(data, params, tau=5, t=t)
guess(data, x=None, **kwargs)[source]

Estimate fitting parameters from data.

load(fp, funcdefs=None, **kws)

Load JSON representation of Model from a file-like object.

fpfile-like object

An open and .read()-supporting file-like object.

funcdefsdict, optional

Dictionary of function definitions to use to construct Model.

**kwsoptional

Keyword arguments that are passed to loads.

Model

Model created from fp.

dump, loads, json.load

loads(s, funcdefs=None, **kws)

Load Model from a JSON string.

sstr

Input JSON string containing serialized Model.

funcdefsdict, optional

Dictionary of function definitions to use to construct Model.

**kwsoptional

Keyword arguments that are passed to json.loads.

Model

Model created from JSON string.

dump, dumps, load, json.loads

make_funcargs(params=None, kwargs=None, strip=True)

Convert parameter values and keywords to function arguments.

make_params(verbose=False, **kwargs)

Create a Parameters object for a Model.

verbosebool, optional

Whether to print out messages (default is False).

**kwargsoptional

Parameter names and initial values.

paramsParameters

Parameters object for the Model.

1. The parameters may or may not have decent initial values for each parameter.

2. This applies any default values or parameter hints that may have been set.

print_param_hints(colwidth=8)

Print a nicely aligned text-table of parameter hints.

colwidthint, optional

Width of each column, except for first and last columns.

set_param_hint(name, **kwargs)

Set hints to use when creating parameters with make_params().

This is especially convenient for setting initial values. The name can include the models prefix or not. The hint given can also include optional bounds and constraints (value, vary, min, max, expr), which will be used by make_params() when building default parameters.

namestr

Parameter name.

**kwargsoptional

Arbitrary keyword arguments, needs to be a Parameter attribute. Can be any of the following:

  • valuefloat, optional

    Numerical Parameter value.

  • varybool, optional

    Whether the Parameter is varied during a fit (default is True).

  • minfloat, optional

    Lower bound for value (default is -numpy.inf, no lower bound).

  • maxfloat, optional

    Upper bound for value (default is numpy.inf, no upper bound).

  • exprstr, optional

    Mathematical expression used to constrain the value during the fit.

>>> model = GaussianModel()
>>> model.set_param_hint('sigma', min=0)