def estimate_lorentzian_dip(self, x_axis, data, params):
""" Provides an estimator to obtain initial values for lorentzian function.
@param numpy.array x_axis: 1D axis values
@param numpy.array data: 1D data, should have the same dimension as x_axis.
@param lmfit.Parameters params: object includes parameter dictionary which
can be set
@return tuple (error, params):
Explanation of the return parameter:
int error: error code (0:OK, -1:error)
Parameters object params: set parameters of initial values
"""
# check if parameters make sense
error = self._check_1D_input(x_axis=x_axis, data=data, params=params)
# check if input x-axis is ordered and increasing
sorted_indices = np.argsort(x_axis)
if not np.all(sorted_indices == np.arange(len(x_axis))):
x_axis = x_axis[sorted_indices]
data = data[sorted_indices]
data_smooth, offset = self.find_offset_parameter(x_axis, data)
# data_level = data-offset
data_level = data_smooth - offset
# calculate from the leveled data the amplitude:
amplitude = data_level.min()
smoothing_spline = 1 # must be 1<= smoothing_spline <= 5
function = InterpolatedUnivariateSpline(x_axis, data_level,
k=smoothing_spline)
numerical_integral = function.integral(x_axis[0], x_axis[-1])
x_zero = x_axis[np.argmin(data_smooth)]
# according to the derived formula, calculate sigma. The crucial part is
# here that the offset was estimated correctly, then the area under the
# curve is calculated correctly:
sigma = np.abs(numerical_integral / (np.pi * amplitude))
# auxiliary variables
stepsize = x_axis[1] - x_axis[0]
n_steps = len(x_axis)
params['amplitude'].set(value=amplitude, max=-1e-12)
params['sigma'].set(value=sigma, min=stepsize / 2,
max=(x_axis[-1] - x_axis[0]) * 10)
params['center'].set(value=x_zero, min=(x_axis[0]) - n_steps * stepsize,
max=(x_axis[-1]) + n_steps * stepsize)
params['offset'].set(value=offset)
return error, params
评论列表
文章目录