From: W. Trevor King Date: Wed, 13 Mar 2013 14:03:41 +0000 (-0400) Subject: plot-unfold.py: Add a simple h5 -> png converter X-Git-Tag: v0.2~6 X-Git-Url: http://git.tremily.us/?p=unfold-protein.git;a=commitdiff_plain;h=7c8d759a93afb857f769b1bc35f441e1e2dc6815 plot-unfold.py: Add a simple h5 -> png converter This makes it easy to filter successful pulls by eye using your favorite image viewer. --- diff --git a/plot-unfold.py b/plot-unfold.py new file mode 100755 index 0000000..d54d823 --- /dev/null +++ b/plot-unfold.py @@ -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))