当前位置: 首页>>代码示例>>Python>>正文


Python Fitter.saveData方法代码示例

本文整理汇总了Python中fitter.Fitter.saveData方法的典型用法代码示例。如果您正苦于以下问题:Python Fitter.saveData方法的具体用法?Python Fitter.saveData怎么用?Python Fitter.saveData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fitter.Fitter的用法示例。


在下文中一共展示了Fitter.saveData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: makeSigmaFit

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def makeSigmaFit(darkTimes, sigmas):
    dt, sdt = list(zip(*darkTimes))
    s, ss = list(zip(*sigmas))
    data = DataErrors.fromLists(dt, s, sdt, ss)

    c = TCanvas('c_sigma', '', 1280, 720)
    g = data.makeGraph('g_sigma', 'Dunkelzeit t_{D} / ms', 'Verschmierung #sigma / #mus')
    g.Draw('APX')

    fit = Fitter('fit_sigma', 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 0, 25)
    fit.saveData('../fit/sigma.txt')

    l = TLegend(0.6, 0.15, 0.85, 0.5)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Verschmierung #sigma', 'p')
    l.AddEntry(None, 'der Fermi-Verteilung', '')
    l.AddEntry(fit.function, 'Fit mit #sigma(t_{D}) = a + b t_{D}', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f')), chisquareformat='%.2f', units=['#mus', '10^{-3}'])
    l.Draw()

    g.Draw('P')
    c.Print('../img/part6/sigmaFit.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP2,代码行数:27,代码来源:part6.py

示例2: makeBFit

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def makeBFit(darkTimes, Bs):
    dt, sdt = list(zip(*darkTimes))
    b, sb = list(zip(*Bs))
    data = DataErrors.fromLists(dt, b, sdt, sb)

    c = TCanvas('c_B', '', 1280, 720)
    g = data.makeGraph('g_B', 'Dunkelzeit t_{D} / ms', 'Fitparameter B / V')
    g.Draw('APX')

    fit = Fitter('fit_B', '[0] + [1] * (1 - exp(-x/[2]))')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 0.1)
    fit.setParam(1, 'b', 0.1)
    fit.setParam(2, 'T_{R_{F}}', 6)
    fit.fit(g, 0, 25)
    fit.saveData('../fit/B.txt')

    l = TLegend(0.55, 0.15, 0.85, 0.6)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Fitparameter B', 'p')
    l.AddEntry(fit.function, 'Fit mit B(t_{D}) = a + b (1 - e^{-x/T_{R_{F}}})', 'l')
    fit.addParamsToLegend(l, (('%.3f', '%.3f'), ('%.3f', '%.3f'), ('%.1f', '%.1f')), chisquareformat='%.2f', units=['V', 'V', 'ms'])
    l.Draw()

    g.Draw('P')
    c.Print('../img/part6/BFit.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP2,代码行数:28,代码来源:part6.py

示例3: fitLambda

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def fitLambda():
    data = Data()
    data.addPoint(500, 1.000279)
    data.addPoint(540, 1.000278)
    data.addPoint(600, 1.000277)
    data.addPoint(682, 1.000276)

    c = TCanvas('c1', '', 1280, 720)
    g = data.makeGraph('g', 'wavelength #lambda / nm', 'refraction index n')
    g.GetYaxis().SetLabelSize(0.03)
    g.GetYaxis().SetTitleOffset(1.39)
    g.Draw('AP')

    fit = Fitter('f', '[0]+[1]*x')
    fit.setParam(0, 'a', 2)
    fit.setParam(1, 'b', -1)
    fit.fit(g, 450, 700)
    fit.saveData('../calc/fit_lambda.txt', 'w')

    a = fit.params[0]['value']
    sa = fit.params[0]['error']
    b = fit.params[1]['value']
    sb = fit.params[1]['error']

    l = TLegend(0.4, 0.6, 0.87, 0.87)
    l.AddEntry('g', 'refraction index n as a function of wavelength #lambda', 'p')
    l.AddEntry(fit.function, 'fit with n(#lambda)= a+b*#lambda', 'l')
    fit.addParamsToLegend(l)
    l.SetTextSize(0.03)
    l.Draw()

    c.Update()
    c.Print('../img/fit_lambda.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:35,代码来源:fit_lambda.py

示例4: main

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def main():
    z, sz = 840, 40
    d = [210, 106, 75]
    sd = [10, 4, 4]
    calc = list(map(lambda x:-20 * log10(x/z), d))
    scalc = list(map(lambda x:20 * sqrt((x[1]/x[0]) ** 2 + (sz/z)**2) / log(10), zip(*[d, sd])))
    
    data = DataErrors.fromLists(calc, [12, 18, 21], scalc, [0]*3)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'measured attenuation m / dB', 'nominal value n / dB')
    g.Draw('AP')
    
    fit = Fitter('fit', 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 11, 22)
    fit.saveData('../fit/attenuator.txt')
    
    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'measured att. vs. nominal value', 'p')
    l.AddEntry(fit.function, 'fit with n = a + b m', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f')), chisquareformat='%.4f', units=['dB', ''], lang='en')
    l.Draw()
    
    c.Update()
    c.Print('../img/attenuator.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP2,代码行数:29,代码来源:evalAttenuator.py

示例5: fitA

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def fitA(amps, times):
    listx, listsx = zip(*times)
    listy, listsy = zip(*amps)
    slaser_rel = 0.05
    listsy = list(listsy)
    for i, y in enumerate(listy):
        listsy[i] = y * np.sqrt(listsy[i] ** 2 + slaser_rel ** 2)
    data = DataErrors.fromLists(listx, listy, listsx, listsy)

    c = TCanvas('cA', '', 1280, 720)
    g = data.makeGraph('A', 'Zeit t / s', 'Amplitude A / V')
    g.GetYaxis().SetTitleOffset(1.2)
    g.Draw('AP')

    fit = Fitter('A', '[0]*exp(-(x)/[1])+[2]')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'C', 5e-8)
    fit.setParam(1, '#tau_{n}', 45e-6)
    fit.setParam(2, 'a', 0)
    fit.fit(g, 7.5e-6, 18e-6)
    fit.saveData('../calc/part2/volt_fit_A.txt')

    l = TLegend(0.625, 0.625, 0.85, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry('A', 'Messung', 'p')
    l.AddEntry(fit.function, 'Fit mit A(t) = C*e^{- #frac{t}{#tau_{n}}} + a', 'l')
    fit.addParamsToLegend(l, [('%.2e', '%.1e'), ('%.2e', '%.1e'), ('%.2e', '%.1e')], chisquareformat='%.2f')
    l.Draw()

    if PRINTGRAPHS or True:
        c.Update()
        c.Print('../img/part2/volt_fitA.pdf', 'pdf')
        c.SetLogy()
        c.Update()
        c.Print('../img/part2/volt_fitA_log.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:37,代码来源:eval_part2_volt.py

示例6: fitSigma

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def fitSigma(sigs, times):
    listx, listsx = zip(*times)
    listy, listsy = zip(*sigs)
    listy = map(abs, listy)   # fits can yield negative sigma, because it only occurse to
    data = DataErrors.fromLists(listx, listy, listsx, listsy)

    c = TCanvas('cSigma', '', 1280, 720)
    g = data.makeGraph('Sigma', 'Zeit t / s', 'Standardabweichung #sigma / cm')
    g.Draw('AP')

    fit = Fitter('fitS', 'sqrt(2*[0]*(x + [1]))')
    fit.setParam(0, 'D_{n}', 100)
    fit.setParam(1, 't_{0}', 0)
    fit.fit(g, 1e-6, 21e-6)
    fit.saveData('../calc/part2/dist_fit_sigma.txt')

    l = TLegend(0.15, 0.625, 0.45, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry('Sigma', 'Messung', 'p')
    l.AddEntry(fit.function, 'Fit mit #sigma(t) = #sqrt{2*D_{n}*(t + t_{0})}', 'l')
    fit.addParamsToLegend(l, [('%.1f', '%.1f'), ('%.2e', '%.2e')], chisquareformat='%.2f')
    l.Draw()

    if PRINTGRAPHS or True:
        c.Update()
        c.Print('../img/part2/dist_fitSigma.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:28,代码来源:eval_part2_dist.py

示例7: evalPedestal

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def evalPedestal():
    name = 'pedestal'
    data = MyonData.fromPath('../data/%s.TKA' % name)
    data.convertToCountrate()
    c = TCanvas('c_ped', '', 1280, 720)
    g = data.makeGraph('g_ped', 'channel c', 'countrate n / (1/s)')
    g.SetLineColor(1)
    g.SetLineWidth(1)
    g.GetXaxis().SetRangeUser(0, 20)
    g.Draw('APX')
    
    fit = Fitter('fit_%s' % name, 'gaus(0)')
    fit.setParam(0, 'A', 30)
    fit.setParam(1, 'x', 6)
    fit.setParam(2, '#sigma', 3)
    fit.setParamLimits(2, 0, 100)
    fit.fit(g, 3.5, 10.5)
    fit.saveData('../fit/%s.txt' % name)
    
    l = TLegend(0.55, 0.6, 0.85, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'pedestal', 'p')
    l.AddEntry(fit.function, 'fit with n(c) = A gaus(c; x, #sigma)', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.3f', '%.3f'), ('%.3f', '%.3f')), chisquareformat='%.2f', units=('1/s', '', ''), lang='en')
    l.Draw()

    g.Draw('P')
    c.Update()
    c.Print('../img/%s.pdf' % name, 'pdf')
    
    return (fit.params[1]['value'], fit.params[1]['error'])
开发者ID:Bigben37,项目名称:FP2,代码行数:33,代码来源:evalEnergyCalibration.py

示例8: fitT

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def fitT(x0):
    # get data and make graph
    data = TData.fromPath('../data/x0_%dmm.txt' % x0)
    c = TCanvas('c_%d' % x0, '', 1280, 720)
    g = data.makeGraph('g_%d' % x0, 'Kreisfrequenz #omega / (rad/ms)', 'Differenzenfrequenz #Delta#nu / kHz')
    g.Draw('AP')

    # fit
    fit = Fitter('fit_%d' % x0, 'pol1(0)')
    fit.setParam(0, 'a')
    fit.setParam(1, 'b')
    fit.fit(g, min(data.getX()) - 3, max(data.getX()) + 3)
    fit.saveData('../calc/fit_x0_%dmm.txt' % x0, 'w')

    # legend
    l = TLegend(0.15, 0.625, 0.425, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Messreihe bei x_{0}\' = %d mm' % x0, 'p')
    l.AddEntry(fit.function, 'Fit mit #Delta#nu (#omega) = a + b*#omega', 'l')
    fit.addParamsToLegend(l, [('%.1f', '%.1f'), ('%.0f', '%.0f')], chisquareformat='%.2f')
    l.Draw()

    # print
    c.Update()
    c.Print('../img/fit_x0_%dmm.pdf' % x0, 'pdf')

    return [(fit.params[0]['value'], fit.params[0]['error']), (fit.params[1]['value'], fit.params[1]['error'])]
开发者ID:Bigben37,项目名称:FP1,代码行数:29,代码来源:eval_T.py

示例9: fitX0

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def fitX0(period):
    # get data and make graph
    data = X0Data.fromPath('../data/T_%dms.txt' % period)
    c = TCanvas('c_%d' % period, '', 1280, 720)
    g = data.makeGraph('g_%d' % period, 'Differenzenfrequenz #Delta#nu / kHz', 'Auftreffpunkt x_{0}\' / mm')
    g.Draw('AP')

    # axis cross
    vline = TLine(0, 33, 0, 60)
    vline.Draw()

    # fit
    fit = Fitter('fit_%d' % period, 'pol1(0)')
    fit.setParam(0, 'x_{m}', 47)
    fit.setParam(1, 'm')
    fit.fit(g, min(data.getX()) - 3, max(data.getX()) + 3)
    fit.saveData('../calc/fit_T_%dms.txt' % period, 'w')

    # legend
    l = TLegend(0.15, 0.65, 0.425, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Messreihe bei T = %d ms' % period, 'p')
    l.AddEntry(fit.function, 'Fit mit x_{0}\'(#Delta#nu) = x_{m} + m * #Delta#nu', 'l')
    fit.addParamsToLegend(l, [('%.3f', '%.3f'), ('%.4f', '%.4f')], chisquareformat='%.2f')
    l.Draw()

    # print
    c.Update()
    c.Print('../img/fit_T_%dms.pdf' % period, 'pdf')

    return [(fit.params[0]['value'], fit.params[0]['error']), (fit.params[1]['value'], fit.params[1]['error'])]
开发者ID:Bigben37,项目名称:FP1,代码行数:33,代码来源:eval_X0.py

示例10: main

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def main():
    x, y, sy = zip(*loadCSVToList('../calc/part3/Co-Si_mergedbins.txt'))
    data = DataErrors.fromLists(x, y, [0]*len(x), sy)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Kanal k', 'Counts N')
    g.SetMarkerStyle(8)
    g.SetMarkerSize(0.5)
    g.SetLineColor(15)
    g.SetLineWidth(0)
    g.Draw('AP')
    
    fit = Fitter('f', '1/(sqrt(2*pi*[2]^2))*gaus(0)')
    fit.setParam(0, 'A', 50)
    fit.setParam(1, 'x_{c}', 690)
    fit.setParam(2, 's', 20)
    fit.fit(g, 672, 712)
    fit.saveData('../calc/part3/fit_Co-Si_01_mergedbins.txt', 'w')
    with TxtFile('../calc/part3/fit_Co-Si_01_mergedbins_raw.txt', 'w') as f:
        for key, param in fit.params.iteritems():
            f.writeline('\t', *map(str, [param['value'], param['error']]))
    
    l = TLegend(0.7, 0.5, 0.95, 0.85)
    l.SetTextSize(0.0225)
    l.AddEntry(g, 'Gemittelte Messwerte', 'p')
    l.AddEntry(fit.function, 'Fit mit', 'l')
    l.AddEntry(0, 'N(k) = #frac{A}{#sqrt{2#pi*#sigma^{2}}} exp(- #frac{1}{2} (#frac{x-x_{c}}{#sigma})^{2})', '')
    l.AddEntry(0, '', '')
    fit.addParamsToLegend(l, chisquareformat='%.2f')
    l.Draw()
    
    c.Update()
    c.Print('../img/part3/Co-Si_01_mergedbins.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:34,代码来源:eval_part3_co_si_smallpeak.py

示例11: energyGauge

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def energyGauge():
    dataList = readFileToList('../calc/hg_lines.txt')
    elemNames = ['Hg'] * len(dataList)
    dataList += readFileToList('../calc/na_lines.txt')
    elemNames += ['Na'] * (len(dataList) - len(elemNames))
    litVals = readFileToList('../data/hg_litvals.txt')
    litVals += readFileToList('../data/na_litvals.txt')

    data = DataErrors()
    for val, litval in zip(dataList, litVals):
        data.addPoint(val, litval, I2Data.ERRORBIN, 0)
        
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'measured wavelength #lambda_{exp} / nm', 'literature value #lambda_{lit} / nm')
    g.Draw('AP')
    
    fit = Fitter('f', '[0]+[1]*x')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 420, 600)
    fit.saveData('../calc/fit_energy_gauge.txt', 'w')
    
    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.AddEntry(fit.function, 'y = a + b*x', 'l')
    fit.addParamsToLegend(l)
    l.SetTextSize(0.03)
    l.Draw()
    
    c.Update()
    c.Print('../img/energy_gauge.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:32,代码来源:eval_energy_gauge.py

示例12: fitTransmissionSignal

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def fitTransmissionSignal(name):
    data = OPData.fromPath(DIR + name + '.tab', 2)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g_%s' % name, 'Zeit t / s', 'Spannung der Photodiode U_{ph} / V')
    prepareGraph(g, 2)
    g.GetXaxis().SetRangeUser(0.004, 0.019)
    g.Draw('APX')

    xmin, xmax = 0.0054, 0.015

    fit = Fitter('fit_%s' % name[-2:], '[0] - [1] * exp(-x/[2])')
    fit.setParam(0, 'a', 0.01)
    fit.setParam(1, 'b', 100)
    fit.setParam(2, '#tau', 0.001)
    fit.fit(g, xmin, xmax, 'M')
    fit.saveData('../fit/part5/%s.txt' % name)

    g.Draw('P')

    l = TLegend(0.35, 0.2, 0.65, 0.525)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Spannung der Photodiode', 'p')
    l.AddEntry(fit.function, 'Fit mit U_{ph}(t) = a - b e^{-t/#tau}', 'l')
    fit.addParamsToLegend(l, [('%.6f', '%.6f'), ('%.2f', '%.2f'), ('%.6f', '%.6f')], chisquareformat='%.2f', units=['V', 'V', 's'])
    l.Draw()

    c.Update()
    c.Print('../img/part5/%s.pdf' % name.replace('.', '-'), 'pdf')

    return fit.params[2]['value'], fit.params[2]['error']
开发者ID:Bigben37,项目名称:FP2,代码行数:32,代码来源:part5.py

示例13: fitSpectrum

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def fitSpectrum(detector, element, params, logy=True):
    data = P3SemiCon.fromPath('../data/part3/%s-%s.mca' % (element, detector))
    printTotalSpectrum(data, element, detector, logy)

    fitresults = []
    for i, peak in enumerate(params):
        c = TCanvas('cpeakl_%s-%s_%d' % (element, detector, i), '', 1280, 720)
        g = data.makeGraph('g%s-%s_%d' % (element, detector, i), 'Kanal k', 'Counts N')
        prepareGraph(g)
        g.GetXaxis().SetRangeUser(peak[2][0], peak[2][1])
        g.SetMinimum(peak[3][0])
        g.SetMaximum(peak[3][1])
        g.Draw('AP')

        fit = None
        paramnames = []
        if len(peak[0]) == 5:
            fit = Fitter('fit%d' % i, 'pol1(0) + 1/(sqrt(2*pi*[4]^2))*gaus(2)')
            paramnames = ['a', 'b', 'A', 'k_{c}', 's']
        elif len(peak[0]) == 4:
            fit = Fitter('fit%d' % i, '[0] + 1/(sqrt(2*pi*[3]^2))*gaus(1)')
            paramnames = ['a', 'A', 'k_{c}', 's']
        elif len(peak[0]) == 3:
            fit = Fitter('fit%d' % i, '1/(sqrt(2*pi*[2]^2))*gaus(0)')
            paramnames = ['A', 'k_{c}', 's']

        l = None
        if len(peak[0]) > 0:
            for j, param in enumerate(peak[0]):
                fit.setParam(j, paramnames[j], param)
            fit.fit(g, *peak[1])

            fitname = ''
            if len(peak[0]) == 5:
                fitname = 'N(k) = a + b*k + #frac{A}{#sqrt{2#pi*#sigma^{2}}} exp(- #frac{1}{2} (#frac{k-k_{c}}{#sigma})^{2})'
            elif len(peak[0]) == 4:
                fitname = 'N(k) = a + #frac{A}{#sqrt{2#pi*#sigma^{2}}} exp(- #frac{1}{2} (#frac{k-k_{c}}{#sigma})^{2})'
            elif len(peak[0]) == 3:
                fitname = 'N(k) = #frac{A}{#sqrt{2#pi*#sigma^{2}}} exp(- #frac{1}{2} (#frac{k-k_{c}}{#sigma})^{2})'
            fit.saveData('../calc/part3/fit_%s-%s_%02d.txt' % (element, detector, i), 'w')
            results = []
            for j, param in fit.params.iteritems():
                results.append((param['value'], param['error']))
            fitresults.append(results)

            # legend
            l = TLegend(0.675, 0.5, 0.995, 0.85)
            l.SetTextSize(0.025)
            l.AddEntry(g, 'Messwerte', 'p')
            l.AddEntry(fit.function, 'Fit mit', 'l')
            l.AddEntry(0, fitname, '')
            l.AddEntry(0, '', '')
            fit.addParamsToLegend(l, chisquareformat='%.2f')
            l.Draw()

        c.Update()
        if PRINTGRAPHS:
            c.Print('../img/part3/%s-%s_%02d.pdf' % (element, detector, i), 'pdf')
    return fitresults
开发者ID:Bigben37,项目名称:FP1,代码行数:61,代码来源:eval_part3.py

示例14: fitLaserVoltage

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def fitLaserVoltage(g, xmin, xmax, file):
    fit = Fitter('%s-laser' % file[:-4], 'pol1(0)')
    fit.function.SetLineColor(92)
    fit.function.SetLineWidth(2)
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 100)
    fit.fit(g, xmin, xmax, '+')
    fit.saveData('../fit/part2/%s-laser.txt' % file)
    return (fit.params[1]['value'], fit.params[1]['error'], fit.function)
开发者ID:Bigben37,项目名称:FP2,代码行数:11,代码来源:part2.py

示例15: main

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import saveData [as 别名]
def main():
    snu = ERRORS["nu"]  # TODO get error
    sB = ERRORS["B"]
    sgyrorel = 0
    files = ["H", "Glycol", "Teflon"]
    for file in files:
        datalist = loadCSVToList("../data/03-%s.txt" % file)
        if len(datalist) == 1:
            B, nu = datalist[0]
            gyro, sgyro = calcGyro(nu, snu, B, sB)
            if not sgyrorel == 0:
                sgyro = gyro * sgyrorel
            with TxtFile("../calc/%s.txt" % file, "w") as f:
                f.writeline("\t", "gyro", *map(str, (gyro, sgyro)))
                f.writeline("\t", "mu", *map(str, calcMu(gyro, sgyro)))
                f.writeline("\t", "gI", *map(str, calcNucGFactor(gyro, sgyro)))
        else:
            x, y = zip(*datalist)
            sx = [0] * len(x)
            sy = [snu] * len(y)
            data = DataErrors.fromLists(x, y, sx, sy)
            data.setXErrorAbs(sB)
            c = TCanvas("c%s" % file, "", 1280, 720)
            g = data.makeGraph("g%s" % file, "Magnetfeld B / mT", "Resonanzfrequenz #nu / MHz")
            g.Draw("AP")

            fit = Fitter("fit%s" % file, "[0]*x")
            fit.setParam(0, "m", 0.002)
            fit.fit(g, datalist[0][0] * 0.95, datalist[-1][0] * 1.05)
            fit.saveData("../calc/fit-%s.txt" % file, "w")

            l = TLegend(0.15, 0.60, 0.475, 0.85)
            l.SetTextSize(0.03)
            l.AddEntry(g, "Messdaten", "p")
            l.AddEntry(fit.function, "Fit mit #nu(B) = m*B", "l")
            l.AddEntry(0, "", "")
            fit.addParamsToLegend(
                l,
                [("%.5f", "%.5f"), ("%.2f", "%.2f")],
                chisquareformat="%.2f",
                advancedchi=True,
                units=["MHz / mT", "MHz"],
            )
            l.Draw()

            gyro = 2 * np.pi * fit.params[0]["value"] * 1e9  # in Hz / T
            sgyro = 2 * np.pi * fit.params[0]["error"] * 1e9  # in Hz / T
            sgyrorel = sgyro / gyro
            with TxtFile("../calc/%s.txt" % file, "w") as f:
                f.writeline("\t", "gyro", *map(str, (gyro, sgyro)))
                f.writeline("\t", "sgyrorel", str(sgyrorel))
                f.writeline("\t", "mu", *map(str, calcMu(gyro, sgyro)))
                f.writeline("\t", "gI", *map(str, calcNucGFactor(gyro, sgyro)))

            c.Update()
            c.Print("../img/03-%s.pdf" % file, "pdf")
开发者ID:Bigben37,项目名称:FP1,代码行数:58,代码来源:eval.py


注:本文中的fitter.Fitter.saveData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。