Sen2Cor and Snappy

I’m not sure. There is the new version 2.4.0 which shall come today. Maybe along with the SNAP BETA 6 it might work.

I think @ramona_manda or @umwilm can say more about it .

Hello,

I have just tested the Sen2Cor with snappy, I have currently Sen2Cor 2.3.1 and SNAP 6.0 beta. For me it works, please find the code:

import datetime
import numpy
from snappy import ProductData
from snappy import GPF
from snappy import HashMap

def readProduct(path, formatName=None):
from snappy import (File, ProductIO)
productFile = File(path)
if formatName is None:
return ProductIO.readProduct(productFile)
else:
reader = ProductIO.getProductReader(formatName)
return reader.readProductNodes(productFile, None)

parameters = HashMap()
parameters.put(‘resolution’, “20”)
L2A_image = GPF.createProduct(‘Sen2Cor’, parameters, readProduct(“D:\temp\a.jp2”))

Let me know if you have any problems with this code.

This does not work anymore with Snap 7.0 and Sen2Cor 2.8
Everything done well, and tool manager set properly.
However it is not installed in python lib.

parameters = HashMap()
parameters.put(‘resolution’, ‘All’)
parameters.put(‘aerosol’, ‘MARITIME’)
parameters.put(‘ozone’, 0)
s2a_s2c = GPF.createProduct(‘Sen2Cor’, parameters, source)

RuntimeErrorTraceback (most recent call last)
in ()
7 parameters.put(‘aerosol’, ‘MARITIME’)
8 parameters.put(‘ozone’, 0)
----> 9 s2a_s2c = GPF.createProduct(‘Sen2Cor’, parameters, source)

RuntimeError: org.esa.snap.core.gpf.OperatorException: Unknown operator ‘Sen2Cor’. Is the name correctly spelled?

This is probably due to the existence of two versions 280 and 255. I tried different spelling like Sen2Cor280 but to no avail.

Otherwise gpt -h Sen2Cor280 works fine. (I only have 280 version installed). So we’re back to this previous solution of going through gpt command line.

milkabe’s code worked for me with minor tweaks to satisfy operator ToolAdapterOp

parameters = HashMap()
parameters.put(‘resolution’, ‘ALL') # was 'All'
parameters.put(‘aerosol’, ‘MARITIME’)
parameters.put(‘ozone’, '0') # was 0

I think the operator name in createProduct should be identical to Alias in Tools -> Manage External Tools -> Alias (in the SNAP GUI)
Edit: A list of all available opreators is available running gpt -h

# see ramona_manda's code above for a better implementations
source = snappy.ProductIO.readProduct(path_to_product) 
s2a_s2c = GPF.createProduct(‘Sen2Cor280’, parameters, source) # was Sen2Cor