"""Compare unfolding pulls between Prof. Yang's software and my own.
"""
+import collections as _collections
import os as _os
import crunch as _crunch
import gyang_curve as _gyang_curve
from matplotlib import pylab as _pylab
+import numpy as _numpy
from pypiezo import surface as _pypiezo_surface
def load_yang_curves(basedir, single=False):
+ if _os.path.isfile(basedir):
+ for curve in _gyang_curve.load_all_traces(basedir):
+ yield(curve)
+ return
for series in sorted(_os.listdir(basedir)):
if series.endswith('.ibw'):
path = _os.path.join(basedir, series)
return
def load_king_curves(basedir, single=False):
+ if _os.path.isfile(basedir):
+ yield _crunch.load_pull(filename=basedir)
+ return
for path in sorted(_os.listdir(basedir)):
if path.endswith('.h5'):
curve = _os.path.join(basedir, path)
if single:
return
-def plot_comparison(yang_dir, king_dir, single=False):
+def plot_comparison(yang_dir, king_dir, single=False, contact_slope=False):
yang = load_yang_curves(yang_dir, single=single)
king = load_king_curves(king_dir, single=single)
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)')
+ if contact_slope:
+ axes.set_xlabel('pull index')
+ axes.set_ylabel('contact slope (bits/bit)')
+ hist_data = {'b': [], 'r': []}
+ else:
+ axes.set_xlabel('z piezo (bits)')
+ axes.set_ylabel('deflection (bits)')
axes.hold(True)
xyc = []
for curve in yang:
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)
+ if contact_slope:
+ hist_data[c].append(alpha_dp)
+ else:
+ axes.plot(
+ x - x0, y - y0,
+ linestyle='none', marker=',', color=c, markeredgecolor=c)
+ if contact_slope:
+ for c,data in hist_data.items():
+ data = [d for d in data if d > 5.5] # HACK!!
+ axes.plot(
+ data,
+ linestyle='none', marker='o', color=c, markeredgecolor=c)
+ #axes.hist(data, color=c, alpha=0.5)
+ data = _numpy.array(data)
+ print('\n'.join(
+ '{}: {}'.format(key,value)
+ for key,value in {
+ 'color': c,
+ 'mean': data.mean(),
+ 'std': data.std(),
+ }.items()))
return figure
parser.add_argument(
'--single', action='store_const', const=True,
help='compare only a single curve of each type')
+ parser.add_argument(
+ '--contact-slope', action='store_const', const=True,
+ help='compare contact slopes')
+ parser.add_argument(
+ '-o', '--output', default=None,
+ help='save figure instead of showing it')
parser.add_argument(
'yang', metavar='DIR',
help="directory for data taken with Prof. Yang's LabVIEW program")
args = parser.parse_args()
- plot_comparison(
+ figure = plot_comparison(
yang_dir=_os.path.expanduser(args.yang),
king_dir=_os.path.expanduser(args.king),
- single=args.single)
- _pylab.show()
+ single=args.single,
+ contact_slope=args.contact_slope)
+ if args.output:
+ figure.savefig(args.output)
+ else:
+ _pylab.show()