Reading HDF4 Files

Hi! As someone who needs to read in HDF4 files from TRMM and MODIS, I am trying to find a workaround in Julia using PyCall. However, I’m having some problems with loading the data.

fhdf = pyhdf.SDS(“3B42.20130909.00.7.HDF”,"/Grid/precipitation");

PyObject <bound method of <pyhdf.SD.SDS object at 0x1a45e318d0>>

i.e. a python object. Is there anyone who has the expertise and who has used pyhdf to read files to tell me how to access the data inside the python object?

Update: I found the solution which is to use PyCall’s “get” function. But “get” is very irritating because it only allows me to retrieve one element at a time, so I have to do a for loop as follows:

dobj = h4read(file,variable); data = zeros(1440,400)
for ii = 0 : 1439
for jj = 0 : 399
data[ii+1,jj+1] = get(dobj,(ii,jj));

Does anyone know if there is an effort to parallelize or optimize this so that I can read in the whole chunk instead of calling it one by one because I’m sure there’s significant overhead as a result haha.

You can read MODIS data via GMT.jl. See first block in this example

But this is HDF5. I need to read HDF4. Even if it is not MODIS, I have other datasets that store as HDF4 and not HDF5.

HDF4 should work as well. The key is GDAL. GMT uses it to read these type of files. If GDAL was compiled with HDF4 support (the GMT windows installer comes with one GDAL linked with HDF4) then it should work.

Alright thanks.

Now to get GMT to work on my julia installation, lol.

Ah, yes! (switch to Windows :slight_smile:). Seriously, that homebrew link I posted should work flawlessly, but I’m not sure if uses a HDF4 aware GDAL