Sen2Cor and snappy : a safe step by step procedure for proper installation

Hi everyone , I do need a safe and definite step by step procedure to use sen2cor as a processor in a Python processing chain. But so far I have found many threads with different instructions and making some confusion. I would need some reference point :

  1. which is the best option so far, SNAP 5 or 6?
  2. which is the working version of sen2cor to use in python? 2.3.1 or 2.4 ?
  3. which version of Anaconda is recommended? the official sen2cor manual says it has been tested with anaconda 4.2.0
  4. for a python usage of sen2cor should I use the sen2cor 2.4 stand-alone or the 2.3.1 version? do I need to build the tool adapter for snap6?

and finally, some step by step indication would be appreciated.

Probably @ramona_manda @ABraun @ could really help me. Thanks in advance!!

2.4 is standalone.
No Anaconda, no Python required :slight_smile:

Just download and execute from the command line. Integration in SNAP will be in version 6 (to be released soon)

1 Like

The problem is that I need to do it via Python :slight_smile:

This is the thread I am referring to, but I would really need some indications to get the same results:
I hope in @ramona_manda or someone working on the same stuff :slight_smile: @obarrilero

I am sorry, I completely overread the snappy part on my mobile device…
Don’t have experience with that so far, sorry. Hopefully someone other can help.

1 Like

I use Ubuntu 16.04 LTS
Python 2.7 from the distro

When you have installed snap 6 properly and managed to follow the installation instructions. It sorts of work although I get loads of warnings. I have written this simple piece of code. I get lots of warnings but the product seems to be produced normally here the script.

import sys
import os, snappy

def Sen2Cor(f):
    parameters = snappy.HashMap()
    parameters.put('resolution', '10')
    parameters.put('nbProcesses', 10)
    L2A_image = snappy.GPF.createProduct('Sen2Cor', parameters, f)

### initialisation
WorkingDir = 'Path_To_Product'
Dir1C = 'S2A_MSIL1C_20170921T020751_N0205_R017_T50JRT_20170921T021044.SAFE'
File = 'MTD_MSIL1C.xml'

### Main
f1C = snappy.ProductIO.readProduct(WorkingDir+os.sep+Dir1C+os.sep+File)

I get a runtime error
RuntimeError: org.esa.snap.core.gpf.OperatorException: Operator 'ToolAdapterOp': No target product set.
L2A_image is not pointing to any object (even when inside the function but the L2A product is written.

It is rough and just my first tries. For example, I don’t know if in the parameters you systematically have to call string or if you could use numbers. Here I have done a mix. I am not sure how many process are actually activated because only some operations seems to multithread.

Hope could be of some help

Hi! it can be interesting, but how did you install sen2cor? which version? stand-alone mode or anaconda mode?

Sen2cor 2.4, standalone
As I said python from the distro, so no Anaconda. I happily removed it from my computer yesterday when I learned it was not needed anymore.

But the stand-alone sen2cor only works in command window, didn’t you install any tool adapter in snap?

Nope it works in SNAP too you just have to DL the plugin
And you can call the function in python through snappy as in the short script I posted.


ok, I will try it then :slight_smile: thanks for the moment

Dear @ramona_manda what do you think about this ?

Hello. When downloading the Sen2Cor plugin, this means you integrate Sen2Cor in SNAP. Further, I think, and Boorhin can correct me, that he is using Windows and when he tried to execute the plugin for the first time, received a message like this 'A bundle has been configured for this adapter. Do you want to proceed with the bundle download…". So actually, without intention, Boorhin probably installed the plugin and also the bundle. Otherwise, the current version of the plugin that comes in SNAP 6 cannot work with other Sen2Cor installation (besides the bundle). Also, as a side note, the error received is an issue discovered yesterday and it is the reason why L2A_image is not pointing to the resulting product. This will be fixed in the next update for sure.

He uses ubuntu If I read well on top of this thread

Dear @Boorhin can you confirm you are using Linux Ubuntu or Windows? :slight_smile:

Ubuntu 16-04 LTS