Replace hooke.util.igorbinarywave with external igor package.
[hooke.git] / hooke / driver / mfp3d.py
index cddbf04ac80e5f5539897eb55e423c3c27475add..700df4dfc1f96f19fd89fdb9524308bf76b20d2d 100644 (file)
@@ -34,9 +34,9 @@ import os.path
 import pprint
 
 import numpy
+from igor.binarywave import load as _loadibw
 
 from .. import curve as curve
-from ..util.igorbinarywave import loadibw
 from . import Driver as Driver
 
 
@@ -68,19 +68,19 @@ class MFP3DDriver (Driver):
         return False
     
     def read(self, path, info=None):
-        data,bin_info,wave_info = loadibw(path)
-        blocks,info = self._translate_ibw(data, bin_info, wave_info)
+        data = _loadibw(path)
+        blocks,info = self._translate_ibw(data)
         return (blocks, info)
      
-    def _translate_ibw(self, data, bin_info, wave_info):
-        if bin_info['version'] != 5:
-            raise NotImplementedError('IBW version %d (< 5) not supported'
-                                      % bin_info['version'])
+    def _translate_ibw(self, data):
+        if data['version'] != 5:
+            raise NotImplementedError(
+                'IBW version {} (< 5) not supported'.format(data['version']))
             # We need version 5 for multidimensional arrays.
 
         # Parse the note into a dictionary
         note = {}
-        for line in bin_info['note'].split('\r'):
+        for line in data['wave']['note'].split('\r'):
             fields = [x.strip() for x in line.split(':', 1)]
             key = fields[0]
             if len(fields) == 2:
@@ -88,7 +88,7 @@ class MFP3DDriver (Driver):
             else:
                 value = None
             note[key] = value
-        bin_info['note'] = note
+        data['wave']['note'] = note
 
         # Ensure a valid MFP3D file version.
         if note['VerDate'] not in ['80501.041', '80501.0207']:
@@ -99,8 +99,7 @@ class MFP3DDriver (Driver):
 
         # Parse known parameters into standard Hooke format.
         info = {
-            'raw info':{'bin':bin_info,
-                        'wave':wave_info},
+            'raw info':data,
             'time':note['Seconds'],
             'spring constant (N/m)':float(note['SpringConstant']),
             'temperature (K)':self._temperature(note),
@@ -112,7 +111,9 @@ class MFP3DDriver (Driver):
         assert indexes[0] == 0, indexes
         for i,start in enumerate(indexes[:-1]):
             stop = indexes[i+1]
-            blocks.append(self._scale_block(data[start:stop+1,:], info, i))
+            blocks.append(
+                self._scale_block(
+                    data['wave']['wData'][start:stop+1,:], info, i))
 
         return (blocks, info)
 
@@ -123,7 +124,7 @@ class MFP3DDriver (Driver):
         # MFP3D's native data dimensions match Hooke's (<point>, <column>) layout.
         shape = 3
         # raw column indices
-        columns = info['raw info']['bin']['dimLabels'][1]
+        columns = info['raw info']['wave']['labels'][1][1:]
         # Depending on your MFP3D version:
         #   VerDate 80501.0207: ['Raw', 'Defl', 'LVDT', 'Time']
         #   VerDate 80501.041:  ['Raw', 'Defl', 'LVDT']
@@ -137,7 +138,7 @@ class MFP3DDriver (Driver):
             info=copy.deepcopy(info)
             )
 
-        version = info['raw info']['bin']['note']['VerDate']
+        version = info['raw info']['wave']['note']['VerDate']
         if version == '80501.041':
             name = ['approach', 'retract', 'pause'][index]
         elif version == '80501.0207':
@@ -189,8 +190,8 @@ class MFP3DDriver (Driver):
         #              h=Hooke();
         #              h.run_command('load playlist',
         #                  {'input':'test/data/vclamp_mfp3d/playlist'});
-        #              x = [(int(c.info['raw info']['bin']['note']['Seconds'])
-        #                    - int(c.info['raw info']['bin']['note']['StartTempSeconds']))
+        #              x = [(int(c.info['raw info']['wave']['note']['Seconds'])
+        #                    - int(c.info['raw info']['wave']['note']['StartTempSeconds']))
         #                   for c in h.playlists.current().items()];
         #              print 'average', float(sum(x))/len(x);
         #              print 'range', min(x), max(x);