Read Specific Z Component Slice Of 3d Hdf From Python
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 ima
Solution 1:
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:
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]
If you choose to use pyNIO, you can read your slice of data as follows:
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]
Hope that helps!
Post a Comment for "Read Specific Z Component Slice Of 3d Hdf From Python"