Error when reprojecting in snappy

Hi, I am trying to reproject some images with snappy but so far I have not been successful. The code is as follows:

parameters = HashMap()
parameters.put('crs', 'EPSG:4326')
parameters.put('noDataValue', -9999.)
parameters.put('addDeltaBands', False)
GPF.createProduct("Reproject", parameters, img_read)

The error I’m getting is:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-4-ee60cbc83b7e> in <module>
      3 parameters.put('noDataValue', -9999.)
      4 parameters.put('addDeltaBands', False)
----> 5 GPF.createProduct("Reproject", parameters, img_read)

RuntimeError: java.lang.IllegalArgumentException: expression: Missing ')'.

I can run other functions without problem but not this one.

Thank you for any help you can give me.

greetings

You should give us enough information so someone can try to reproduce the issue (platform, SNAP version, complete script, example data set, etc.). A
Missing ')'” error could be caused by typographic or formatting errors that we can’t see in your snippet. If GPF.createProduct(..., img_read) is the last line in the file it could be as simple as missing a “newline” character after the closing parenthesis.

Hi, thank you for your answer.

An example script and an image are available at this link.

This is what I’m using:

SNAP version: 8.0.8
Operating system: Ubuntu 18
JDK version: 11
jpy-0.10.0.dev1-cp36-cp36m-linux_x86_64.whl

jpy was compiled from GitHub - bcdev/jpy: A bi-directional Python-Java bridge used to embed Java in CPython or the other way round.

Thank you so much for any help.

Your example works for me (using SNAP 8.0.8 on Windows 10, ) , after changing the file name in the script to the name of the example file. The edited script is called snappy_reproject.py, and also sets the path to the ESA SNAP snappy directory so I don’t run into conflicts with one of the other “snappy” packages. Normally I would try your script in Ubuntu 18, but I’m in the process of reconfiguring my systems.

Without the NASA SeaDAS plugin SNAP fails to read the metadata because it tries to use the sttbx reader (I added the .nc extension in the hope that SNAP would use a more generic NetCDF4-CF reader).

PS D:\SNAP_Forum\snappy_reproject> ren .\A2020_02_10_173000_nir.L2_LAC_OC .\A2020_02_10_173000_nir.L2_LAC_OC.nc
PS D:\SNAP_Forum\snappy_reproject> py -3.6 .\snappy_reproject.py
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: GDAL not found on system. Internal GDAL 3.0.0 from distribution will be used. (f1)
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
SEVERE: org.esa.snap.core.dataio.ProductIO: Error attempting to read A2020_02_10_173000_nir.L2_LAC_OC.nc with plugin reader org.esa.s1tbx.io.risat1.Risat1ProductReaderPlugIn@365cdacf
java.lang.NullPointerException
        at org.esa.s1tbx.io.risat1.Risat1ProductReaderPlugIn.findMetadataFile(Risat1ProductReaderPlugIn.java:61)
        at org.esa.s1tbx.io.risat1.Risat1ProductReaderPlugIn.findMetadataFile(Risat1ProductReaderPlugIn.java:80)
        at org.esa.s1tbx.io.risat1.Risat1ProductReaderPlugIn.getDecodeQualification(Risat1ProductReaderPlugIn.java:44)
        at org.esa.snap.core.dataio.ProductIO.getProductReaderForInput(ProductIO.java:304)
        at org.esa.snap.core.dataio.ProductIO.readProductImpl(ProductIO.java:255)
        at org.esa.snap.core.dataio.ProductIO.readProduct(ProductIO.java:207)

Nombre de las bandas que contiene: ['Rrs_412', 'Rrs_443', 'Rrs_488', 'Rrs_555', 'Rrs_645', 'Rrs_667', 'Rrs_859', 'Rrs_869', 'angstrom', 'aot_412', 'aot_443', 'aot_488', 'aot_555', 'aot_667', 'aot_869', 'chl_oc2', 'chl_oc3', 'nLw_412', 'nLw_443', 'nLw_488', 'nLw_555', 'nLw_667', 'nLw_869', 'l2_flags', 'longitude', 'latitude']
INFO: org.hsqldb.persist.Logger: dataFileCache open start

100% done.
Nombre de las bandas que contiene: ['Rrs_412', 'Rrs_443', 'Rrs_488', 'Rrs_555', 'Rrs_645', 'Rrs_667', 'Rrs_859', 'Rrs_869', 'angstrom', 'aot_412', 'aot_443', 'aot_488', 'aot_555', 'aot_667', 'aot_869', 'chl_oc2', 'chl_oc3', 'nLw_412', 'nLw_443', 'nLw_488', 'nLw_555', 'nLw_667', 'nLw_869', 'l2_flags', 'longitude', 'latitude']type or paste code here

I then installed the NASA SNAP SeaDAS Toolbox which is meant for an earlier SNAP version. This appears to work, but there is a conflict due to different SL4J bindings.

PS D:\SNAP_Forum\snappy_reproject> py -3.6 .\snappy_reproject.py
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: GDAL not found on system. Internal GDAL 3.0.0 from distribution will be used. (f1)
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/gwhite/AppData/Roaming/SNAP/modules/ext/org.esa.snap.snap-netcdf/org-slf4j/slf4j-simple.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/gwhite/AppData/Roaming/SNAP/modules/ext/gov.nasa.gsfc.seadas.seadas-processing/org-slf4j/slf4j-log4j12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
Nombre de las bandas que contiene: ['Rrs_412', 'Rrs_443', 'Rrs_488', 'Rrs_555', 'Rrs_645', 'Rrs_667', 'Rrs_859', 'Rrs_869', 'angstrom', 'aot_412', 'aot_443', 'aot_488', 'aot_555', 'aot_667', 'aot_869', 'chl_oc2', 'chl_oc3', 'nLw_412', 'nLw_443', 'nLw_488', 'nLw_555', 'nLw_667', 'nLw_869', 'l2_flags', 'longitude', 'latitude']
log4j:WARN No appenders could be found for logger (hsqldb.db.HSQLDB4AD417742A.ENGINE).
log4j:WARN Please initialize the log4j system properly.

100% done.
Nombre de las bandas que contiene: ['Rrs_412', 'Rrs_443', 'Rrs_488', 'Rrs_555', 'Rrs_645', 'Rrs_667', 'Rrs_859', 'Rrs_869', 'angstrom', 'aot_412', 'aot_443', 'aot_488', 'aot_555', 'aot_667', 'aot_869', 'chl_oc2', 'chl_oc3', 'nLw_412', 'nLw_443', 'nLw_488', 'nLw_555', 'nLw_667', 'nLw_869', 'l2_flags', 'longitude', 'latitude']

Can you try running snappy with OpenJDK JRE 8 and jpy-0.9.0?

Hello, I tried the tests you suggested, I even reinstalled snap and updated it to test with openjdk-8 and jpy-0.9.0 but the result is always the same. I leave you the last run after installing even the seadas plugin.

INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: GDAL 2.2.3 found on system. JNI driver will be used.
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/andres/snap/snap/modules/ext/org.esa.snap.snap-netcdf/org-slf4j/slf4j-simple.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/andres/.snap/system/modules/ext/gov.nasa.gsfc.seadas.seadas-processing/org-slf4j/slf4j-log4j12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
Nombre de las bandas que contiene: ['angstrom', 'aot_412', 'aot_443', 'aot_488', 'aot_555', 'aot_667', 'aot_869', 'nLw_412', 'nLw_443', 'nLw_488', 'nLw_555', 'nLw_667', 'nLw_869', 'l2_flags', 'longitude', 'latitude']
log4j:WARN No appenders could be found for logger (hsqldb.db.HSQLDB4AD417742A.ENGINE).
log4j:WARN Please initialize the log4j system properly.
Traceback (most recent call last):
  File "prueba.py", line 24, in <module>
    reproject = fn_reproject(img_read)
  File "prueba.py", line 21, in fn_reproject
    projected = GPF.createProduct("Reproject", parameters, product)
RuntimeError: java.lang.IllegalArgumentException: expression: Missing ')'.

However, the reprojection works fine if I do it directly in snap but this would not be the idea :S

NASA SeaDAS 8 (based on ESA SNAP 8) does not yet support GPT, but it was worth a try in SNAP. I think the NASA SeaDAS toolbox is needed to properly handle the MODIS metadata. Can you use the NASA OCSSW (see the section titled “Manual iinstallation” to download install_ocssw with tag=v2021.2 or later) command-line tools? NASA OCSSW has l2mapgen, which runs l2bin and then l3mapgen. This has some statistical advantages over directly mapping level-2 files, but previous versions would produce Moiré patterns near pass edges in areas with only a single pass. The current version uses a more sophisticated algorithm that can eliminate the Moiré patterns.

If the result layer doesn’t line up with the basemap, it’s probably not set to its native CRS. Change the CRS in the layer properties. Try different CRS’s until you find the one that makes it line up with the basemap. Only when the layer has its native CRS can you re-project it into the CRS you want.
MyBalanceNow

Thank you very much for your answers, finally the solution was to use NASA SeaDAS toolbox.