Qudi
|
First of all it is important to mention that the naming convention of methods is very important! Only if the methods are named right the automated import works properly!
General procedure to create new fitting routines:
A fitting routine consists of three major parts:
make_<custom>_model()
estimate_<custom>()
make_<custom>_fit()
The power of that general splitting is that you can write pretty independent fit algorithms, but their efficiency will (very often) rely on the quality of the estimator.
make_<custom>_fit()
it is important to have no extra underscores, and that it starts with make_
and ends with _fit
. In order to distinguish between oneD and twoD models, every twoD model has to include the string twoD e.g. def make_gaussian_fit() and def make_twoDgaussian_fit()
estimate_<custom>()
e.g. estimate_gaussian()
if you only have one estimator, if there are different estimators estimate_<custom>_<estimator name>
. it is important to have no extra underscores, and that it starts with estimate_
, e.g. def estimate_gaussian_dip() and def estimate_gaussian_peak()
make_<custom>_model()
, if one wants to construct the model from a custom (not built-in) function one can do that within the make_<custom>_model()
` method e.g. def make_sinewithoutoffset_model(self): """ This method creates a model of sine. @return tuple: (object model, object params) """ def sine_function(x, amplitude, frequency,phase): """ Function of a sine. @param x: variable variable - e.g. time @param amplitude: amplitude @param frequency: frequency @param phase: phase @return: sine function: in order to use it as a model """ return amplitude*np.sin(2*np.pi*frequency*x+phase) model = Model(sine_function, prefix='s0') params = model.make_params() return model, params
Useful methods usable from the model are:
model.eval(x=x_axis, parameters)
or
linear_model.eval(x=np.linspace(0,10,100), slope=2., offset=10.)
One can retrieve the independent and variable variables from a model with:
model.param_names and model.independent_vars
More information here: https://lmfit.github.io/lmfit-py/model.html
In the object returned from the fit method many parameters are saved. Some useful values are listed here:
result.fit_report()
result.best_fit
result.init_fit
result.best_values
result.init_values
result.message
result.success
More information at https://lmfit.github.io/lmfit-py/model.html
The parameter object can be created from a model:
parameters = model.make_param()
It is also given back from the make_<custom>_model()
method:
model, parameters = make_<custom>_model()
Useful methods of the Parameters class are:
#(Name, Value, Vary, Min, Max, Expr) params.add_many(('amplitude', amplitude, True, 100, 1e7, None), ( 'sigma_x', sigma_x, True, 1*(stepsize_x) , 3*(x_axis[-1]-x_axis[0]), None), ( 'sigma_y', sigma_y, True, 1*(stepsize_y) , 3*(y_axis[-1]-y_axis[0]) , None), ( 'x_zero', x_zero, True, (x_axis[0])-n_steps_x*stepsize_x , x_axis[-1]+n_steps_x*stepsize_x, None), ( 'y_zero', y_zero, True, (y_axis[0])-n_steps_y*stepsize_y , (y_axis[-1])+n_steps_y*stepsize_y, None), ( 'theta', 0., True, 0. , np.pi, None), ( 'offset', offset, True, 0, 1e7, None))
Single changes can be set in the following way:
params['amplitude'].min = 0.0 params['amplitude'].max = 10.0 params['lorentz1'].expr='lorentz0_center+2.15' params['amplitude'].vary = True params['amplitude'].value = 0.12
See very detailed description: https://lmfit.github.io/lmfit-py/parameters.html
_search_double_dip()
_search_end_of_dip()
find_offset_parameter()
gaussian_smoothing()
This list can be read out in the manager console:
fitlogic.oneD_fit_methods and fitlogic.twoD_fit_methods