{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Save Photon-HDF5 description to JSON" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from collections import OrderedDict\n", "import json\n", "import phconvert as phc\n", "phc.__version__" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "filename = 'phconvert/specs/photon-hdf5_fields.json'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "with open(filename, 'wt') as f:\n", " json.dump(phc.hdf5.official_fields_descr, f, \n", " indent=4, separators=(',', ':\\n '))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "with open(filename) as f:\n", " official_fields_descr = json.load(f, object_pairs_hook=OrderedDict)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check roundtrip:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "official_fields_descr == phc.hdf5.official_fields_descr" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 0 }