Created
February 11, 2019 10:57
-
-
Save makoc/3486c45d53ccf04395179cbb1dcf47f1 to your computer and use it in GitHub Desktop.
python h5py blosc example, options explained
This file contains 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
# conda install h5py pytables | |
__import__('tables') # <-- import PyTables; __import__ so that linters don't complain | |
import h5py | |
# now h5py "supports" blosc | |
def blosc_opts(complevel=9, complib='blosc:lz4', shuffle=True): | |
shuffle = 2 if shuffle == 'bit' else 1 if shuffle else 0 | |
compressors = ['blosclz', 'lz4', 'lz4hc', 'snappy', 'zlib', 'zstd'] | |
complib = ['blosc:' + c for c in compressors].index(complib) | |
args = { | |
'compression': 32001, | |
'compression_opts': (0, 0, 0, 0, complevel, shuffle, complib) | |
} | |
if shuffle: | |
args['shuffle'] = False | |
return args | |
# for writing, do something like this | |
with h5py.File('foo.h5', 'w') as f: | |
f.create_dataset('x', data=x, **blosc_opts(9, 'blosc:zstd', True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment