SoFunction
Updated on 2024-10-30

python visualization hdf5 file manipulation

For some complex hdf5 files, through the visualization method can be relatively easy to understand the internal structure of the file, the following introduces a python based on the installation of the hdf5 file using methods

1 Install the vitables toolkit

The command pip install vitables

2 After the installation is complete, use the command in the terminal

vitables filename.hdf5

The final realization of the hdf5 file visualization , convenient and intuitive as a layer of open folders like

Addendum: python's operations for HDF5

Look at the code.

    import h5py  #Import Toolkit
    import numpy as np  
    #HDF5 writes:
    imgData = ((30,3,128,256))  
    f = ('HDF5_FILE.h5','w')   # Create an h5 file with a file pointer of f
    f['data'] = imgData                 # Write data to the file under the primary key data
    f['labels'] = range(100)            # Write the data to the file under the primary key labels
    ()                           # Close the file
      
    #HDF5 reads:
    f = ('HDF5_FILE.h5','r')   #open h5 file
    ()                            # You can see all the primary keys: in this case: [data],[label].
    a = f['data'][:]                    # Take out all the keys whose primary key is data
    ()  

Supplementary: on the python environment hdf5 error reporting problems of several solutions (pro-test)

I. The error is reported as follows:

Warning! HDF5 library version mismatched error
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as ‘LD_LIBRARY_PATH'.
You can, at your own risk, disable this warning by setting the environment
variable ‘HDF5_DISABLE_VERSION_CHECK' to a value of ‘1'.
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.10.4, library is 1.10.5

II. Several solutions

First of all, the problem is that it is possible that the hdf5 library does not match the problem, it is also possible that it is something like a WARNING, I will talk about it in detail below.

First solution:

Uninstall hdf5 and reinstall it.

The code executed by the terminal is as follows:

conda uninstall hdf5
conda install hdf5

There are a lot of people on the Internet who use this method to help, I personally test: the method does not work for me.

Second solution:

Check the path to the setting: LD_LIBRARY_PATH

I personally test: because I use the system is win10, but LD_LIBRARY_PATH this path I looked for a long time and could not find, and then searched and found when the Linux, so this method I did not use.

Third solution:

Set HDF5_DISABLE_VERSION_CHECK to a higher level to ignore warnings.

Before importing tensorflow, add the following code to the code:

import os;
[‘HDF5_DISABLE_VERSION_CHECK'] = ‘2'

I personally test: this method is really useful!

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.