From: W. Trevor King Date: Fri, 20 Jul 2012 20:05:18 +0000 (-0400) Subject: Add test-igorpy.py for testing igor.igorpy. X-Git-Tag: v0.2~19 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a2151cb15bcb281e94b75d3d4206f0c0a451fbd0;p=igor.git Add test-igorpy.py for testing igor.igorpy. --- diff --git a/igor/igorpy.py b/igor/igorpy.py index f68c7fc..ad4a09a 100644 --- a/igor/igorpy.py +++ b/igor/igorpy.py @@ -1,6 +1,5 @@ # This program is in the public domain -""" -IGOR file reader. +"""`igor.py` compatibility layer on top of the `igor` package. igor.load('filename') or igor.loads('data') loads the content of an igore file into memory as a folder structure. @@ -14,7 +13,9 @@ To see the whole tree, use: print folder.format() The usual igor folder types are given in the technical reports PTN003.ifn and TN003.ifn. """ -__version__="0.9" +from __future__ import absolute_import + +__version__='1.0' import struct import numpy diff --git a/test/test-igorpy.py b/test/test-igorpy.py new file mode 100644 index 0000000..ab9e9a8 --- /dev/null +++ b/test/test-igorpy.py @@ -0,0 +1,184 @@ +# Copyright + +r"""Test the igor.igorpy compatibility layer by loading sample files. + +>>> from pprint import pprint +>>> import igor.igorpy as igor + +Load a packed experiment: + +>>> path = data_path('polar-graphs-demo.pxp') +>>> d = igor.load(path) +>>> print(d) + +>>> dir(d) # doctest: +ELLIPSIS +['Packages', 'W_plrX5', 'W_plrX6', ..., 'radiusData', 'radiusQ1'] + + +Navigation: + +>>> print(d.Packages) + +>>> print(d[0]) # doctest: +ELLIPSIS + + + +Variables: + +>>> v = d[0] +>>> dir(v) # doctest: +ELLIPSIS +['__class__', ..., 'depstr', 'depvar', 'format', 'sysvar', 'userstr', 'uservar'] +>>> v.depstr +{} +>>> v.depvar +{} +>>> v.format() +'' +>>> pprint(v.sysvar) # doctest: +REPORT_UDIFF +{'K0': 0.0, + 'K1': 0.0, + 'K10': 0.0, + 'K11': 0.0, + 'K12': 0.0, + 'K13': 0.0, + 'K14': 0.0, + 'K15': 0.0, + 'K16': 0.0, + 'K17': 0.0, + 'K18': 0.0, + 'K19': 0.0, + 'K2': 0.0, + 'K20': 128.0, + 'K3': 0.0, + 'K4': 0.0, + 'K5': 0.0, + 'K6': 0.0, + 'K7': 0.0, + 'K8': 0.0, + 'K9': 0.0} +>>> v.userstr +{} +>>> v.uservar +{} + + +Waves: + +>>> d.W_plrX5 + +>>> dir(d.W_plrX5) # doctest: +ELLIPSIS +['__array__', ..., 'axis', 'axis_units', 'data', ..., 'name', 'notes'] +>>> d.W_plrX5.axis # doctest: +ELLIPSIS +[array([ 0.04908739, 0.04870087, 0.04831436, 0.04792784, 0.04754133, + 0.04715481, 0.0467683 , 0.04638178, 0.04599527, 0.04560875, + ... + 0.00077303, 0.00038651, 0. ]), array([], dtype=float64), array([], dtype=float64), array([], dtype=float64)] +>>> d.W_plrX5.axis_units +('', '', '', '') +>>> d.W_plrX5.data # doctest: +ELLIPSIS +array([ 1.83690956e-17, 2.69450769e-02, 7.65399113e-02, + 1.44305170e-01, 2.23293692e-01, 3.04783821e-01, + ... + -2.72719120e-03, 5.24539061e-08], dtype=float32) + + +Dump the whole thing: + +>>> print(d.format()) +root + + + radiusData data (128) + angleData data (128) + W_plrX5 data (128) + W_plrY5 data (128) + angleQ1 data (64) + radiusQ1 data (64) + W_plrX6 data (64) + W_plrY6 data (64) + Packages + WMDataBase + + PolarGraphs + + + + + + +Load a packed experiment without ignoring unknown records: + +>>> d = igor.load(path, ignore_unknown=False) +>>> print(d.format()) +root + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + radiusData data (128) + angleData data (128) + W_plrX5 data (128) + W_plrY5 data (128) + angleQ1 data (64) + radiusQ1 data (64) + W_plrX6 data (64) + W_plrY6 data (64) + Packages + WMDataBase + + PolarGraphs + + + + + + +Try to load a binary wave: + +>>> path = data_path('mac-double.ibw') +>>> d = igor.load(path) +Traceback (most recent call last): + ... +IOError: final record too long; bad pxp file? +""" + +import os.path + +from igor import LOG + + +_this_dir = os.path.dirname(__file__) +_data_dir = os.path.join(_this_dir, 'data') + +def data_path(filename): + LOG.info('Testing igorpy compatibility {}\n'.format(filename)) + path = os.path.join(_data_dir, filename) + return path