the fitdata 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 fitdata modules

There is a base class called “fitdata” that defines the basic routines necessary for fitting. Currently, the fitdata 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 fitdata 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.

class pyspecdata.core.fitdata(*args, **kwargs)

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

The user creates a fitdata class object from an existing nddata class object, and on this fitdata 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. The user provides fit coefficients using fit_coeff() and obtains output using fit() and eval().

If you haven’t done this before, create a jupyter notebook (not checked in, just for your own playing around) with: ` import sympy as s s.init_printing() ` you can then use s.symbols( to create symbols/variables that allow you to build the mathematical expression for your fitting function

analytical_covariance()

Not up to date

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.

covar(*names)

give the covariance for the different symbols

eval(taxis, set_what=None, set_to=None)

after we have fit, evaluate the fit function along the axis taxis set_what and set_to allow you to forcibly set_what a specific symbol to a specific value –> however, this does not affect the class, but only the return value

fit(set_what=None, set_to=None, force_analytical=False)

actually run the fit

fitfunc(p, x)

this wraps fitfunc_raw (which gives the actual form of the fit function) to take care of forced variables

function_string

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

functional_form

A property of the fitdata 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(use_pseudoinverse=False)

old code that I am 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

linear(*args, **kwargs)

return the linear-form function, either smoothly along the fit function, or on the raw data, depending on whether or not the taxis argument is given can take optional arguments and pass them on to eval

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
parameter_derivatives(xvals, set=None, set_to=None)

return a matrix containing derivatives of the parameters, can set dict set, or keys set, vals set_to

residual(p, x, y, sigma)

just the error function

settoguess()

a debugging function, to easily plot the initial guess