I am exporting bands from a Sentinel-2 L1C product to geotiff, with some constraints:
direct export to geotiff (no BEAM-DIMAP!)
limit memory requirements as much as possible (e.g. 60m bands shouldn’t need much)
To achieve this, I’m playing around with all possible parameters that I’m aware of. This revealed a critical issue: some parameter combinations results in empty files (having 0 bytes), without showing errors.
My actual use case is more complex, but the example below shows the issue, using SNAP 7.0. Note that it is very sensitive to the memory and jai tile cache parameters. So by simply changing those, it can be made to work (assuming you feel like doing a lot of trial and error).
[driesj@driesj ~]$ time /usr/local/snap/bin/gpt BandSelect -e -Dsnap.dataio.bigtiff.tiling.width=256 -Dsnap.dataio.bigtiff.tiling.height=256 -Dsnap.jai.defaultTileSize=256 -c 1000M -q 4 -J-Xmx1000M -PsourceBands=B1 -f GeoTIFF-BigTIFF -t B01.tif S2B_MSIL1C_20180418T030539_N0206_R075_T50TMK_20180418T055826.zip
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
SEVERE: org.esa.s2tbx.dataio.gdal.activator.GDALDistributionInstaller: The environment variable LD_LIBRARY_PATH does not contain the current folder '.'. Its value is '/opt/rh/python27/root/usr/lib64'.
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.
INFO: org.esa.s2tbx.dataio.s2.ortho.S2OrthoProductReaderPlugIn: Building product reader - EPSG:32650
WARNING: org.esa.s2tbx.dataio.metadata.GenericXmlMetadata: Metadata: the path to element [metadata_level] does not exist
WARNING: org.esa.s2tbx.dataio.metadata.GenericXmlMetadata: Metadata: the path to element [granuleidentifier] does not exist
WARNING: org.esa.s2tbx.dataio.metadata.GenericXmlMetadata: Metadata: the path to element [bandid] does not exist
INFO: org.hsqldb.persist.Logger: dataFileCache open start
INFO: org.esa.snap.core.gpf.common.WriteOp: Start writing product S2B_MSIL1C_20180418T030539_N0206_R075_T50TMK_20180418T055826 to B01.tif
Writing.....
INFO: org.esa.snap.dataio.bigtiff.BigGeoTiffProductWriter: writing to output file B01.tif
..10%....20%....30%....40%....50%....60%....70%....80%....90%....100% done.
INFO: org.esa.snap.core.gpf.common.WriteOp: End writing product B01 to B01.tif
INFO: org.esa.snap.core.gpf.common.WriteOp: Time: 9.200 s total, 0.838 ms per line, 0.000076 ms per pixel
real 0m21.081s
user 0m44.087s
sys 0m5.674s
Some more relevant info, I got the GDAL based geotiff driver to work. This was non-trivial as the built-in attempts to load native libaries seem to fail. So I had to configure java.library.path myself.
It runs faster, and never resulted in an empty file. However, I cannot set gdal creation option like compression and tile size, so it does not solve my problem in the end, as I’m looking for ways to create a proper geotiff.
This is the full example run:
[driesj@driesj ~]$ LD_LIBRARY_PATH=. /usr/local/snap/bin/gpt BandSelect -e -J-Djava.library.path=/home/driesj/.snap/auxdata/gdal:/home/driesj/.snap/auxdata/gdal/gdal-2.2.0-linux/lib/jni:/home/driesj/.snap/auxdata/gdal/gdal-2.2.0-linux/lib/ -Dsnap.dataio.bigtiff.tiling.width=256 -Dsnap.dataio.bigtiff.tiling.height=256 -Dsnap.jai.defaultTileSize=256 -c 128M -x -q 4 -J-Xmx512M -PsourceBands=B1 -f GDAL-GTiff-WRITER -t B01.tif /data/TERRASCOPE/morpho_v2/unit_test_data/unit_test_data_develop/products/S2B_MSIL1C_20180418T030539_N0206_R075_T50TMK_20180418T055826/input/S2B_MSIL1C_20180418T030539_N0206_R075_T50TMK_20180418T055826.zip
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.s2.ortho.S2OrthoProductReaderPlugIn: Building product reader - EPSG:32650
WARNING: org.esa.s2tbx.dataio.metadata.GenericXmlMetadata: Metadata: the path to element [metadata_level] does not exist
WARNING: org.esa.s2tbx.dataio.metadata.GenericXmlMetadata: Metadata: the path to element [granuleidentifier] does not exist
WARNING: org.esa.s2tbx.dataio.metadata.GenericXmlMetadata: Metadata: the path to element [bandid] does not exist
INFO: org.hsqldb.persist.Logger: dataFileCache open start
INFO: org.esa.snap.core.gpf.common.WriteOp: Start writing product S2B_MSIL1C_20180418T030539_N0206_R075_T50TMK_20180418T055826 to B01.tif
Writing...
....10%....20%....30%....40%....50%.....62%....72%....82%....92%... done.
INFO: org.esa.snap.core.gpf.common.WriteOp: End writing product S2B_MSIL1C_20180418T030539_N0206_R075_T50TMK_20180418T055826 to B01.tif
INFO: org.esa.snap.core.gpf.common.WriteOp: Time: 4.007 s total, 0.365 ms per line, 0.000033 ms per pixel
No, my real use case is not about trying to convert individual bands to geotiff, I also want to apply other snap operations.
I just posted a minimal example that clearly exposes the issue(s), so that it’s easier to debug, and rule out influence from a more complex process graph.
Hi @marpet,
could you give us an idea on whether the proposed fixes could be integrated? We need to integrate this in a processing chain, so it would help a lot if we don’t need to maintain a patched version.
We can always improve the pull request if needed.
Any updates on this? I am experiencing a similar problem but with Sentinel1 data: Graph execution failed with a Geotiff output created but empty after this log:
INFO: org.esa.snap.dataio.bigtiff.BigGeoTiffProductWriter: writing to output file S1A_IW_GRDH_1SDV_20201228T170552_20201228T170617_035889_0433FB_D8C7_SIGMA0_VV_DB.tif
Processing the graph
Picked up _JAVA_OPTIONS: -Xms24g -Xmx24g
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
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.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.
Executing processing graph
INFO: org.hsqldb.persist.Logger: dataFileCache open start
version = 3.31
INFO: org.esa.snap.dataio.bigtiff.BigGeoTiffProductWriter: writing to output file S1A_IW_GRDH_1SDV_20201228T170552_20201228T170617_035889_0433FB_D8C7_SIGMA0_VV_DB.tif
10%20%30%40%50%60%70%.80%90%
Traceback (most recent call last):
File “/srv/conda/envs/env_snap/bin/sar-calibration”, line 33, in
sys.exit(load_entry_point(‘sar-calibration==0.0.1’, ‘console_scripts’, ‘sar-calibration’)())
File “/srv/conda/envs/env_snap/lib/python3.9/site-packages/click/core.py”, line 829, in call
return self.main(*args, **kwargs)
File “/srv/conda/envs/env_snap/lib/python3.9/site-packages/click/core.py”, line 782, in main
rv = self.invoke(ctx)
File “/srv/conda/envs/env_snap/lib/python3.9/site-packages/click/core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/srv/conda/envs/env_snap/lib/python3.9/site-packages/click/core.py”, line 610, in invoke
return callback(*args, **kwargs)
File “/srv/conda/envs/env_snap/lib/python3.9/site-packages/sar_calibration-0.0.1-py3.9.egg/sar_calibration/app.py”, line 33, in main
File “/srv/conda/envs/env_snap/lib/python3.9/site-packages/snapista-0.1.2-py3.9.egg/snapista/graph.py”, line 338, in run
Exception: Graph execution failed (exit code -9)