-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic support for builtin H5 filters
So far implemented are: - zlib - szip (if available in h5 dll) Soon to be implemented extern filters: - blosc To be implemented h5 filters: - shuffle - nbits - fletcher32 - scale offset
- Loading branch information
Showing
4 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import sequtils | ||
import hdf5_wrapper | ||
|
||
import datatypes | ||
import H5nimtypes | ||
|
||
const SzipPixPerBlockSeq = toSeq(0'u8 .. 32'u8).filterIt(it mod 2 == 0) | ||
const ZlibCompressionLevel = {0 .. 9} | ||
# define allowed values for the Szip pixels per block (even values < 32) | ||
var tempSet {.compileTime.}: set[uint8] = {} | ||
static: | ||
for x in SzipPixPerBlockSeq: | ||
tempSet.incl x | ||
const SzipPixPerBlockSet = tempSet | ||
|
||
type | ||
H5FilterKind* = enum | ||
fkNone, fkSzip, fkZlib, fkBlosc | ||
|
||
SzipOptionMask* {.pure.} = enum | ||
EntropyCoding = H5_SZIP_EC_OPTION_MASK | ||
NearestNeighbor = H5_SZIP_NN_OPTION_MASK | ||
|
||
H5Filter* = object | ||
case kind*: H5FilterKind | ||
of fkSzip: | ||
optionMask*: SzipOptionMask | ||
pixPerBlock*: int | ||
of fkZlib: | ||
zlibLevel*: int | ||
of fkBlosc: | ||
bloscLevel*: int | ||
of fkNone: | ||
# if no filter used, empty object | ||
discard | ||
|
||
proc setFilters*(dset: H5DataSet, filter: H5Filter) = | ||
## parses the given `filter` and sets the dataset creation property list | ||
## accordingly | ||
## raises: | ||
## HDF5LibraryError: if a call to a H5 lib function fails | ||
## ValueError: | ||
## - if a `pixPerBlock` field of an Szip filter is invalid | ||
## (uneven or larger 32) | ||
## - if `zlibLevel` notin {0 .. 9} | ||
var status: herr_t = 0 | ||
|
||
case filter.kind | ||
of fkSzip: | ||
if filter.pixPerBlock.uint8 notin SzipPixPerBlockSet: | ||
raise newException(ValueError, "Invalid `pixPerBlock` value for SZip " & | ||
"compression. Valid values are even, positive integers <= 32") | ||
status = H5Pset_szip(dset.dcpl_id, filter.optionMask.cuint, filter.pixPerBlock.cuint) | ||
of fkZlib: | ||
if filter.zlibLevel notin ZlibCompressionLevel: | ||
raise newException(ValueError, "Invalid `zlibLevel` compression value Zlib " & | ||
"compression. Valid values are {0 .. 9}") | ||
status = H5Pset_deflate(dset.dcpl_id, filter.zlibLevel.cuint) | ||
of fkBlosc: | ||
raise newException(NotImplementedError, "Blosc support not yet implemented!") | ||
of fkNone: | ||
discard | ||
|
||
if status < 0: | ||
raise newException(Hdf5LibraryError, "Call to hdf5 library failed in " & | ||
"`setFilters` trying to set " & $filter.kind & " filter.") |