--- /dev/null
+#!/usr/bin/env python2
+#
+# Copyright (C) 2012 W. Trevor King <wking@tremily.us>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""Compare unfolding pulls between Prof. Yang's software and my own.
+"""
+
+import os as _os
+
+import crunch as _crunch
+import gyang_curve as _gyang_curve
+from matplotlib import pylab as _pylab
+from pypiezo import surface as _pypiezo_surface
+
+
+def load_yang_curves(basedir):
+ for series in sorted(_os.listdir(basedir)):
+ if series.endswith('.ibw'):
+ path = _os.path.join(basedir, series)
+ for curve in _gyang_curve.load_all_traces(path):
+ yield curve
+
+def load_king_curves(basedir):
+ for path in sorted(_os.listdir(basedir)):
+ if path.endswith('.h5'):
+ curve = _os.path.join(basedir, path)
+ yield _crunch.load_pull(filename=curve)
+
+
+def plot_comparison(yang_dir, king_dir):
+ yang = load_yang_curves(yang_dir)
+ king = load_king_curves(king_dir)
+ figure = _pylab.figure()
+ axes = figure.add_subplot(1, 1, 1)
+ axes.set_title('velocity clamp unfolding')
+ axes.set_xlabel('z piezo (bits)')
+ axes.set_ylabel('deflection (bits)')
+ axes.hold(True)
+ xyc = []
+ for curve in yang:
+ xyc.append(
+ (curve.piezo_expanded + 2**15, curve.deflection + 2**15, 'b'))
+ for curve in king:
+ xyc.append((curve['alpha_v'], curve['alpha_f'], 'r'))
+ for x, y, c in xyc:
+ ddict = {
+ 'approach': { # for _analyze_surface_position_data
+ 'z': x[::-1],
+ 'deflection': y[::-1],
+ }
+ }
+ (non_contact_offset,non_contact_slope,kink,alpha_dp
+ ) = _pypiezo_surface.analyze_surface_position_data(
+ ddict, return_all_parameters=True)
+ y0 = non_contact_offset + non_contact_slope*(kink-x.min())
+ x0 = x.max() - (y.max()-y0)/alpha_dp
+ axes.plot(
+ x - x0, y - y0,
+ linestyle='none', marker=',', color=c, markeredgecolor=c)
+ return figure
+
+
+if __name__ == '__main__':
+ import argparse
+
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument(
+ 'yang', metavar='DIR',
+ help="directory for data taken with Prof. Yang's LabVIEW program")
+ parser.add_argument(
+ 'king', metavar='DIR',
+ help='directory for data taken with my pyafm-based unfolder')
+
+ args = parser.parse_args()
+
+ plot_comparison(
+ yang_dir=_os.path.expanduser(args.yang),
+ king_dir=_os.path.expanduser(args.king))
+ _pylab.show()