Sen2coral_python


#1

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


#2

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


#3

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)?


#4

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.


#5

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?


#6

Hi,

the command for calling DepthInvariant should be:

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


#7

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?


#8

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


#9

yeap i can see the menu


#10

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


#11

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


#12

And if you execute the command:

gpt DepthInvariantIndicesOp -h

Is the operator found?


#13

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?


#14

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