Handling sentinel data in python ( working with snappy)


I resampled one S2 product, but I don’t see resampled images in my …\AppData\Local\Temp\… directory.

I know that data is cached by the S2 reader in the directory <USER_HOME>.snap\var\cache\s2tbx\l1c-reader. This could fill up your disk and the handling of this cache needs to be improved. There are already issues for this in our bug tracker (SIITBX-277, SIITBX-288).
In SNAP Desktop it is possible to change the interval how often the cache is deleted (Tools / Options / S2TBX). But this will probably not help you.
This cached data can be cleaned by a function call. I guess the following will work.

from snappy import jpy
S2CacheUtils = jpy.get_type('org.esa.s2tbx.dataio.cache.S2CacheUtils')


If you call deleteCache() after every processed product you should get rid of this problem. If the reader-cache is the problem and not something else. Probably it would be good if you first call on the source product dispose().


I’ll make a try in the following days and I will come back with an answer :slight_smile:


Hi Marco,

After a few days short break I’ve come back and start dealing again with the issue.

What I figure out was that by reading the *.zip file corresponding to the S2 imagery, the readProduct function was creating data in the folder …\AppData\Local\Temp\snap-user and that data was not removed. The dispose() method called on the product obtained by using readProduct did the trick and now the hard drive is free of unwanted data. The code is looking something like this:

S2CacheUtils = jpy.get_type(‘org.esa.s2tbx.dataio.cache.S2CacheUtils’)

product = ProductIO.readProduct(file_path)
- create product subset
- do something with product subset

In this way it is possible to remove the cache from subset-ing operation and remove the unnecessary data obtained after reading the product.

I would like to know if there is a difference in this case if I use product.closeIO() instead of product.dispose().

Thanks again for the tip!



Good to hear that it now works for you.

The method dispose() calls closeIO().

closeIO closes only the input/output stream and dispose releases all resources which have been allocated.

In the end the implementations of both methods often do the same. I would suggest calling always the dispose method.


snappy give me none output either i give zip file or unzip file. checked in two sentinel images. Instead when i open the manifest.safe in snap software it show result…


This happens either when no reader is found or when the file name is invalid. It is weird when you can open the file in SNAP Desktop, though. Can you tell me the value of ‘path1’?


Here is :


Perhaps could it be a typo in the path? Normally it should be
When you unzip it, the product folder should be [yourProductName].SAFE and if you are opening it compressed, then the path should be:


try it too. but same problem. give path with distinct ways :confused:


Pity, the missing ‘.SAFE’ really looked like the problem. Anyway, if the .SAFE is missing, it won’t open.

Do you maybe have multiple installations of SNAP on your computer?

Can you open other S1 products with snappy? Or any other products for that matter?


yes i opened .geotif with snappy ,no error detected while reading geotif


Try this:

reader = ProductIO.getProductReader(‘SENTINEL-1’)
product = reader.readProductNodes(path1, None)

Is the reader None or is it an object?


You should use the path with double back-slash like ‘\\’, e.g. ‘x:\\your_dir\\imag_name.zip’

To correctly read the product you must have something like:

from snappy import ProductIO

product = ProductIO.readProduct( ‘x:\\your_dir\\imag_name.zip’)
band_names = product.getBandNames()
print (list(band_names))

If you have the correct python setup for snappy (python 3.4 !!! + snappy) then the above scratch should work.


@marpet @ABraun
In the example provided snappy_flh.py I am getting an error:
w1 = b1.getSpectralWavelength()
AttributeError: ‘NoneType’ object has no attribute ‘getSpectralWavelength’
How can it be corrected?