# Reading .h5 files with snappy

Dear All,

I have a .h5 file that I can correctly open with SNAP.
However when I try to open it with snappy using this code it doesn’t work:

import os
import snappy
from snappy import ProductIO
from snappy import GPF
from snappy import jpy
from snappy import ProductUtils

images_directory = “C:/…/SMAP/test”
for subdir, dirs, files in os.walk(images_directory):

for filename in files:

if filename.endswith(".h5"):
image_path = os.path.join(images_directory,filename)
wkt="POLYGON((-80 43, -87 43, -87 33, -80 33,-80 43 ))"

HashMap = jpy.get_type('java.util.HashMap')
parameters = HashMap()
parameters.put('geoRegion', geom)
SMAP_image_subset = GPF.createProduct('Subset', parameters, SMAP_image)
ProductIO.writeProduct(SMAP_image_subset, image_path+'_florida', 'NETCDF4-BEAM')


This is the error message that i get:

How can I solve this problem ?

Thank you

Fabiano

Can you check which reader is used in SNAP Desktop when you open it there?
Open the Information Windows (in menu Analysis) and select the product.
Please post a screenshot of this window.

Also helpful could be this information for you. You might need to specify the libraries manually.

For snappy you need to add the two properties to the snappy.ini file.

java_options: -Dncsa.hdf.hdflib.HDFLibrary.hdflib=c:\path\to\jhdf.dll -Dncsa.hdf.hdf5lib.H5.hdf5lib=c:\path\to\jhdf5.dll


Add this line with updated paths to the libraries

Thank you very much for your reply, this is what I get from the information Window:

It also modified the snappy.ini file like you suggested but I get the same error message.

Best regards

Fabiano

Ah, it’s a SMAP file. This is not well supported at all. Even if you could fix the HDF problem.

I see…I will try with some other library then !
Thank you anyway for your time!

Fabiano