|
| 1 | +####################################################################### |
| 2 | +# Copyright (c) 2019-present, Blosc Development Team <[email protected]> |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under a BSD-style license (found in the |
| 6 | +# LICENSE file in the root directory of this source tree) |
| 7 | +# |
| 8 | +# This example can only be run if blosc2-btune is installed. You can |
| 9 | +# get it from https://pypi.org/project/blosc2-btune/ |
| 10 | +# For more info on this tuner plugin see |
| 11 | +# https://github.com/Blosc/blosc2_btune/blob/main/README.md |
| 12 | +####################################################################### |
| 13 | + |
| 14 | +import numpy as np |
| 15 | + |
| 16 | +import blosc2 |
| 17 | +import blosc2_btune |
| 18 | + |
| 19 | +nchunks = 10 |
| 20 | +# Set the compression and decompression parameters, use BTUNE tuner |
| 21 | +cparams = {"codec": blosc2.Codec.LZ4HC, "typesize": 4, "tuner": blosc2.Tuner.BTUNE} |
| 22 | +dparams = {} |
| 23 | +contiguous = True |
| 24 | +urlpath = "filename" |
| 25 | + |
| 26 | +storage = {"contiguous": contiguous, "urlpath": urlpath, "cparams": cparams, "dparams": dparams} |
| 27 | +blosc2.remove_urlpath(urlpath) |
| 28 | + |
| 29 | +# Set the Btune configuration to use |
| 30 | +btune_conf = {"tradeoff": 0.3, "perf_mode": blosc2_btune.PerformanceMode.DECOMP} |
| 31 | +blosc2_btune.set_params_defaults(**kwargs) |
| 32 | + |
| 33 | +# Create the SChunk |
| 34 | +data = np.arange(200 * 1000 * nchunks) |
| 35 | +schunk = blosc2.SChunk(chunksize=200 * 1000 * 4, data=data, **storage) |
| 36 | + |
| 37 | +# Check data can be retrieved correctly |
| 38 | +data2 = np.empty(data.shape, dtype=data.dtype) |
| 39 | +schunk.get_slice(out=data2) |
| 40 | +assert np.array_equal(data, data2) |
| 41 | + |
| 42 | +blosc2.remove_urlpath(urlpath) |
0 commit comments