In [1]:
%matplotlib inline
In [2]:
from pylab import*
import numpy as np
In [3]:
#import sys
#sys.path.append('\CVFIT')
In [4]:
#from cvfit import fitting
from cvfit.fitting import SingleFitSession
from cvfit.fitting import MultipleFitSession
from cvfit import data
from cvfit import plots
In [5]:
fname = "Chimera1_tofit.xlsx"
sheet = 1
sets = data.read_sets_from_Excel(fname, 2, 0, sheet)
print('File {0} loaded'.format(fname))
print('{0:d} sets found.'.format(len(sets)))
#sets = fitting.set_weights(sets)
for i in range(len(sets)):
print ('\nSet #{0:d}:'.format(i+1))
print (sets[i])
In [6]:
eqname = 'Hill'
if eqname == 'Hill' or eqname == 'Langmuir':
from cvfit.equations import Hill as eqfit
In [7]:
# initiate fitting sessions, fit data and print results
fitsessions = MultipleFitSession()
for each in sets:
equation = eqfit(eqname)
fs = SingleFitSession(each, equation)
fs.fit()
fs.calculate_errors()
print('\n*************************************************')
print('\t' + fs.data.title + ' fit finished')
print(fs.string_estimates())
print(fs.string_liklimits())
#plots.plot_hill_fit_result_single(fname, fsession.data, fsession.eq, plotguess=True)
fitsessions.add(fs)
print('\n*************************************************')
print('\tAverage of all fits:')
print(fitsessions.string_average_estimates())
In [8]:
fplots = fitsessions.prepare_fplot('fit')
for each in sets:
semilogx(each.X, each.Y, 'o', label=each.title)
for fp in fplots:
semilogx(fp[0], fp[1], 'b-')
In [9]:
for fs in fitsessions.list:
fs.eq.normalise(fs.data)
fplots = fitsessions.prepare_fplot('norm')
for each in sets:
semilogx(each.X, each.normY, 'o', label=each.title)
for fp in fplots:
semilogx(fp[0], fp[1], 'b-')
In [10]:
# pool data and fit pooled
fitsessions.pool(norm=True)
fitsessions.pooled.fit()
fitsessions.pooled.calculate_errors()
fitsessions.pooled.data.average_pooled()
print('\n***********************\n**************************')
print('\tNormalised and pooled data fit finished')
print(fitsessions.pooled.string_estimates())
print(fitsessions.pooled.string_liklimits())
In [11]:
# plot pooled data fit
fplots = fitsessions.prepare_fplot('pooled')
fig = plots.cvfit_plot([fitsessions.pooled.data], fig=None, fplotsets=fplots,
fplotline='b-', logX=True, logY=False, legend=False, pooled=True)
In [12]:
fout = open(fname[:-5] + '_points.txt', 'w')
for i in range(len(fitsessions.pooled.data.avX)):
fout.write('{0:.6e}\t{1:.6e}\t{2:.6e}\n'.
format(fitsessions.pooled.data.avX[i],
fitsessions.pooled.data.avY[i],
fitsessions.pooled.data.avS[i]))
fout.close()
fout = open(fname[:-5] + '_fit.txt', 'w')
for i in range(len(fplots[0][0])):
fout.write('{0:.6e}\t{1:.6e}\n'.
format(fplots[0][0][i], fplots[0][1][i]))
fout.close()
In [ ]: