Fix '@Sens. ZSensorSens' KeyError loading picoforce 0x07200000 curves.
[hooke.git] / hooke / driver / picoforce.py
index a465c2ef5ad1c359532e435f9fb6a2ff83aca80d..94339d438964b76f97b29e1ee132e5998a5f388f 100644 (file)
@@ -4,15 +4,15 @@
 #
 # 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
@@ -29,7 +29,6 @@ import numpy
 
 from .. import curve as curve # this module defines data containers.
 from .. import experiment as experiment # this module defines expt. types
-from ..config import Setting # configurable setting class
 from . import Driver as Driver # this is the Driver base class
 
 
@@ -48,7 +47,7 @@ class PicoForceDriver (Driver):
 
         return header[2:17] == 'Force file list'
 
-    def read(self, path):
+    def read(self, path, info=None):
         info = self._read_header_path(path)
         self._check_version(info)
         data = self._read_data_path(path, info)
@@ -213,8 +212,12 @@ class PicoForceDriver (Driver):
                 match = type_re.match(image['@4:Image Data'])
                 assert match != None, 'Bad regexp for %s, %s' \
                     % ('@4:Image Data', image['@4:Image Data'])
-                assert match.group(1).lower() == match.group(2).replace(' ','').lower(), \
-                    'Name missmatch: "%s", "%s"' % (match.group(1), match.group(2))
+                if version == '0x06130001' and match.group(1) == 'ZLowVoltage':
+                    assert match.group(2) == 'Low Voltage Z', \
+                        'Name missmatch: "%s", "%s"' % (match.group(1), match.group(2))
+                else:
+                    assert match.group(1).lower() == match.group(2).replace(' ','').lower(), \
+                        'Name missmatch: "%s", "%s"' % (match.group(1), match.group(2))
                 tname = match.group(2)
             else:
                 assert version == '0x07200000', version
@@ -292,12 +295,13 @@ class PicoForceDriver (Driver):
         #    raise NotImplementedError(
         #        'Missmatched duplicate traces for %s: %s'
         #        % (trace_name, ', '.join(msg)))
-        import sys
+        import logging
+        log = logging.getLogger('hooke')
         for name,t in traces.items():
             if (t == trace).all():
-                print >> sys.stderr, 'replace %s with %s-2' % (name, trace_name)
+                log.debug('replace %s with %s-2' % (name, trace_name))
                 return name  # Replace this identical dataset.
-        print >> sys.stderr, 'store %s-2 as Other' % (trace_name)
+        log.debug('store %s-2 as Other' % (trace_name))
         return 'Other'
         # return None
 
@@ -344,9 +348,17 @@ class PicoForceDriver (Driver):
         # offset assumed if raw data is signed...
 
         nm_sens_re = re.compile('V ([.0-9]*) nm/V')
-        match = nm_sens_re.match(info['Scanner list']['@Sens. Zsens'])
-        assert match != None, 'Bad regexp for %s/%s, %s' \
-            % ('Scanner list', '@Sens. Zsens', info['Scanner list']['@4:Z scale'])
+        if version in ['0x06120002', '0x06130001']:        
+            match = nm_sens_re.match(info['Ciao scan list']['@Sens. ZSensorSens'])
+            assert match != None, 'Bad regexp for %s/%s, %s' \
+                % ('Ciao scan list', '@Sens. ZSensorSens',
+                   info['Ciao scan list']['@Sens. ZSensorSens'])
+        else:
+            assert version == '0x07200000', version
+            match = nm_sens_re.match(info['Ciao scan list']['@Sens. ZsensSens'])
+            assert match != None, 'Bad regexp for %s/%s, %s' \
+                % ('Ciao scan list', '@Sens. ZsensSens',
+                   info['Ciao scan list']['@Sens. ZsensSens'])
         ret['z piezo sensitivity (m/V)'] = float(match.group(1))*1e-9
 
         match = nm_sens_re.match(info['Ciao scan list']['@Sens. DeflSens'])