Drop down menu in -info.xml

Hi all! Recently I started developing a plugin for SNAP in Python. SNAP offers many options for standard datasets. In some SNAP applications a DEM is required and can be selected from a predefined list (e.g. for the Range Doppler Terrain Correction plugin: Radar>Range Doppler Terrain Correction>Processing Parameters). This raised two questions regarding the implementation of my plugin:

1a) How do I create a drop-down menu in the -info.xml file?
1b) How do I obtain the actual DEM in the _op.py file as a source variable (e.g.
org.esa.snap.core.datamodel.Product[name=SRTM])? This SRTM DEM should be downloaded by SNAP internally after selection in the Processing Parameter menu.

Best regards,

Lars

Hi Lars,
A dropdown menu can easily be created. When you define a valueSet in the info.xml then these values are shown in a dropdown menu. But this can not be created dynamically.

The DEM handling is a bit more difficult.
On GitHub you can find corresponding java code, but there is no python example yet.
But after importing the classes it should work.

Hi Marco,

I guess that

<valueSet>
<name>optionList</name>
<string>Option A</string>
<string>Option B</string>
<string>Option C</string>
</valueSet>

is what you mean. Is this correct? That would mean I could get the values via context.getParameter(‘optionList’) in the initialize function within the Python class, but what about the value for each element, list data type etc. Could you give an example of how this looks in the info.xml file?

Regarding the java code and its classes. For acquiring a DEM I believe that I need use the following line of code (but then in Python):

ElevationModel dem = DEMFactory.createElevationModel(demName, demResamplingMethod);

Considering that line, the following remains unclear to me:

  1. Can I use demName = “SRTM 3Sec”? will this automatically point to an internal handle for the SRTM download?
  2. For the resampling method I require the ResamplingFactory class, how do I import this class in Python?
  3. Can I import DEMFactory.createElevationModel via snappy? If so, could you give me an example line?
  4. Do I need to replace the ElevationModel type, or can I leave it out in Python?

Thank you very much in advance!

A parameter section would look like this:

<parameter>
            <name>algorithm</name>
            <label>Algorithm</label>
            <description>Algorithm to be used</description>
            <dataType>String</dataType>
            <defaultValue>split</defaultValue>
            <valueSet>split,mono</valueSet>
</parameter>

This would result in a parameter where the user can select between split and mono, and split will be the default selection.

You can then get the value by

context.getParameter(‘algorithm’)

Regarding the elevation handling:
When you retrieve values from the dem you get via the DEMFactory the dem will be downloaded. But not the whole dataset only the tiles which are necessary.
Yes, ‘SRTM 3Sec’ should be usable. You can see what’s possible when you open the GUI for the ‘Raster\DEM Tools\Add Elevation Band’. The name is what is written before the braces.

To get the unknown classes you need to use jpy.get_type().
Most common classes are preloaded in __init__.py of snappy. There you can find examples of usages of this method.
In these two posts are also some examples:


For DEMFactory you would do:

 dem_factory = jpy.get_type('org.esa.snap.dem.dataio.DEMFactory')
 dem = demFactory.createElevationModel('SRTM 3Sec', 'NEAREST_NEIGHBOUR') 
 elev = dem.getElevation(GeoPos(lat, lon))