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)
        SMAP_image = ProductIO.readProduct(image_path)
        WKTReader = snappy.jpy.get_type('com.vividsolutions.jts.io.WKTReader')
        wkt="POLYGON((-80 43, -87 43, -87 33, -80 33,-80 43 ))"

        geom = WKTReader().read(wkt)
        HashMap = jpy.get_type('java.util.HashMap')
        GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()
        parameters = HashMap()
        parameters.put('copyMetadata', True)
        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:

95727 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95727 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95743 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95743 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95743 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95743 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95760 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95760 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95765 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95765 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95765 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95765 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95781 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95781 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95781 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95781 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95796 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95796 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95796 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95796 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95812 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95812 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95812 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95812 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95827 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95827 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95827 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95827 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
95827 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 72 at filePos 21865640
95843 [main] ERROR ucar.nc2.iosp.hdf5.H5header - bad version 68 at filePos 21865641
WARNING: org.esa.snap.dataio.netcdf.util.MetadataUtils: Missing configuration property ‘snap.dataio.netcdf.metadataElementLimit’. Using default (100).

How can I solve this problem ?

Thank you

Fabiano

I’m not sure about this problem.
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