Sen2coral_python

Is there any possibility of running sen2coral from python so i can use it in batch mode for multiple images?

1 Like

It should work using snappy. Please see:
https://senbox.atlassian.net/wiki/spaces/SNAP/pages/19300362/How+to+use+the+SNAP+API+from+Python

Another option for running SNAP in batch mode is the Graph Processing Tool (GPT) that is included in the SNAP installation.
https://senbox.atlassian.net/wiki/spaces/SNAP/pages/70503590/Creating+a+GPF+Graph

Thank you for your answer. One more question but how i can call the plugin of sen2coral since it is a build plugin (you call it from IntelliJ IDEA programm)?

If you have built it properly, then you will have some .nbm files in the target/netbeans-site folder of the sen2coral-kit. You can use these files for installing the sen2coral plugin in SNAP: Tools->Plugin->Downloaded->AddPlugins…

If you prefer, you can also execute it directly from IntelliJ.

1 Like

I have build the application and i have installed the plugin in snap. I have installed jython.

I was trying to implement this code for the Depth Invariant Indices :
import snappy
from snappy import *
from snappy import GPF
from snappy import jpy
from snappy import HashMap
from snappy import ProductIO

product=ProductIO.readProduct(‘F:\sen2coral\polygona_deep_geom.dim’)
HashMap = jpy.get_type(‘java.util.HashMap’)

last=str(product)
parameters = HashMap()
parameters.put(‘sourceBands’, ‘B2,B3’)
parameters.put(‘deepWaterVector’,‘geom_1’)
parameters.put(‘sameBottomVectors’, ‘deep’)
c1=GPF.createProduct(‘test’,parameters)
p=ProductIO.writeProduct(c1,‘F:\sen2coral\test1000.dim’,‘BEAM-DIMAP’)

How i can call in this script the Depth Invariant Indices?

Hi,

the command for calling DepthInvariant should be:

c1=GPF.createProduct(‘DepthInvariantIndicesOp’,parameters,product)

Thanks for your response. I tried your idea but i get the following error

Traceback (most recent call last):
File “F:\sen2coral\sen2cora;.py”, line 18, in
c1=GPF.createProduct(‘DepthInvariantIndicesOp’,parameters,product)
RuntimeError: org.esa.snap.core.gpf.OperatorException: Unknown operator ‘DepthInvariantIndicesOp’. Note that operator aliases are case sensitive.

Any ideas?

Have you checked that the sen2coral plugin is properly installed? If you open SNAP Desktop, can you see the Sen2Coral operators in the menu?

yeap i can see the menu

And did you add the plugin via Menu->Tools->Plugins… in your SNAP installation or are you running it from IntelliJ?

I added my plugin through Menu->Tools->Plugins .

And if you execute the command:

gpt DepthInvariantIndicesOp -h

Is the operator found?

yeap. I get the following.

WARNING: org.esa.snap.core.util.ServiceFinder: Can't search for SPIs, not a directory: \snap-desktop-plugins
INFO: org.esa.snap.python.gpf.PyOperatorSpi: Python operator 'py_sambuca_snap_op' registered (Python module: 'sambuca_snap_op', class: 'sambuca_snap_op', root: 'C:\Users\user\AppData\Roaming\SNAP\modules\org-esa-sen2coral-sen2coral-inversion.jar')
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
Usage:
  gpt DepthInvariantIndicesOp [options]

Description:
  DepthInvariantIndicesOp algorithm


Source Options:
  -SsourceProduct=<file>    Sets source 'sourceProduct' to <filepath>.
                            This is a mandatory source.

Parameter Options:
  -PdeepWaterVector=<string>                  Deep water area
  -PsameBottomVectors=<string>                Same bottom areas
  -PsourceBands=<string,string,string,...>    The list of source bands.

Graph XML Format:
  <graph id="someGraphId">
    <version>1.0</version>
    <node id="someNodeId">
      <operator>DepthInvariantIndicesOp</operator>
      <sources>
        <sourceProduct>${sourceProduct}</sourceProduct>
      </sources>
      <parameters>
        <sourceBands>string,string,string,...</sourceBands>
        <deepWaterVector>string</deepWaterVector>
        <sameBottomVectors>string</sameBottomVectors>
      </parameters>
    </node>
  </graph>

I also tried from another post the following code

registry = GPF.getDefaultInstance().getOperatorSpiRegistry()
registry.loadOperatorSpis()

It seems to work. Does it make any sense?

It is strange, that should be done automatically since SNAP version 5.0. See for example:

hello obarrilero, do you have a tutuorial to instal plugin sen2coral? . thankyou

hello obariello, can i see step by step instal sen2coral in Windows? i was see tutorial in github.but its not work. thankyou for your respon