Created
October 17, 2018 14:04
-
-
Save hugohadfield/7dfa44baa7817996514a52a2e6e3fce7 to your computer and use it in GitHub Desktop.
hdf5_clifford
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import h5py | |
| import numpy as np | |
| # This is our function that will do the writing | |
| def write_mv_array(file_name, mv_array, metric, basis_names, compression=False): | |
| n_datapoints = mv_array.shape[0] | |
| mv_dims = mv_array.shape[1] | |
| with h5py.File(file_name, "w") as f: | |
| if compression: | |
| dset_coefs = f.create_dataset("coefs", data=mv_array, compression="gzip", compression_opts=9) | |
| else: | |
| dset_coefs = f.create_dataset("coefs", data=mv_array) | |
| dset_ip = f.create_dataset("metric", data=metric) | |
| dset_basis_names = f.create_dataset("basis_names", data=basis_names) | |
| from clifford.g3c import * | |
| from clifford.tools.g3c import * | |
| # We will test it with clifford | |
| basis_names = np.array(list(sorted(layout.basis_vectors.keys())),dtype=bytes) | |
| # TODO make this into a function in clifford | |
| layout.metric = np.zeros((len(layout.basis_vectors),len(layout.basis_vectors))) | |
| for i,v in enumerate(layout.basis_vectors_lst): | |
| for j,v2 in enumerate(layout.basis_vectors_lst): | |
| layout.metric[i,j] = (v|v2)[0] | |
| # Make some data | |
| mv_array = ConformalMVArray([random_point_pair() for i in range(500)]).value | |
| # Write the file with and without compression | |
| # This is 128K | |
| write_mv_array("mytestfile.hdf5", mv_array, layout.metric, basis_names) | |
| # This is 48K | |
| write_mv_array("mytestfile_compressed.hdf5", mv_array, layout.metric, basis_names, compression=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment