Skip to content

Instantly share code, notes, and snippets.

@hugohadfield
Last active October 17, 2018 14:03
Show Gist options
  • Save hugohadfield/1f632ba17eeafe5deaee75777c13fabc to your computer and use it in GitHub Desktop.
Save hugohadfield/1f632ba17eeafe5deaee75777c13fabc to your computer and use it in GitHub Desktop.
hdf5mvs.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import h5py\nimport numpy as np",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# This is our function that will do the writing\ndef write_mv_array(file_name, mv_array, metric, basis_names, compression=False):\n n_datapoints = mv_array.shape[0]\n mv_dims = mv_array.shape[1]\n with h5py.File(file_name, \"w\") as f:\n if compression:\n dset_coefs = f.create_dataset(\"coefs\", data=mv_array, compression=\"gzip\", compression_opts=9)\n else:\n dset_coefs = f.create_dataset(\"coefs\", data=mv_array)\n dset_ip = f.create_dataset(\"metric\", data=metric)\n dset_basis_names = f.create_dataset(\"basis_names\", data=basis_names)",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from clifford.g3c import *\nfrom clifford.tools.g3c import *\n\n# We will test it with clifford\nbasis_names = np.array(list(sorted(layout.basis_vectors.keys())),dtype=bytes)\n\n# TODO make this into a function in clifford\nlayout.metric = np.zeros((len(layout.basis_vectors),len(layout.basis_vectors)))\nfor i,v in enumerate(layout.basis_vectors_lst):\n for j,v2 in enumerate(layout.basis_vectors_lst):\n layout.metric[i,j] = (v|v2)[0]\n\n# Make some data\nmv_array = ConformalMVArray([random_point_pair() for i in range(500)]).value",
"execution_count": 3,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# Write the file with and without compression\n\n# This is 128K\nwrite_mv_array(\"mytestfile.hdf5\", mv_array, layout.metric, basis_names)\n\n# This is 48K\nwrite_mv_array(\"mytestfile_compressed.hdf5\", mv_array, layout.metric, basis_names, compression=True)",
"execution_count": 4,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python"
},
"gist": {
"id": "1f632ba17eeafe5deaee75777c13fabc",
"data": {
"description": "hdf5mvs.ipynb",
"public": true
}
},
"_draft": {
"nbviewer_url": "https://gist.github.com/1f632ba17eeafe5deaee75777c13fabc"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment