Add W_plrX5.data_units check to test-igorpy.py.
[igor.git] / test / test-igorpy.py
1 # Copyright
2
3 r"""Test the igor.igorpy compatibility layer by loading sample files.
4
5 >>> from pprint import pprint
6 >>> import igor.igorpy as igor
7
8 Load a packed experiment:
9
10 >>> path = data_path('polar-graphs-demo.pxp')
11 >>> d = igor.load(path)
12 >>> print(d)
13 <igor.Folder root>
14 >>> dir(d)  # doctest: +ELLIPSIS
15 ['Packages', 'W_plrX5', 'W_plrX6', ..., 'radiusData', 'radiusQ1']
16
17
18 Navigation:
19
20 >>> print(d.Packages)
21 <igor.Folder root/Packages>
22 >>> print(d[0])  # doctest: +ELLIPSIS
23 <igor.igorpy.Variables object at 0x...>
24
25
26 Variables:
27
28 >>> v = d[0]
29 >>> dir(v)  # doctest: +ELLIPSIS
30 ['__class__', ..., 'depstr', 'depvar', 'format', 'sysvar', 'userstr', 'uservar']
31 >>> v.depstr
32 {}
33 >>> v.depvar
34 {}
35 >>> v.format()
36 '<Variables: system 21, user 0, dependent 0>'
37 >>> pprint(v.sysvar)  # doctest: +REPORT_UDIFF
38 {'K0': 0.0,
39  'K1': 0.0,
40  'K10': 0.0,
41  'K11': 0.0,
42  'K12': 0.0,
43  'K13': 0.0,
44  'K14': 0.0,
45  'K15': 0.0,
46  'K16': 0.0,
47  'K17': 0.0,
48  'K18': 0.0,
49  'K19': 0.0,
50  'K2': 0.0,
51  'K20': 128.0,
52  'K3': 0.0,
53  'K4': 0.0,
54  'K5': 0.0,
55  'K6': 0.0,
56  'K7': 0.0,
57  'K8': 0.0,
58  'K9': 0.0}
59 >>> v.userstr
60 {}
61 >>> v.uservar
62 {}
63
64
65 Waves:
66
67 >>> d.W_plrX5
68 <igor.Wave W_plrX5 data (128)>
69 >>> dir(d.W_plrX5)  # doctest: +ELLIPSIS
70 ['__array__', ..., 'axis', 'axis_units', 'data', ..., 'name', 'notes']
71 >>> d.W_plrX5.axis  # doctest: +ELLIPSIS
72 [array([ 0.04908739,  0.04870087,  0.04831436,  0.04792784,  0.04754133,
73         0.04715481,  0.0467683 ,  0.04638178,  0.04599527,  0.04560875,
74         ...
75         0.00077303,  0.00038651,  0.        ]), array([], dtype=float64), array([], dtype=float64), array([], dtype=float64)]
76 >>> d.W_plrX5.data_units
77 ('', '', '', '')
78 >>> d.W_plrX5.axis_units
79 ('', '', '', '')
80 >>> d.W_plrX5.data  # doctest: +ELLIPSIS
81 array([  1.83690956e-17,   2.69450769e-02,   7.65399113e-02,
82          1.44305170e-01,   2.23293692e-01,   3.04783821e-01,
83          ...
84         -2.72719120e-03,   5.24539061e-08], dtype=float32)
85
86
87 Dump the whole thing:
88
89 >>> print(d.format())
90 root
91   <Variables: system 21, user 0, dependent 0>
92   <History>
93   radiusData data (128)
94   angleData data (128)
95   W_plrX5 data (128)
96   W_plrY5 data (128)
97   angleQ1 data (64)
98   radiusQ1 data (64)
99   W_plrX6 data (64)
100   W_plrY6 data (64)
101   Packages
102     WMDataBase
103       <Variables: system 21, user 6, dependent 0>
104     PolarGraphs
105       <Variables: system 21, user 38, dependent 0>
106   <Recreation>
107   <GetHistory>
108   <Procedure>
109
110
111 Load a packed experiment without ignoring unknown records:
112
113 >>> d = igor.load(path, ignore_unknown=False)
114 >>> print(d.format())
115 root
116   <Unknown type 11>
117   <Unknown type 12>
118   <Unknown type 13>
119   <Unknown type 13>
120   <Unknown type 13>
121   <Unknown type 13>
122   <Unknown type 13>
123   <Unknown type 13>
124   <Unknown type 13>
125   <Unknown type 14>
126   <Unknown type 15>
127   <Unknown type 16>
128   <Unknown type 16>
129   <Unknown type 17>
130   <Unknown type 17>
131   <Unknown type 17>
132   <Unknown type 17>
133   <Unknown type 17>
134   <Unknown type 17>
135   <Unknown type 16>
136   <Unknown type 17>
137   <Unknown type 17>
138   <Unknown type 17>
139   <Unknown type 17>
140   <Unknown type 17>
141   <Unknown type 17>
142   <Unknown type 18>
143   <Unknown type 11>
144   <Unknown type 26>
145   <Unknown type 26>
146   <Variables: system 21, user 0, dependent 0>
147   <History>
148   radiusData data (128)
149   angleData data (128)
150   W_plrX5 data (128)
151   W_plrY5 data (128)
152   angleQ1 data (64)
153   radiusQ1 data (64)
154   W_plrX6 data (64)
155   W_plrY6 data (64)
156   Packages
157     WMDataBase
158       <Variables: system 21, user 6, dependent 0>
159     PolarGraphs
160       <Variables: system 21, user 38, dependent 0>
161   <Recreation>
162   <GetHistory>
163   <Procedure>
164
165
166 Try to load a binary wave:
167
168 >>> path = data_path('mac-double.ibw')
169 >>> d = igor.load(path)
170 Traceback (most recent call last):
171    ...
172 IOError: final record too long; bad pxp file?
173 """
174
175 import os.path
176
177 from igor import LOG
178
179
180 _this_dir = os.path.dirname(__file__)
181 _data_dir = os.path.join(_this_dir, 'data')
182
183 def data_path(filename):
184     LOG.info('Testing igorpy compatibility {}\n'.format(filename))
185     path = os.path.join(_data_dir, filename)
186     return path