Snap 10 with Python 3.10 is not loading latest S2A products (windows 11)

Hi,
I just updated to Snap10 and from Python 3.6 to 3.10 running on Windows 11, and it seems to have unleased lots of issues which I’m trying to work through.

I have an existing codebase that has been running happily for several years, opening S2 A and B products, resampling, zooming, pulling out band data etc…

Firstly the basic install worked fine and I can open some products using esa_snappy so no fundamental issue with setup.

But all of the most recent S2B_MSIL2A products throw this error:

Error reading product: java.io.IOException: Unable to read metadata from MTD_MSIL2A.xml
(this is actually what caused me to upgrade, as all the new products coming in started failing)

Older products still open, but when I try and resample and resize I am now getting this error: (there could be more issues but that is where my script crashes)

Exception has occurred: RuntimeError

org.esa.snap.core.gpf.OperatorException: Operator ‘ResamplingOp’: Value for ‘Target height’ must be of type ‘Integer’.
with this code:
targetWidth = int(targetWidth)
targetHeight = int(targetHeight)
parameters.put(‘targetWidth’, targetWidth)
parameters.put(‘targetHeight’, targetHeight)
resampled = GPF.createProduct(‘Resample’, parameters, product)

targetWidth and Height are 800,800, so definitely integers.

I’m not sure if something in this interface has changed or what, but I can replicate both of these issue in a simply python test file.

Any help would be greatly appreciated:

Python test code pasted below:

import sys
import numpy as np
import esa_snappy
from esa_snappy import ProductIO, HashMap, GPF

def resize(product, targetWidth, targetHeight):    
    parameters = HashMap()   
    parameters.put('targetWidth', targetWidth)
    parameters.put('targetHeight', targetHeight)
    resampled = GPF.createProduct('Resample', parameters, product)
    print("Resized image to {} by {}".format(targetWidth, targetHeight))
    return resampled

file = "c:/code/aquaspatial/py/S2A_MSIL2A_20180112T021911_N0500_R060_T50HMJ_20230802T065254.zip"
# this one fails to open - comment in
#file = "c:/code/aquaspatial/py/S2B_MSIL2A_20240724T223709_N0511_R072_T59GLL_20240725T020713.zip"

product = None
try:
    product = ProductIO.readProduct(file)
except Exception as e:
    print("Error reading product: ", e)
    sys.exit(1)

if product is None:
    print("Product is None")
    sys.exit(1)

bands = product.getBandNames()
for band in bands:
    print(band)

# try a resize
zoomedIn = resize(product, 800,800)

This issue is already tracked, and they work on it already.

Thanks for that update, yeah I saw that one and was tempted to post there, but with the additional problem with the Resample I thought it deserved a new topic.

I just reverted to snap 9 and python 3.6 and the above test code works again.
But it does not work with snap 10 and python 3.6. So unlikely to be Python related, hopefully they can fix soon as products are piling up here!

1 Like

someone can help me about radar vegetitoin index

i can’t take hh hv polirisation sentinel how can i take it

A module update (10.0.2) is available for the Optical Toolbox module. Please update your SNAP.

1 Like

Thanks. That update fixes the issue with : Error reading product: java.io.IOException: Unable to read metadata from MTD_MSIL2A.xml

However the issue with attempting to Resample still persists.

    parameters = HashMap()   
    parameters.put('targetWidth', targetWidth)
    parameters.put('targetHeight', targetHeight)
    resampled = GPF.createProduct('Resample', parameters, product)

Error:
RuntimeError: org.esa.snap.core.gpf.OperatorException: Operator ‘ResamplingOp’: Value for ‘Target height’ must be of type ‘Integer’.

The same code works with python 3.6 in snap 9.0.

Please try the following:

Integer = jpy.get_type('java.lang.Integer')
parameters.put('targetWidth', Integer(targetWidth))
parameters.put('targetHeight', Integer(targetHeight))

I don’t understand why it worked before and now not anymore. But the above code should work around the issue.

yes that worked thanks!

I guess something in the default types changed as I have never used that cast before but easy fix for us.

Thanks a lot for your prompt answers on here

1 Like