Thursday, July 2, 2015

HDF5 quick start

1. Exampkle of creating a HDF5 file 
!/usr/bin/python
# Import module
import unittest
import sys
import h5py
import os
import numpy

# Create a HDF file handle.
f = h5py.File('myfile.hdf5', 'w')

# 2-D array
d1 = f.create_dataset("d1", (2,2), 'i')
#d7 = f.create_dataset("d7", (2,2), 'i')
d1[...] = 42

# 1-D array
d6 = f.create_dataset("d6", (1,), 'i')
d3 = f.create_dataset("d3", (2,), 'i')

# Assign values to array elements of each datasets. 
#d3[...] = 30
d3[0] = 30
d3[1] = 40


print d1
print d6
print d3
print d3[0]
print d3.len()

# Close the HDF file
f.close()

2. Example of reading a HDF5 file
!/usr/bin/python
import unittest
import sys
import h5py
import os
import numpy


listOfParams=["PARAM_1, "PARAM_2"]

fh =h5py.File('abc.hdf', 'r')

for i in range(203):
   ds=fh["/sub_dir_1/sub_dir_2/"+listOfParams[i]]
   print listOfParams[i] ,  ds[0]

fh.close()


3. HDF5 utilities 
-----------------------------------------
1. Most used utlitiles
-----------------------------------------
$ h5diff  a1.hdf   a2.hdf
$ h5dump  a1.hdf        // Display content
$ h5dump  -d  /sub_dir_1/sub_dir_2/SMALL_VALUE_THRESHOLD    abc.hdf
$ h5stat  a1.hdf
$ h5mkgrp a1.hdf  G1   G1/G11  G1/G11/G111  G1/G12
$ h5ls  abc.hdf
$ h5ls  abc.hdf/sub_dir_1/sub_dir_2/
$ ncdump -h a1.nc    // Display header information

-------------------------------
2. View and edit
-------------------------------
hdfview
$ hdfview  abc.hdf

h5dump  
$ h5dump  -H    abc.hdf
$ h5dump  -d    /sub_dir_1/sub_dir_2/SMALL_VALUE_THRESHOLD    abc.hdf

h5stat
h5ls          
h5diff   
h5copy :
h5copy man page :   http://manned.org/h5copy/c4949885
$  h5copy  -i  abc.dmi   -o deyong.dmi   -s  Depth550 -d aod550

h5mkgrp       
h5import 
h5repart

--------------------------------------------------------
3. Convet to or from gif files.
--------------------------------------------------------
gif2h5
h52gif 

----------------------------------------------------------------------
4. Compile codes to manipulate hdf5
----------------------------------------------------------------------
h5c++  
h5cc   
h5fc     

----------------------------------------
5. Advanced topics
----------------------------------------
h5debug  
h5jam         
h5unjam
h5repack
h5redeploy    
h5perf_serial 


No comments:

Post a Comment