-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcvfitCLI_example.py
68 lines (57 loc) · 2.41 KB
/
cvfitCLI_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/python
__author__="remislp"
__date__ ="$29-Nov-2014 15:40:02$"
from cvfit import fitting
from cvfit import plots
from cvfit.fitting import SingleFitSession, MultipleFitSession
if __name__ == "__main__":
# load data set
datasets, fname = fitting.load_data(example=True)
print('File {0} loaded'.format(fname))
print('{0:d} sets found.'.format(len(datasets)))
for i in range(len(datasets)):
print ('\nSet #{0:d}:'.format(i+1))
print (datasets[i])
# load equation
eqname = 'Hill'
if eqname == 'Hill' or eqname == 'Langmuir':
from cvfit.equations import Hill
# initiate fitting sessions, fit data and print results
fitsessions = MultipleFitSession()
for each in datasets:
equation = Hill(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())
fitsessions.add(fs)
print('\n*************************************************')
print('\tAverage of all fits:')
print(fitsessions.string_average_estimates())
# plot fitted
fplots = fitsessions.prepare_fplot('fit')
fig = plots.cvfit_plot(datasets, fig=None,
fplotsets=fplots, fplotline='b-',
logX=True, logY=False, legend=True)
# normalise to fitted maxima and replot
for fs in fitsessions.list:
fs.eq.normalise(fs.data)
fplots = fitsessions.prepare_fplot('norm')
plots.cvfit_plot(datasets, fig=None, fplotsets=fplots, fplotline='b-',
logX=True, logY=False, legend=True, norm=True)
# 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())
# plot pooled data fit
fplots = fitsessions.prepare_fplot('pooled')
plots.cvfit_plot([fitsessions.pooled.data], fig=None, fplotsets=fplots,
fplotline='b-', logX=True, logY=False, legend=False, pooled=True)