e7d34b8716c2e632859db4459e46839573f88276
[hooke.git] / test / polymer_fit.py
1 # Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
5 # Hooke is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
8 # later version.
9 #
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
17
18 """
19 >>> from hooke.hooke import Hooke, HookeRunner
20 >>> h = Hooke()
21 >>> r = HookeRunner()
22
23 Prepare a curve for polymer fitting.
24
25 >>> h = r.run_lines(h, ['load_playlist test/data/test']) # doctest: +ELLIPSIS
26 <FilePlaylist test.hkp>
27 Success
28 <BLANKLINE>
29 >>> h = r.run_lines(h, ['zero_surface_contact_point --block retract']
30 ...     ) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
31 {...'fitted parameters': [8.413...e-08, 2.812...e-10, 158.581...],...}
32 Success
33 <BLANKLINE>
34 >>> h = r.run_lines(h, ['polynomial_flatten --block retract --deflection_column "surface deflection (m)" --degree 1'])
35 Success
36 <BLANKLINE>
37 >>> h = r.run_lines(h, ['convert_distance_to_force --block retract --deflection_column "flattened deflection (m)"'])
38 Success
39 <BLANKLINE>
40 >>> h = r.run_lines(h, ['remove_cantilever_from_extension --block retract'])
41 Success
42 <BLANKLINE>
43 >>> h = r.run_lines(h, ['flat_filter_peaks --block retract --min_points 1']
44 ...     )  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
45 [<Peak flat filter peak 0 of surface deflection 510
46   [ -1.065...e-09  -2.244...e-09]>,
47  <Peak flat filter peak 1 of surface deflection 610
48   [ -1.156...e-09  -8.840...e-10  -3.173...e-10  -7.480...e-10]>,
49  <Peak flat filter peak 2 of surface deflection 704
50   [ -7.933...e-10  -1.654...e-09]>,
51  <Peak flat filter peak 3 of surface deflection 812
52   [ -1.745...e-09]>,
53  <Peak flat filter peak 4 of surface deflection 916 [ -2.085...e-09]>,
54  <Peak flat filter peak 5 of surface deflection 1103
55   [ -1.768...e-09  -8.885...e-09  -1.722...e-09]>]
56 Success
57 <BLANKLINE>
58
59 Fit the flat filter peaks with a polymer tension.
60
61 >>> h = r.run_lines(h, ['flat_peaks_to_polymer_peaks --block retract'])
62 Success
63 <BLANKLINE>
64 >>> h = r.run_lines(h, ['polymer_fit_peaks --block retract'])
65 Success
66 <BLANKLINE>
67
68 Check the results.
69
70 >>> curve = h.playlists.current().current()
71 >>> retract = curve.data[1]
72 >>> retract.info['columns']  # doctest: +NORMALIZE_WHITESPACE
73 ['z piezo (m)', 'deflection (m)',
74  'surface distance (m)', 'surface deflection (m)',
75  'flattened deflection (m)', 'deflection (N)',
76  'cantilever adjusted extension (m)', 'flat filter peaks (m)',
77  'polymer peak 0 (N)', 'polymer peak 1 (N)', 'polymer peak 2 (N)',
78  'polymer peak 3 (N)', 'polymer peak 4 (N)', 'polymer peak 5 (N)']
79 >>> retract[:5,-2:]
80 Data([[ NaN,  NaN],
81        [ NaN,  NaN],
82        [ NaN,  NaN],
83        [ NaN,  NaN],
84        [ NaN,  NaN]])
85 >>> retract[1097:1103,-2:]  # doctest: +ELLIPSIS
86 Data([[             NaN,   5.2...e-10],
87        [             NaN,   5...e-10],
88        [             NaN,   6.1...e-10],
89        [             NaN,   6.2...e-10],
90        [             NaN,   7...e-10],
91        [             NaN,              NaN]])
92 >>> retract[-5:,-2:]
93 Data([[ NaN,  NaN],
94        [ NaN,  NaN],
95        [ NaN,  NaN],
96        [ NaN,  NaN],
97        [ NaN,  NaN]])
98 """