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