From 59c7729c093fe9712a884de2c43a2716866958a7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 16 Oct 2012 13:55:49 -0400 Subject: [PATCH] compare-unfold.py: add bit-level comparison between my and Marisa's programs. Marisa was using Prof. Yang's LabVIEW unfolder, while I use my pyafm-based unfolder. The `compare-unfold.py` script allows bit-level comparison between the two approaches, reading the native data saved by each approach. Here's an example using local data on my system: $ ./compare-unfold.py \ ~/rsrch/analysis/labview-comparison/gyang/2012-10-01-unfold/ \ ~/rsrch/analysis/labview-comparison/wking/unfold/ --- .../compare-unfold.py | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 posts/Comparing_velocity_clamp_experiments/compare-unfold.py diff --git a/posts/Comparing_velocity_clamp_experiments/compare-unfold.py b/posts/Comparing_velocity_clamp_experiments/compare-unfold.py new file mode 100755 index 0000000..9ffd53a --- /dev/null +++ b/posts/Comparing_velocity_clamp_experiments/compare-unfold.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python2 +# +# Copyright (C) 2012 W. Trevor King +# +# 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 . + +"""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() -- 2.26.2