Skip to content

Commit

Permalink
Readme, example: How to enable/disable optimization via API funcs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivilata committed Dec 5, 2023
1 parent 16bcbcc commit 85cc9e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ After that, optimization will be attempted for any slicing of a dataset (of the

.. _hdf5plugin: https://github.com/silx-kit/hdf5plugin

Even if the module is imported and the ``Dataset`` class is patched, you may still force-disable the optimization by setting ``BLOSC2_FILTER=1`` in the environment.
You may globally disable the optimization after importing ``b2h5py`` by calling ``b2h5py.unpatch_dataset_class()``, and enable it again with ``b2h5py.patch_dataset_class()``. Even if the module is imported and the ``Dataset`` class is patched, you may still force-disable the optimization by setting ``BLOSC2_FILTER=1`` in the environment.

Building
--------
Expand Down
11 changes: 11 additions & 0 deletions examples/blosc2_optimized_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,14 @@
print("Slice from dataset:", slice_, sep='\n')
print("Slice from input array:", data[150:, 150:], sep='\n')
os.environ['BLOSC2_FILTER'] = '0' # back to normal
# Utility functions are also provided to enable and disable optimization
# (`BLOSC2_FILTER` still takes priority, though).
print("Disabling Blosc2 optimized slicing via API.")
with h5py.File(file_name, 'r') as f:
import b2h5py
b2h5py.unpatch_dataset_class()
dataset = f[dataset_name]
slice_ = dataset[150:, 150:]
print("Slice from dataset:", slice_, sep='\n')
print("Slice from input array:", data[150:, 150:], sep='\n')
b2h5py.patch_dataset_class() # back to normal

0 comments on commit 85cc9e6

Please sign in to comment.