the lmfitdata class

This is a child class of nddata used for fitting.

For old fitdata documentation (obsolete, for development reference) see fitdata_old

creating new types of lmfitdata modules

There is a base class called “lmfitdata” that defines the basic routines necessary for fitting. Currently, the lmfitdata class only supports fitting along one dimension, so before constructing a new class, one must first choose what dimension they will be fitting along.

Todo

Of course, for multidimensional data, the fit will be repeated along the dimensions that are not the fit dimension. see how easy it would be to allow more than one dimension

To fit a new type of function, one simply creates a new type of class that inherits from the lmfitdata class. We override all the methods that have to do with the definition of the functional format. These are defined in the first section, where we build up an example for fitting a general \(T_1\) recovery curve. This example should be used as a starting point for making new fit classes. Then, we can make instances of the new class, and use their methods (described in the subsequent section) next.

Todo

the option block :no-inherited-members: doesn’t work – not sure how to modify class.rst I put a template from stackexchange inside _templates – see https://stackoverflow.com/questions/28147432/how-to-customize-sphinx-ext-autosummary-rst-template on how to use it

then, I need to link to or include generated/pyspecdata.lmfitdata.rst

class pyspecdata.lmfitdata.lmfitdata(*args, **kwargs)

Inherits from an nddata and enables curve fitting through use of a sympy expression.

The user creates a lmfitdata class object from an existing nddata class object, and on this lmfitdata object can define the functional_form() of the curve it would like to fit to the data of the original nddata. This functional form must be provided as a sympy expression, with one of its variables matching the name of the dimension that the user would like to fit to.

copy()

Return a full copy of this instance.

Because methods typically change the data in place, you might want to use this frequently.

Parameters:

data (boolean) –

Default to True. False doesn’t copy the data – this is for internal use, e.g. when you want to copy all the metadata and perform a calculation on the data.

The code for this also provides the definitive list of the nddata metadata.

eval(taxis=None)

Calculate the fit function along the axis taxis.

Parameters:

taxis (ndarray, int) –

if ndarray:

the new axis coordinates along which we want to calculate the fit.

if int:

number of evenly spaced points along the t-axis along the fit

Returns:

self – the fit function evaluated along the axis coordinates that were passed

Return type:

nddata

fit()

actually run the fit

property function_string

A property of the myfitclass class which stores a string output of the functional form of the desired fit expression provided in func:functional_form in LaTeX format

property functional_form

A property of the myfitclass class which is set by the user, takes as input a sympy expression of the desired fit expression

gen_indices(this_set, set_to)

pass this this_set and this_set_to parameters, and it will return: indices,values,mask indices –> gives the indices that are forced values –> the values they are forced to mask –> p[mask] are actually active in the fit

guess()

Old code that we are preserving here – provide the guess for our parameters; by default, based on pseudoinverse

latex()

show the latex string for the function, with all the symbols substituted by their values

output(*name)

give the fit value of a particular symbol, or a dictionary of all values.

Parameters:

name (str (optional)) – name of the symbol. If no name is passed, then output returns a dictionary of the resulting values.

Returns:

retval – Either a dictionary of all the values, or the value itself

Return type:

dict or float

residual(pars, x, y, sigma=None)

calculate the residual OR if data is None, return fake data

set_guess(*args, **kwargs)

set both the guess and the bounds

Parameters:

guesses (dict of dicts) –

each dict has a keyword giving the parameter and a value that comprises a dict with guesses (value) and/or constraints (min/max)

Can be passed either as the only argument, or a kwarg called guesses, or as the kwargs themselves.

settoguess()

a debugging function, to easily plot the initial guess