Search code examples
juliahdf5

Open HDF5 files in Julia


I have Julia 1.7.2 and HDF v"0.16.2" on a Windows 10 machine. I ran into an issue opening an HDF5 file:

using HDF5
raw_hdf_data = h5open("Data_2021-03-17_11-21-19.h5", "r")  
obj = raw_hdf_data["Group"]["Data_1"]
HDF5.read(obj)

but got an error:

HDF5.API.H5Error: Error reading dataset /Flatfield/Data_1
libhdf5 Stacktrace:
[1] H5PL__find_plugin_in_path: Plugin for dynamically loaded library/Can't open directory or file
can't open directory

[11] H5Dread: Dataset/Read failed
can't read data

Stacktrace:
[1] macro expansion @ C:\Users\jhsu.julia\packages\HDF5\auFb7\src\api\error.jl:18 [inlined]
[2] h5d_read(dataset_id::HDF5.Dataset, mem_type_id::HDF5.Datatype, mem_space_id::HDF5.Dataspace, file_space_id::HDF5.Dataspace, xfer_plist_id::HDF5.DatasetTransferProperties, buf::Matrix{Int64}) @ HDF5.API C:\Users\jhsu.julia\packages\HDF5\auFb7\src\api\functions.jl:508

[3] generic_read(::HDF5.Dataset, ::HDF5.Datatype, ::Type{Int64}) @ HDF5 C:\Users\jhsu.julia\packages\HDF5\auFb7\src\HDF5.jl:978
[4] read(obj::HDF5.Dataset) @ HDF5 C:\Users\jhsu.julia\packages\HDF5\auFb7\src\HDF5.jl:878
[5] (::var"#66#67")(fid::HDF5.File) @ Main .\In[68]:3
[6] h5open(::var"#66#67", ::String, ::Vararg{String, N} where N; swmr::Bool, pv::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ HDF5 C:\Users\jhsu.julia\packages\HDF5\auFb7\src\HDF5.jl:287
[7] h5open(::Function, ::String, ::String) @ HDF5 C:\Users\jhsu.julia\packages\HDF5\auFb7\src\HDF5.jl:285
[8] top-level scope @ In[68]:1
[9] eval @ .\boot.jl:360 [inlined]
[10] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String) @ Base .\loading.jl:1116

Thanks very much!


Solution

  • I had the same issue when I updated my HDF5 library.
    Probably the file is compressed and one of the following plugins are necessary. Try:

    ] add H5Zblosc, H5Zbzip2, H5Zlz4, H5Zzstd
    using HDF5, H5Zblosc, H5Zbzip2, H5Zlz4, H5Zzstd
    raw_hdf_data = h5open("Data_2021-03-17_11-21-19.h5", "r")  
    ...
    

    Now it should open the file.