bff752082de112de2c266f8e2d780035594b2ccf
[hooke.git] / test / jpk_driver.py
1 # Copyright (C) 2010-2011 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 >>> import os
21 >>> import os.path
22 >>> from hooke.hooke import Hooke, HookeRunner
23 >>> h = Hooke()
24 >>> r = HookeRunner()
25 >>> playlist = os.path.join('test', 'data', 'vclamp_jpk', 'playlist')
26 >>> h = r.run_lines(h, ['load_playlist ' + playlist]) # doctest: +ELLIPSIS
27 <FilePlaylist JPK>
28 Success
29 <BLANKLINE>
30 >>> h = r.run_lines(h, ['curve_info']) # doctest: +ELLIPSIS, +REPORT_UDIFF
31 name: 2009.04.23-15.15.47.jpk
32 path: .../test/data/vclamp_jpk/2009.04.23-15.15.47.jpk
33 driver: <hooke.driver.jpk.JPKDriver object at 0x...>
34 note: None
35 command stack: []
36 blocks: 2
37 block names: ['approach', 'retract']
38 block sizes: [(4096, 6), (4096, 4)]
39 Success
40 <BLANKLINE>
41
42 Ensure that we can at least load each of the example curves.
43
44 >>> p = h.playlists.current()
45 >>> for i,curve in enumerate(p.items()):
46 ...     print (i,
47 ...            curve.info['raw info']['file-format-version'],
48 ...            [d.info['name'] for d in curve.data]) # doctest: +REPORT_UDIFF
49 (0, '0.5', ['approach', 'retract'])
50 (1, '0.5', ['approach', 'pause', 'retract'])
51 (2, '0.2', ['pause-0', 'approach', 'pause-1', 'retract'])
52 (3, '0.12', ['approach', 'pause-0', 'retract', 'pause-1'])
53 (4, '0.2', ['pause-0', 'approach', 'pause-1', 'retract'])
54 (5, '0.12', ['approach', 'pause-0', 'retract', 'pause-1'])
55
56 Load each of the example segments in the :file:`Data1D` directory.
57
58 >>> driver = [d for d in h.drivers if d.name == 'jpk'][0]
59 >>> base_dir = os.path.join('test', 'data', 'vclamp_jpk', 'Data1D')
60 >>> for file_name in sorted(os.listdir(base_dir)):
61 ...     path = os.path.join(base_dir, file_name)
62 ...     print path
63 ...     print driver.is_me(path)
64 ...     data = driver.read(path)
65 ...     print data.shape, data[:5], data[-5:]
66 ...     # doctest: +ELLIPSIS, +REPORT_UDIFF
67 test/data/vclamp_jpk/Data1D/data1D-ConstantData1D-1282315524304.jpk-data1D
68 True
69 (128,) [  9.99999997e-07   9.99999997e-07   9.99999997e-07   9.99999997e-07
70    9.99999997e-07] [  9.99999997e-07   9.99999997e-07   9.99999997e-07   9.99999997e-07
71    9.99999997e-07]
72 test/data/vclamp_jpk/Data1D/data1D-MemoryFloatData1D-1282315524326.jpk-data1D
73 True
74 (128,) [  5.31691167e+36   5.31691167e+36   1.06338233e+37   1.59507347e+37
75    2.12676467e+37] [ Inf  Inf  Inf  Inf  Inf]
76 test/data/vclamp_jpk/Data1D/data1D-MemoryIntegerData1D-1282315524320.jpk-data1D
77 True
78 (128,) [ 0.  0.  0.  0.  0.] [ 0.  0.  0.  0.  0.]
79 test/data/vclamp_jpk/Data1D/data1D-MemoryIntegerData1D-1282315524323.jpk-data1D
80 True
81 (128,) [ 0.  0.  0.  0.  0.] [ 0.  0.  0.  0.  0.]
82 test/data/vclamp_jpk/Data1D/data1D-MemoryShortData1D-1282315524313.jpk-data1D
83 True
84 (128,) [ 0.000511  0.000511  0.001022  0.001533  0.002044] [-0.002683 -0.002172 -0.001661 -0.00115  -0.000639]
85 test/data/vclamp_jpk/Data1D/data1D-MemoryShortData1D-1282315524316.jpk-data1D
86 True
87 (128,) [ 0.  0.  0.  0.  0.] [ 0.  0.  0.  0.  0.]
88 test/data/vclamp_jpk/Data1D/data1D-RasterData1D-1282315524283.jpk-data1D
89 True
90 (128,) [ 0.  1.  2.  3.  4.] [ 123.  124.  125.  126.  127.]
91
92 The data for the float and integer samples are not very convincing,
93 but appear to be correct.  I've emailed Michael Haggerty to confirm
94 the expected contents.
95 """