Does anyone know how to make the modification of the following code so that I can read the specific z component slice of 3D hdf data in Python? As you can see from the attached image, z value spans from 0 to 160 and I want to plot the '80' only. And the dimension is 400x160x160. Here is my code.
import h5handler as h5h
h5h.manager.setPath('E:\data\Data5', False)
for i in np.arange(0,1,5000):
cycleFile = h5h.CycleFile(h5h.manager.cycleFiles['cycle_'+str(i)+'.hdf'], 'r')
fig = plt.figure()
fig.suptitle('Cycle_'+str(i)+' at t=14.4s', fontsize=20)
ax1 = plt.subplot(311)
ax2 = plt.subplot(312)
ax3 = plt.subplot(313)
Bx = np.reshape(cycleFile.get('/fields/Bx').value.T, (160,400))*6.872130320978866e-06*(1e9)
I would guess from the name that h5handler is a tool meant for working with HDF5 (.h5) files, whereas the file you appear to be working with is an HDF4 or HDF-EOS (.hdf) file. The two libraries for working with HDF4 files are pyhdf (http://pysclint.sourceforge.net/pyhdf/documentation.html) and pyNIO (https://www.pyngl.ucar.edu/Nio.shtml).
If you choose to use pyhdf, you can read your slice of data as follows:
If you choose to use pyNIO, you can read your slice of data as follows:
Hope that helps!