本文整理汇总了Python中fitter.Fitter类的典型用法代码示例。如果您正苦于以下问题:Python Fitter类的具体用法?Python Fitter怎么用?Python Fitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeSigmaFit
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')
示例2: energyGauge
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')
示例3: main
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')
示例4: fitT
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'])]
示例5: multiPeakFit
def multiPeakFit(g, ufunc, uparams, params, xstart, xend):
"""fits all peaks with one function
Arguments:
g -- graph
ufunc -- underground function
uparams -- start parameter for underground function
params -- params for peaks
xstart -- start x value
xend -- end x value
"""
# build fit function
fitfunc = ufunc
pstart = len(uparams)
for i in xrange(len(params)):
fitfunc += ' + gaus(%d)' % (pstart + 3 * i)
# create fitter, change npx to high value
fit = Fitter('f', fitfunc)
fit.function.SetNpx(10000)
# set underground params
for i, param in enumerate(uparams):
fit.setParam(i, chr(97 + i), param) # params of underground are enumerated with a, b, c, ...
# set peak params
for i, param in enumerate(params):
fit.setParam(3 * i + pstart + 0, 'A%d' % (i + 1), param[0])
fit.setParam(3 * i + pstart + 1, 'c%d' % (i + 1), param[1])
fit.setParam(3 * i + pstart + 2, 's%d' % (i + 1), param[3])
# fit
fit.fit(g, xstart, xend)
return fit
示例6: fitLaserVoltage
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)
示例7: main
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")
示例8: compareSpectrum
def compareSpectrum(prefix, spectrum, litvals):
xlist = list(zip(*spectrum))[0]
sxlist = list(zip(*spectrum))[1]
compData = DataErrors.fromLists(xlist, litvals, sxlist, [0] * len(litvals))
c = TCanvas('c_%s_compspectrum' % prefix, '', 1280, 720)
g = compData.makeGraph('g_%s_compspectrum' % prefix,
'experimentell bestimmte HFS-Aufspaltung #Delta#nu^{exp}_{%s} / GHz' % prefix,
'theoretische HFS-Aufspaltung #Delta#nu^{theo} / GHz')
g.Draw('AP')
fit = Fitter('fit_%s_compspectum' % prefix, 'pol1(0)')
fit.setParam(0, 'a_{%s}' % prefix, 0)
fit.setParam(1, 'b_{%s}' % prefix, 1)
fit.fit(g, compData.getMinX() - 0.5, compData.getMaxX() + 0.5)
if prefix == "up":
l = TLegend(0.15, 0.6, 0.45, 0.85)
else:
l = TLegend(0.15, 0.6, 0.5, 0.85)
l.SetTextSize(0.03)
l.AddEntry(g, 'Spektrum', 'p')
l.AddEntry(fit.function, 'Fit mit #Delta#nu^{theo} = a_{%s} + b_{%s} #Delta#nu^{exp}_{%s}' % (prefix, prefix, prefix), 'l')
fit.addParamsToLegend(l, [('%.2f', '%.2f'), ('%.3f', '%.3f')], chisquareformat='%.2f', units=['GHz', ''])
l.Draw()
c.Update()
if not DEBUG:
c.Print('../img/part2/%s-spectrum.pdf' % prefix, 'pdf')
示例9: makePeakFreqGraph
def makePeakFreqGraph(peaks, name):
xlist = list(list(zip(*peaks))[0])
sxlist = list(list(zip(*peaks))[1])
ylist = list(map(lambda i: i * 9.924, range(len(peaks))))
sylist = list(map(lambda i: i * 0.03, range(len(peaks))))
direction = name.split('-')[0]
tabledata = list(zip(*[list(range(1, len(xlist) + 1)), list(map(lambda x:x * 1000, xlist)), list(map(lambda x:x * 1000, sxlist)),
ylist, sylist]))
with TxtFile('../src/tab_part2_etalonfreqs_%s.tex' % direction, 'w') as f:
f.write2DArrayToLatexTable(tabledata,
["i", r"$x_i$ / ms", r"$0.2 \cdot s_i$ / ms", r"$\nu_i$ / GHz", r"$s_{\nu_i}$ / GHz"],
["%d", "%.3f", "%.3f", "%.2f", "%.2f"],
"Zentren $x_i$ der gefitteten Cauchy-Funktionen mit Fehler aus den " +
"Breiteparametern $s_i$ und Frequenzdifferenzen zum ersten Peak. ",
"tab:etalon:calib:%s" % direction)
etalonData = DataErrors.fromLists(xlist, ylist, sxlist, sylist)
etalonData.multiplyX(1000)
c = TCanvas('c_pf_' + name, '', 1280, 720)
g = etalonData.makeGraph('g_pf_' + name, 'Zeit t / ms', 'Frequenzabstand #Delta#nu / GHz')
g.SetMinimum(etalonData.getMinY() - 5)
g.SetMaximum(etalonData.getMaxY() + 5)
g.Draw('AP')
fit = Fitter('fit_pf_' + name, 'pol1(0)')
fit.setParam(0, 'a')
fit.setParam(1, 'r')
xmin, xmax = etalonData.getMinX(), etalonData.getMaxX()
deltax = (xmax - xmin) / 10
fit.fit(g, xmin - deltax, xmax + deltax)
fit.saveData('../fit/part2/%s-etalon_calibration.txt' % name)
if fit.params[1]['value'] < 0:
l = TLegend(0.575, 0.6, 0.85, 0.85)
else:
l = TLegend(0.15, 0.6, 0.425, 0.85)
l.SetTextSize(0.03)
l.AddEntry(g, 'Etalonpeaks', 'p')
l.AddEntry(fit.function, 'Fit mit #Delta#nu = a + r * t', 'l')
fit.addParamsToLegend(l, [('%.1f', '%.1f'), ('%.2f', '%.2f')], chisquareformat='%.2f', units=('GHz', 'GHz/ms'))
l.Draw()
c.Update()
if not DEBUG:
c.Print('../img/part2/%s-etalon_calibration.pdf' % name, 'pdf')
return (fit.params[1]['value'], fit.params[1]['error'])
示例10: __init__
def __init__( self ) :
self.dict = Dictionary()
self.spliter = PinyinSpliter()
self.fitter = Fitter()
self.picker = Picker( self.dict )
#self.picker.set( [], [], True )
self.cache = [ [ 0, [], "" ] ]
self.candCacheIndex = 0
self.candStartIndex = 0
self.candList = []
示例11: evalDistance
def evalDistance(n, params):
xmin, xmax = params[1:]
deltax = abs(xmax - xmin) * 0.1
data = P2SemiCon.fromPath('../data/part2/length/ALL%04.d/F%04dCH1.CSV' % (n, n))
g = data.makeGraph('g%d' % n, 'Zeit t / s', 'Spannung U / V')
c = TCanvas('c%d' % n, '', 1280, 720)
g.SetMarkerStyle(1)
g.GetXaxis().SetRangeUser(xmin - deltax, xmax + deltax)
closex = min(getByCloseX(data, xmin)[1], getByCloseX(data, xmax)[1])
if closex > 0:
ymin = closex * 0.95
else:
ymin = closex * 1.1
g.SetMinimum(ymin)
g.GetYaxis().SetTitleOffset(1.2)
g.Draw('APX')
fit = Fitter('f', 'pol1(0) + 1/(sqrt(2*pi*[4]^2))*gaus(2)')
fit.function.SetNpx(1000)
paramname = ['a', 'b', 'A', 't_{c}', '#sigma']
for i, param in enumerate(params[0]):
fit.setParam(i, paramname[i], param)
fit.fit(g, xmin, xmax)
fit.saveData('../calc/part2/dist%02d.txt' % n, 'w')
l = TLegend(0.625, 0.6, 0.99, 0.99)
l.SetTextSize(0.03)
l.AddEntry(g, 'Messung', 'p')
l.AddEntry(fit.function, 'Fit mit U(t) = a + b*t + #frac{A}{#sqrt{2#pi*#sigma^{2}}} e^{- #frac{1}{2} (#frac{t - t_{c}}{#sigma})^{2}}', 'l')
l.AddEntry(0, '', '')
fit.addParamsToLegend(l, [('%.2e', '%.2e')] * len(params[0]), chisquareformat='%.2f')
l.Draw()
if PRINTGRAPHS:
c.Update()
c.Print('../img/part2/dist%02d.pdf' % n, 'pdf')
return data, fit.params, fit.getCorrMatrix(), params[1], params[2]
示例12: singlePeakFit
def singlePeakFit(g, debug=False):
"""fits every peak individually
Arguments:
g -- graph
debut -- if true prints values of found peaks to console (default=False)
"""
peaks = getStartValues()
params = []
for i, peak in enumerate(peaks):
fit = Fitter('fit%d' % i, 'pol1(0) + gaus(2)')
fit.function.SetLineColor(i % 8 + 2)
for param in peak[0]:
fit.setParam(*param)
fit.fit(g, peak[1], peak[2], '+')
params.append([fit.params[2]['value'], fit.params[3]['value'], fit.params[3]['error'], fit.params[4]['value'], fit.function])
if debug:
for j, par in fit.params.iteritems():
print(par['name'], par['value'], par['error'])
print('')
return params
示例13: evalFaraday
def evalFaraday():
data = FaraData.fromPath('../data/fara_data.txt')
c = TCanvas('c', '', 1280, 720)
g = data.makeGraph('g', 'Strom I / A', 'Winkel #alpha / #circ')
g.GetXaxis().SetRangeUser(-6, 6)
g.SetMinimum(-15)
g.SetMaximum(15)
g.Draw('AP')
vline = TLine(0, -15, 0, 15)
vline.Draw()
hline = TLine(-6, 0, 6, 0)
hline.Draw()
fit = Fitter('f', 'pol1(0)')
fit.setParam(0, 'a', 0)
fit.setParam(1, 'b', 2)
fit.fit(g, -5.5, 5.5)
fit.saveData('../calc/faraday.txt', 'w')
l = TLegend(0.15, 0.65, 0.35, 0.85)
l.AddEntry('g', 'Messwerte', 'p')
l.AddEntry(fit.function, 'Fit mit y = a + b*x', 'l')
l.AddEntry(0, 'Parameter:', '')
l.AddEntry(0, 'a = %.2f #pm %.2f' % (fit.params[0]['value'], fit.params[0]['error']), '')
l.AddEntry(0, 'b = %.3f #pm %.3f' % (fit.params[1]['value'], fit.params[1]['error']), '')
l.Draw()
c.Update()
c.Print('../img/faraday.pdf', 'pdf')
b = (fit.params[1]['value'], fit.params[1]['error'])
c = 2554.85
N = 3600
v = map(lambda x: x / c, b) # verdet constant
oe = 60 * 79.58 / 100 # factor for min/(Oe*cm)
voe = map(lambda x: x * oe, v) # verdet in min/(Oe*cm)
vi = map(lambda x: x / N, b) # ideal
vioe = map(lambda x: x * oe, vi)
with TxtFile('../calc/faraday_verdet.txt', 'w') as f:
f.writeline('\t', *map(str, v))
f.writeline('\t', *map(str, voe))
f.writeline('\t', *map(str, vi))
f.writeline('\t', *map(str, vioe))
示例14: main
def main():
times = [2.4, 4.5, 6.25, 8.6]
times_error = [0.02] * len(times)
channels = [113, 223, 315.5, 441]
channels_error = [0.5] * len(times)
with TxtFile('../src/tab_timecalibration.tex', 'w') as f:
f.write2DArrayToLatexTable(list(zip(*[times, times_error, channels, channels_error])),
["$t$ / \\textmu s", "$s_t$ / \\textmu s", "$c$", "$s_c$"],
["%.2f", "%.2f", "%.1f", "%.1f"],
"Measured times and channels with errors for the time calibration.", "tab:tcal")
data = DataErrors.fromLists(channels, times, channels_error, times_error)
c = TCanvas('c', '', 1280, 720)
g = data.makeGraph('g', 'channel c', 'time t / #mus')
g.Draw('APX')
fit = Fitter('fit', 'pol1(0)')
fit.setParam(0, 'a', 0)
fit.setParam(1, 'b', 50)
fit.fit(g, 100, 450)
fit.saveData('../fit/timeCalibration.txt')
l = TLegend(0.15, 0.6, 0.5, 0.85)
l.SetTextSize(0.03)
l.AddEntry(g, 'measurement', 'p')
l.AddEntry(fit.function, 'fit with t(c) = a + b * c', 'l')
fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.5f', '%.5f')), chisquareformat='%.2f', units=('#mus', '#mus/channel'), lang='en')
l.Draw()
g.Draw('P')
c.Update()
c.Print('../img/timeCalibration.pdf', 'pdf')
with TxtFile('../calc/timeCalibration.txt', 'w') as f:
f.writeline('\t', str(fit.params[0]['value']), str(fit.params[0]['error']))
f.writeline('\t', str(fit.params[1]['value']), str(fit.params[1]['error']))
f.writeline('\t', str(fit.getCovMatrixElem(0, 1)))
示例15: load_data
import setup
from load_data import load_data
import numpy as np
import scipy as sp
import matplotlib as mpl
import matplotlib.pyplot as plt
from plots import *
from all_fits import *
import config as cfg
from fitter import Fitter
from shapes.sigmoid import Sigmoid
from shapes.spline import Spline
from scalers import LogScaler
cfg.verbosity = 1
data = load_data(pathway='serotonin', scaler=LogScaler())
series = data.get_one_series('HTR1A','MD')
x = series.ages
y = series.single_expression
fitter = Fitter(Spline())
theta, sigma, LOO_predictions,_ = fitter.fit(x,y)
spline = theta[0]
preds = spline(x)
print preds