Exemplo n.º 1
0
def nonlinear_fit():
    global Plot1
    global Plot2
    ds = Plot1.ds
    if len(ds) == 0:
        print 'Error: no curve to fit in Plot2'
        return
    for d in ds:
        if d.title == 'nonlinear_fitting':
            Plot1.remove_dataset(d)
    d0 = ds[0]
    d1 = d0 / 180 * math.pi
    axis = d1.axes[0].__copy__()
    axis[:] = (3.5238 * 3.5238 / axis).sqrt() * 2
    d1.set_axes([axis])
    Plot2.set_dataset(d1)
    function = '2*asin(k1/x[0])+k2'
    fitting = UndefinedFitting(function, 'Energy')
    fitting.set_histogram(d1)
    m = 1.67e-27
    h = 6.63e-34
    eV = 1.6e-19
    pl = 1.0e10
    l = h * pl * 100 / math.sqrt(linear_slope.value * eV * 20 * m)
    fitting.set_param('k1', l)
    fitting.set_param('k2', 0)
    res = fitting.fit()
    res.var[:] = 0
    res.title = 'nonlinear_fitting'
    Plot2.add_dataset(res)
    lambda_fit.value = fitting.k1
    two_theta_off.value = fitting.k2 * 180 / math.pi
    print 'lambda = ' + str(fitting.k1)
    print 'meV = ' + str((h * pl / fitting.k1 / m) ** 2 * m * 500 / eV)
    print 'two-theta_offset = ' + str(fitting.k2 * 180 / math.pi)
def nonlinear_fit():
    global Plot3
    ds3 = Dataset(peaks * -1, axes=[twod])
    Plot3.set_dataset(ds3)
    ds = Plot3.ds
    if len(ds) == 0:
        slog('Error: no curve to fit in Plot3')
        return
    for d in ds:
        if d.title == 'nonlinear_fit':
            Plot3.remove_dataset(d)
    d3 = ds[0]
    cur = d3 * math.pi / 180
    function = '2*asin(k1/x[0])+k2'
    fitting = UndefinedFitting(function, 'Energy')
    fitting.set_histogram(cur)
    m = 1.67492861e-027
    h = 6.626068e-034
    eV = 1.60217646e-019
    pl = 1.0e10
    l = h * pl * 100 / math.sqrt(linear_slope.value * eV * 20 * m)
    if lambda_fit.value == 0 and two_theta_off.value == 0:
        fitting.set_param('k1', l)
        fitting.set_param('k2', 0)
    else:
        fitting.set_param('k1', lambda_fit.value)
#        fitting.set_param('k2', two_theta_off.value)
    fitting.fitter.setResolutionMultiple(10)
#    fitting.fitter.getRawFitter().fitParameterSettings("k1").setStepSize(0.00001);
#    fitting.fitter.getRawFitter().fitParameterSettings("k2").setStepSize(0.00001);
    for i in xrange(5):
        res = fitting.fit()
        lambda_fit.value = fitting.k1
        two_theta_off.value = fitting.k2 * 180 / math.pi
        fit_quality.value = fitting.fitter.getQuality()
        fitting = UndefinedFitting(function, 'Energy')
        fitting.set_histogram(cur)
        fitting.set_param('k1', lambda_fit.value)
    res.var[:] = 0
    res.title = 'nonlinear_fit'
    res = res * 180 / math.pi
    Plot3.add_dataset(res)
    m1_new.value = math.asin(lambda_fit.value / 2 / PG002d) * 180 / math.pi
    m2_new.value = 2 * m1_new.value
    slog('Chi2 = ' + str(fit_quality.value))
    slog('lambda = ' + str(lambda_fit.value))
    slog('meV = ' + str((h * pl / lambda_fit.value / m) ** 2 * m * 500 / eV))
    slog('two-theta_offset = ' + str(two_theta_off.value * 180 / math.pi))
Exemplo n.º 3
0
def nonlinear_fit():
    global Plot2
    ds = Plot2.ds
    if len(ds) == 0:
        print 'Error: no curve to fit in Plot2'
        return
    for d in ds:
        if d.title == 'fitting':
            Plot2.remove_dataset(d)
    d0 = ds[0]
    function = '2*asin(k1/x[0])+k2'
    fitting = UndefinedFitting(function, 'Energy')
    fitting.set_histogram(d0)
    res = fitting.fit()
    res.var[:] = 0
    res.title = 'fitting'
    Plot2.add_dataset(res)
    print fitting.params
Exemplo n.º 4
0
def nonlinear_fit():
    global Plot3
    valid = []
    vaxes = []
    for i in xrange(peak_res.size):
        if not Double.isNaN(peak_res[i]):
            valid.append(peak_res[i] * -1)
            vaxes.append(twod[i])
    if len(valid) == 0:
        slog('Error: there is not any available peak.')
        return
    ds3 = Dataset(valid, axes=[vaxes])
    Plot3.set_dataset(ds3)
    ds = Plot3.ds
    if len(ds) == 0:
        print 'Error: no curve to fit in Plot3'
        return
    for d in ds:
        if d.title == 'nonlinear_fit':
            Plot3.remove_dataset(d)
    d3 = ds[0]
    cur = d3 * math.pi / 180
    function = '2*asin(k1/x[0])+k2'
    fitting = UndefinedFitting(function, 'Energy')
    fitting.set_histogram(cur)
    m = 1.67492861e-027
    h = 6.626068e-034
    eV = 1.60217646e-019
    pl = 1.0e10
    l = h * pl * 100 / math.sqrt(linear_slope.value * eV * 20 * m)
#    if lambda_fit.value == 0 and s2_offset.value == 0:
#        fitting.set_param('k1', 0)
##        fitting.set_param('k2', 0)
#    else:
#        fitting.set_param('k1', lambda_fit.value)
#        fitting.set_param('k2', s2_offset.value)
    try:
        v_lmd = lmd.value
    except:
        v_lmd = 0
    fitting.set_param('k1', v_lmd)
    fitting.set_param('k2', 0)
    fitting.fitter.setResolutionMultiple(10)
#    fitting.fitter.getRawFitter().fitParameterSettings("k1").setStepSize(0.00001);
#    fitting.fitter.getRawFitter().fitParameterSettings("k2").setStepSize(0.00001);
    for i in xrange(5):
        res = fitting.fit()
        lambda_fit.value = fitting.k1
        s2_offset.value = fitting.k2 * 180 / math.pi
        fit_quality.value = fitting.fitter.getQuality()
        fitting = UndefinedFitting(function, 'Energy')
        fitting.set_histogram(cur)
        fitting.set_param('k1', lambda_fit.value)
    res.var[:] = 0
    res.title = 'nonlinear_fit'
    res = res * 180 / math.pi
    Plot3.add_dataset(res)
#    lambda_fit.value = fitting.k1
#    s2_offset.value = fitting.k2 * 180 / math.pi
#    fit_quality.value = fitting.fitter.getQuality()
    m1_new.value = math.asin(lambda_fit.value / 2 / D_space) * 180 / math.pi
    m2_new.value = 2 * m1_new.value
    slog('Chi2 = ' + str(fit_quality.value))
    slog('lambda = ' + str(lambda_fit.value))
    slog('meV = ' + str((h * pl / lambda_fit.value / m) ** 2 * m * 500 / eV))
    slog('two-theta_offset = ' + str(s2_offset.value))