1 # Copyright (C) 2012 W. Trevor King <wking@tremily.us>
3 # This file is part of %(project)s.
5 # %(project)s is free software: you can redistribute it and/or modify it under
6 # the 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
10 # %(project)s is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with %(project)s. If not, see <http://www.gnu.org/licenses/>.
18 r"""Test the igor.igorpy compatibility layer by loading sample files.
20 >>> from pprint import pprint
21 >>> import igor.igorpy as igor
22 >>> igor.ENCODING = 'UTF-8'
24 Load a packed experiment:
26 >>> path = data_path('polar-graphs-demo.pxp')
27 >>> d = igor.load(path)
30 >>> dir(d) # doctest: +ELLIPSIS
31 ['Packages', 'W_plrX5', 'W_plrX6', ..., 'radiusData', 'radiusQ1']
37 <igor.Folder root/Packages>
38 >>> print(d[0]) # doctest: +ELLIPSIS
39 <igor.igorpy.Variables object at 0x...>
45 >>> dir(v) # doctest: +ELLIPSIS
46 ['__class__', ..., 'depstr', 'depvar', 'format', 'sysvar', 'userstr', 'uservar']
52 '<Variables: system 21, user 0, dependent 0>'
53 >>> pprint(v.sysvar) # doctest: +REPORT_UDIFF
84 <igor.Wave W_plrX5 data (128)>
85 >>> dir(d.W_plrX5) # doctest: +ELLIPSIS
86 ['__array__', ..., 'axis', 'axis_units', 'data', ..., 'name', 'notes']
87 >>> d.W_plrX5.axis # doctest: +ELLIPSIS
88 [array([ 0.04908739, 0.04870087, 0.04831436, 0.04792784, 0.04754133,
89 0.04715481, 0.0467683 , 0.04638178, 0.04599527, 0.04560875,
91 0.00077303, 0.00038651, 0. ]), array([], dtype=float64), array([], dtype=float64), array([], dtype=float64)]
92 >>> d.W_plrX5.data_units
94 >>> d.W_plrX5.axis_units
96 >>> d.W_plrX5.data # doctest: +ELLIPSIS
97 array([ 1.83690956e-17, 2.69450769e-02, 7.65399113e-02,
98 1.44305170e-01, 2.23293692e-01, 3.04783821e-01,
100 -2.72719120e-03, 5.24539061e-08], dtype=float32)
103 Dump the whole thing:
105 >>> print(d.format())
107 <Variables: system 21, user 0, dependent 0>
109 radiusData data (128)
119 <Variables: system 21, user 6, dependent 0>
121 <Variables: system 21, user 38, dependent 0>
127 Load a packed experiment without ignoring unknown records:
129 >>> d = igor.load(path, ignore_unknown=False)
130 >>> print(d.format())
162 <Variables: system 21, user 0, dependent 0>
164 radiusData data (128)
174 <Variables: system 21, user 6, dependent 0>
176 <Variables: system 21, user 38, dependent 0>
182 Try to load a binary wave:
184 >>> path = data_path('mac-double.ibw')
185 >>> d = igor.load(path)
186 Traceback (most recent call last):
188 IOError: final record too long; bad pxp file?
196 _this_dir = os.path.dirname(__file__)
197 _data_dir = os.path.join(_this_dir, 'data')
199 def data_path(filename):
200 LOG.info('Testing igorpy compatibility {}\n'.format(filename))
201 path = os.path.join(_data_dir, filename)