Most code should add the Blosc2 filter with
hdf5lib_set_blosc2(), which builds its parameters for you;
see Compression & Filters.
This page sets out those parameters, the filter’s
cd_values, for the rare cases that need them: calling
H5Pset_filter() yourself, or reading the list
H5Pget_filter_by_id() returns for a dataset.
The plugin’s cd_values follow the layout of the
reference HDF5-Blosc2 filter (the one hdf5plugin, PyTables
and The HDF Group build) slot for slot, so other implementations can
read, describe and append to hdf5lib’s datasets. The
reference has room for a single pre-filter and no codec parameters, so
the plugin packs the rest of its settings, the whole pre-filter pipeline
and one parameter byte, into cd_values[0], which the
reference only uses for its revision number and never reads.
The layout
-
Filter ID:
32026 -
Elements (
cd_nelmts): 7
| Slot | You pass | The plugin stores |
|---|---|---|
cd_values[0] |
The packed settings below | The same, less anything that does not run (see below) |
cd_values[1] |
0 |
0: Blosc2 picks the block size |
cd_values[2] |
0 |
The item size in bytes |
cd_values[3] |
0 |
The chunk size in bytes |
cd_values[4] |
Compression level, 0 to 9
|
The same, or 255 for a dataset a ZFP codec cannot
take |
cd_values[5] |
0, or the code of the last pre-filter |
The code of the last pre-filter |
cd_values[6] |
Codec | The same |
cd_values[7], [8...]
|
Nothing | The chunk rank and shape, for chunks compressed as B2ND arrays |
The packed settings in cd_values[0]:
| Bits | Contents |
|---|---|
| 31-24 |
0xB2, marking the value as hdf5lib’s |
| 23-20 | Layout version, 1
|
| 19-16 | Pre-filter bitmask |
| 15-8 | Meta value |
| 7-0 |
1, the reference filter’s revision |
That is,
cd_values[0] = 0xB2100001 + (bitmask << 16) + (meta << 8),
where the bitmask and meta value are hdf5lib_set_blosc2()’s
prefilters and meta. The bitmask is the sum of
1 (shuffle), 2 (bitshuffle), 4
(delta) and 8 (trunc-prec), the values of
HDF5LIB_BLOSC2_SHUFFLE and the rest. A negative meta value
goes in as its 8-bit equivalent, 256 + meta:
-3 is 253 (0xFD). Compression & Filters explains
what each pre-filter and meta value does.
-
cd_values[4]: Compression level (0to9). A higher level makesH5Dcreate2()fail; the plugin itself records255for a dataset a ZFP codec cannot take, so that every chunk is stored unfiltered. -
cd_values[5]: the last pre-filter that runs, as a single Blosc2 filter code, which is what the reference filter keeps in this slot:2if the bitmask has bitshuffle, else1if shuffle, else3if delta, else4if trunc-prec, else0. The plugin works it out from the bitmask, so pass0or that code; any other value makesH5Dcreate2()fail with a message naming the code expected. -
cd_values[6]: the codec, ashdf5lib_set_blosc2()’scodec(0=blosclz,1=lz4,2=lz4hc,4=zlib,5=zstd,32=ndlz,33=zfp_acc,34=zfp_prec,35=zfp_rate).
The list the plugin stores records only what runs, so it may differ
from the one you passed. The ZFP codecs and NDLZ skip the pre-filters,
so their bitmask and cd_values[5] are stored as
0. With bitshuffle, the shuffle bit is dropped;
truncate-precision is dropped on data it cannot take, or when it would
keep every bit. The meta value is stored as 0 when nothing
reads it, and NDLZ’s as 4 or 8. For chunks of
2 to 16 dimensions the plugin adds the rank and shape in
cd_values[7] onwards, as the reference does, except for
array datatypes, which it compresses as plain Blosc2, and ZFP chunks of
more than 4 dimensions or with a dimension under 4, which it compresses
as one long row. NDLZ always records the 2-D byte image it compresses.
Values you pass after cd_values[6] are ignored.
Example
Truncating floats to 16 bits of precision, applying Bitshuffle, and
compressing with LZ4 at level 5, which hdf5lib_set_blosc2()
sets up as:
hdf5lib_set_blosc2(plist_id, H5Z_FLAG_MANDATORY, HDF5LIB_BLOSC2_LZ4, 5,
HDF5LIB_BLOSC2_TRUNC_PREC | HDF5LIB_BLOSC2_BITSHUFFLE, 16);The same, passed to H5Pset_filter() directly:
Lists in other forms
The plugin reads cd_values[0] to tell what kind of list
it was handed, both from your H5Pset_filter() call and from
a creation property list copied from another dataset (as
h5repack and H5Dget_create_plist() hand them
on), and converts each to the layout above:
-
0: the form earlier versions ofhdf5libdocumented, still accepted:{ 0, 0, 0, 0, level, bitmask, codec, meta }, with the pre-filter bitmask incd_values[5]and the meta value as an optional 8th value. The example above in this form is{ 0, 0, 0, 0, 5, 10, 1, 16 }, and it stores exactly the same list. Herecd_values[5]is still the bitmask, not a filter code. The option tupleshdf5plugin’sBlosc2()builds also start with0, so they are read this way too, and two of its codes mean something else:3(itsDELTA) is shuffle + bitshuffle, so bitshuffle, and4(itsTRUNC_PREC) is delta. Passing no values at all also lands here: level 5, shuffle, BloscLZ. -
1: the reference filter’s own lists, such as a creation property list copied from a dataseth5pywrote.cd_values[5]is one filter code (0none,1shuffle,2bitshuffle,3delta,4trunc-prec); there is no meta value, so trunc-prec failsH5Dcreate2()on native floats (it has no precision to keep) and NDLZ uses 4 x 4 cells. Any other code failsH5Dcreate2(). -
2: lists stored byhdf5lib2.1.1.0 to 2.2.0.0 (and development builds of 2.2.0.1): the bitmask in the low byte ofcd_values[5], and the meta value in its next byte (lists of 7 values) or after the chunk shape. -
0xB2...: the layout above. A layout version other than1failsH5Dcreate2().
Any other cd_values[0] fails H5Dcreate2().
When the plugin compresses chunks for a dataset already in a file, such
as one being appended to, it reads the stored list the same way: a
dataset an earlier hdf5lib wrote keeps the settings it
recorded, and one another implementation wrote gets the single
pre-filter its cd_values[5] names, as the reference filter
would run it. It refuses to compress with a layout version it does not
know. Reading does not depend on any of these settings, because every
Blosc2 chunk records its own pre-filters, codec and parameters.
