2014-12-02 71 views
0

3D HDF的具体Z分量片有谁知道如何使下面的代码的修改,这样我可以读取3D HDF数据在Python的具体Z分量分得一杯羹?正如你从附加图像中看到的,z值的范围是从0到160,我只想绘制'80'。尺寸是400x160x160。这是我的代码。阅读从Python的

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) 

enter image description here

回答

0

我会从h5handler是一种工具的名称猜意味着与HDF5工作(.h5)文件,而该文件,你似乎有是HDF4或HDF-EOS合作(.hdf)文件。这两个库与HDF4文件的工作是pyhdf(http://pysclint.sourceforge.net/pyhdf/documentation.html)和pyNIO(https://www.pyngl.ucar.edu/Nio.shtml)。

如果您选择使用pyhdf,您可以读取数据的切片如下:

from pyhdf.SD import * 
import numpy as np 


file_handle = SD("your_input_file.hdf", SDC.READ) 
data_handle = file_handle.select("Bx") 
Bx_data = data_handle.get() #creates a numpy array filled with the data 
Bx_subset = Bx_data[:,:,80] 

如果您选择使用pyNIO,您可以读取数据的切片如下:

import Nio 

file_handle = nio.open_file("your_input_file.hdf", format='hdf') 
Bx_data = file_handle.variables["Bx"][:] #creates a numpy array filled with the data 
Bx_subset = Bx_data[:,:,80] 

希望有所帮助!