compare-unfold.py: add --single option for less crowded plots.
authorW. Trevor King <wking@tremily.us>
Thu, 18 Oct 2012 17:10:36 +0000 (13:10 -0400)
committerW. Trevor King <wking@tremily.us>
Thu, 18 Oct 2012 17:10:36 +0000 (13:10 -0400)
posts/Comparing_velocity_clamp_experiments/compare-unfold.py

index 9ffd53ac0869a817c4b11c8b7a4992e5f9890d88..f27127f3a245ca101fe7ab2ee39ff4004528cea8 100755 (executable)
@@ -26,23 +26,26 @@ from matplotlib import pylab as _pylab
 from pypiezo import surface as _pypiezo_surface
 
 
-def load_yang_curves(basedir):
+def load_yang_curves(basedir, single=False):
     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
+                if single:
+                    return
 
-def load_king_curves(basedir):
+def load_king_curves(basedir, single=False):
     for path in sorted(_os.listdir(basedir)):
         if path.endswith('.h5'):
             curve = _os.path.join(basedir, path)
             yield _crunch.load_pull(filename=curve)
+            if single:
+                return
 
-
-def plot_comparison(yang_dir, king_dir):
-    yang = load_yang_curves(yang_dir)
-    king = load_king_curves(king_dir)
+def plot_comparison(yang_dir, king_dir, single=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')
@@ -55,6 +58,7 @@ def plot_comparison(yang_dir, king_dir):
             (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
@@ -77,6 +81,9 @@ if __name__ == '__main__':
     import argparse
 
     parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument(
+        '--single', action='store_const', const=True,
+        help='compare only a single curve of each type')
     parser.add_argument(
         'yang', metavar='DIR',
         help="directory for data taken with Prof. Yang's LabVIEW program")
@@ -88,5 +95,6 @@ if __name__ == '__main__':
 
     plot_comparison(
         yang_dir=_os.path.expanduser(args.yang),
-        king_dir=_os.path.expanduser(args.king))
+        king_dir=_os.path.expanduser(args.king),
+        single=args.single)
     _pylab.show()