Run update-copyright.py.
[hooke.git] / hooke / driver / mfp3d.py
index 39ea3d36d8e1b80b05398e9ee19a7a027f092fde..cddbf04ac80e5f5539897eb55e423c3c27475add 100644 (file)
@@ -1,24 +1,23 @@
-# Copyright (C) 2008-2010 A. Seeholzer
-#                         Alberto Gomez-Casado
-#                         Richard Naud <richard.naud@epfl.ch>
+# Copyright (C) 2008-2012 A. Seeholzer
+#                         Alberto Gomez-Casado <a.gomezcasado@tnw.utwente.nl>
+#                         Richard Naud
 #                         Rolf Schmidt <rschmidt@alcor.concordia.ca>
 #                         W. Trevor King <wking@drexel.edu>
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# Hooke is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
-# Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
 
 """Driver for MFP-3D files.
 
@@ -37,9 +36,8 @@ import pprint
 import numpy
 
 from .. import curve as curve
-from .. import experiment as experiment
+from ..util.igorbinarywave import loadibw
 from . import Driver as Driver
-from .igorbinarywave import loadibw
 
 
 __version__='0.0.0.20100604'
@@ -71,10 +69,8 @@ class MFP3DDriver (Driver):
     
     def read(self, path, info=None):
         data,bin_info,wave_info = loadibw(path)
-        approach,retract,info = self._translate_ibw(data, bin_info, wave_info)
-        info['filetype'] = self.name
-        info['experiment'] = experiment.VelocityClamp
-        return ([approach, retract], info)
+        blocks,info = self._translate_ibw(data, bin_info, wave_info)
+        return (blocks, info)
      
     def _translate_ibw(self, data, bin_info, wave_info):
         if bin_info['version'] != 5:
@@ -93,28 +89,38 @@ class MFP3DDriver (Driver):
                 value = None
             note[key] = value
         bin_info['note'] = note
+
+        # Ensure a valid MFP3D file version.
         if note['VerDate'] not in ['80501.041', '80501.0207']:
             raise Exception(note['VerDate'])
             raise NotImplementedError(
                 '%s file version %s not supported (yet!)\n%s'
                 % (self.name, note['VerDate'], pprint.pformat(note)))
 
+        # Parse known parameters into standard Hooke format.
         info = {
             'raw info':{'bin':bin_info,
                         'wave':wave_info},
-            'time':wave_info['creationDate'],
+            'time':note['Seconds'],
             'spring constant (N/m)':float(note['SpringConstant']),
             'temperature (K)':self._temperature(note),
             }
-        # MFP3D's native data dimensions match Hooke's (<point>, <column>) layout.
-        approach = self._scale_block(data[:wave_info['npnts']/2,:], info, 'approach')
-        retract = self._scale_block(data[wave_info['npnts']/2:,:], info, 'retract')
-        return (approach, retract, info)
 
-    def _scale_block(self, data, info, name):
+        # Extract data blocks
+        blocks = []
+        indexes = [int(i) for i in note['Indexes'].split(',')]
+        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))
+
+        return (blocks, info)
+
+    def _scale_block(self, data, info, index):
         """Convert the block from its native format to a `numpy.float`
         array in SI units.
         """
+        # MFP3D's native data dimensions match Hooke's (<point>, <column>) layout.
         shape = 3
         # raw column indices
         columns = info['raw info']['bin']['dimLabels'][1]
@@ -130,6 +136,14 @@ class MFP3DDriver (Driver):
             dtype=numpy.float,
             info=copy.deepcopy(info)
             )
+
+        version = info['raw info']['bin']['note']['VerDate']
+        if version == '80501.041':
+            name = ['approach', 'retract', 'pause'][index]
+        elif version == '80501.0207':
+            name = ['approach', 'pause', 'retract'][index]
+        else:
+            raise NotImplementedError()
         ret.info['name'] = name
         ret.info['raw data'] = data # store the raw data