-
Notifications
You must be signed in to change notification settings - Fork 143
/
filter.jl
85 lines (64 loc) · 2.06 KB
/
filter.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using HDF5
using HDF5.Filters
using Test
using H5Zblosc, H5Zlz4, H5Zbzip2, H5Zzstd
@testset "filter" begin
# Create a new file
fn = tempname()
# Create test data
data = rand(1000, 1000)
# Open temp file for writing
f = h5open(fn, "w")
# Create datasets
dsdeflate = create_dataset(f, "deflate", datatype(data), dataspace(data),
chunk=(100, 100), deflate=3)
dsshufdef = create_dataset(f, "shufdef", datatype(data), dataspace(data),
chunk=(100, 100), shuffle=true, deflate=3)
dsfiltdef = create_dataset(f, "filtdef", datatype(data), dataspace(data),
chunk=(100, 100), filters=Filters.Deflate(3))
dsfiltshufdef = create_dataset(f, "filtshufdef", datatype(data), dataspace(data),
chunk=(100, 100), filters=[Filters.Shuffle(), Filters.Deflate(3)])
# Write data
write(dsdeflate, data)
write(dsshufdef, data)
write(dsfiltdef, data)
write(dsfiltshufdef, data)
# Test compression filters
compressionFilters = Dict(
"blosc" => BloscFilter,
"bzip2" => Bzip2Filter,
"lz4" => Lz4Filter,
"zstd" => ZstdFilter
)
for (name, filter) in compressionFilters
ds = create_dataset(
f, name, datatype(data), dataspace(data),
chunk=(100,100), filters=filter()
)
write(ds, data)
ds = create_dataset(
f, "shuffle+"*name, datatype(data), dataspace(data),
chunk=(100,100), filters=[Filters.Shuffle(), filter()]
)
write(ds, data)
end
# Close and re-open file for reading
close(f)
f = h5open(fn)
# Read datasets and test for equality
for name in keys(f)
ds = f[name]
@testset "$name" begin
@debug "Filter Dataset" HDF5.name(ds)
@test ds[] == data
filters = HDF5.get_create_properties(ds).filters
if startswith(name, "shuffle+")
@test filters[1] isa Shuffle
@test filters[2] isa compressionFilters[name[9:end]]
elseif haskey(compressionFilters, name)
@test filters[1] isa compressionFilters[name]
end
end
end
close(f)
end # @testset "filter"