Writing Python plugin

I am writing a Python SNAP plugin (https://github.com/DHI-GRAS/sen-et-snap) and I run into a couple of questions for which I couldn’t find answers online. Any help on those would be greatly appreciated.

  1. Can an operator have multiple target products and if yes then how to specify this?
  2. I am running SNAP through IntelliJ and all the print statements output to the IntelliJ terminal. How can I display messages in SNAP GUI (e.g. in the operator dialog) instead? This could be to indicate progress, advise on input parameters, report errors, etc.
  3. My operators are available through the specified SNAP menu (in my case Optical) but I cannot see them when creating a graph. How can I specify that an operator should be available in the graph dialog?
  4. How can I find out from snappy how many processors and how much memory are assigned to SNAP?
  5. How can I create a File/Folder parameter?
  6. How can I specify which source product a Band parameter refers to? Currently it always reads the bands from the first source product.
  7. Which exception should I use in case the user sets wrong parameters or input data is wrong? I would like a warning dialog to be displayed and the user given the possibility to select different parameters and inputs.
  8. How to set autoWriteDisabled? I tried to set it in -info.xml but it didn’t seem to work. How exactly does it affect computeTileStack and computeTile methods?

Thank you and regards

Dear SNAP developers,
Would anyone be able to assist with the above questions now that SNAP 7 is out?

Hello @radosuav ,
For beginning, I will try to answer what I know.

Q1. There is only one targetProductFile parameter (read-only). It is a File corresponding to the target product that will be loaded in SNAP after the tool execution.

Q2. There are 2 elements available (progressPattern, errorPattern), under <operator>. E.g.
<progressPattern>.*: (\d{1,3})%(?:.+)</progressPattern>

Q3. When creating a graph, search the external operator under Add -> Tools (not under Optical)

Q5. By setting its dataType to “java.io.File”

Q7. There are already basic validations done (with popup dialogs displayed), depending on the configuration of a parameter:

  • not empty value [notEmpty]
  • required parameter [notNull]
  • value of a specified data type [dataType]
  • regex validations for [progressPattern] and [errorPattern]
  • value within value set [valueSet])

Q8. It’s autoWriteSupressed, e.g.:

I am supposing you already saw the help page inside SNAP:

Also, you can install an existing external plugin in SNAP (from Tools -> Plugins -> Available Plugins), and then try to export it in order to see exactly how it’s made (Tools -> Manage External Tools -> select an operator -> click on Edit -> Export as module :

Best regards,

Hi Oana,
Thank you for the useful tips! Unfortunately not everything seems to be working.

Q2. If I put any of those elements under <operator> I get “Unexpected Exception: Could not initialize class org.esa.snap.python.gpf.PyOperatorSpi” when starting SNAP and cannot open the operator.

Q3. I cannot find my operators under Add -> Tools. Is it because operatorClass is org.esa.snap.python.gpf.PyOperator and not org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterOp? Is there a way to add org.esa.snap.python.gpf.PyOperator to graphs?

Q5. java.ioFile works fine but if I use $USERPROFILE in the I get an “Unexpected Exception”. However this is not a critical issue for me.

Q8. <autoWriteSuppressed>false</autoWriteSuppressed> works (i.e. I do not get an exception when starting SNAP) but in the operator dialog there is still Target Product area on the I/O tab. Is there a way to remove the Target Product selection from this tab? Alternatively, can I somehow limit the output format of the Target Products (e.g. just to NetCDF).

Thank you!