plot-unfold.py: Add a simple h5 -> png converter
authorW. Trevor King <wking@tremily.us>
Wed, 13 Mar 2013 14:03:41 +0000 (10:03 -0400)
committerW. Trevor King <wking@tremily.us>
Wed, 13 Mar 2013 14:03:41 +0000 (10:03 -0400)
This makes it easy to filter successful pulls by eye using your
favorite image viewer.

plot-unfold.py [new file with mode: 0755]

diff --git a/plot-unfold.py b/plot-unfold.py
new file mode 100755 (executable)
index 0000000..d54d823
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+#
+# Copyright
+
+import os.path as _os_path
+
+import h5py as _h5py
+import matplotlib as _matplotlib
+import matplotlib.pyplot as _matplotlib_pyplot
+
+
+FIGURE = _matplotlib_pyplot.figure()
+
+
+class BadDataError (ValueError):
+    pass
+
+
+def convert_to_png(filename):
+    with _h5py.File(filename) as f:
+        png = filename + '.png'
+        if not _os_path.isfile(png):
+            FIGURE.clear()
+            axes = FIGURE.add_subplot(1, 1, 1)
+            axes.hold(True)
+            try:
+                z = f['approach']['z']
+                d = f['approach']['deflection']
+            except KeyError, e:
+                raise BadDataError(e)
+            plot = axes.plot(z, d, '.')
+            try:
+                z = f['unfold']['z']
+                d = f['unfold']['deflection']
+            except KeyError, e:
+                raise BadDataError(e)
+            plot = axes.plot(z, d, '.')
+            FIGURE.savefig(png)
+
+
+if __name__ == '__main__': 
+    import sys as _sys
+
+    for filename in _sys.argv[1:]:
+        try:
+            convert_to_png(filename)
+        except BadDataError:
+            print('Error converting {}'.format(filename))