Where to find Operator Parameters for Snappy?

Hi there,

I’m currently writing a script to automate Calibration and Terrain Correction of SAR GRD datasets.

I’m struggling to find any documentation on what the parameters are named to pass into the GPF.createProduct() methods, they don’t line up with the names used within the SNAP gui application. Could anyone lead me to these?

In particular I can’t seem to work out what Mask out areas without elevation is.

Many thanks,

Ciaran

1 Like

You can see the names of the parameters on the command line when you call gpt <operator_name> -h

It’s also possible to ask for it in python. The following snippet print the names and their aliases. You can use both. But I would prefer the alias, because they are in general better readable.

opSpi = GPF.getOperatorSpiRegistry().getOperatorSpi("operatorName")   
paramDescList = opSpi.getOperatorDescriptor().getParameterDescriptors()
for param in paramDescList:
  print(param.getName(), "or", param.getAlias())

See: http://step.esa.int/docs/v5.0/apidoc/engine/org/esa/snap/core/gpf/descriptor/ElementDescriptor.html#getName--

1 Like

Brilliant thanks! I tried the getName() and getAlias() approach but it always just returned ‘none’.

Mmmh?
Strange that is none.
You are using SNAP 5.0 already?

Yes, installed SNAP 5.0 a day or so ago.

CLI method worked but was not able to return meaningful strings back with the getAlias() methods.

op_spi = GPF.getDefaultInstance().getOperatorSpiRegistry().getOperatorSpi('Fill-DEM-Hole')
print('Op name:', op_spi.getOperatorDescriptor().getName())
print('Op alias:', op_spi.getOperatorDescriptor().getAlias())
param_Desc = op_spi.getOperatorDescriptor().getParameterDescriptors()
for param in param_Desc:
    print(param.getName(), "or", param.getAlias())

The above snippet gives me the following output.

Op name: org.esa.snap.dem.gpf.FillDEMHoleOp
Op alias: Fill-DEM-Hole
 sourceBandNames (alias: sourceBands )
 NoDataValue (alias: None )

It seems that I was wrong with my guess that both are always available.
The alias is often none. But name should be present.

Ah okay, brilliant.

Thanks for the help! :slight_smile:

Hello there, based on @marpet snippet used to print the names of an operator parameters I’ve created this little function:

def Op_help(op):
        op_spi = snappy.GPF.getDefaultInstance().getOperatorSpiRegistry().getOperatorSpi(op)
        print('Op name: {}'.format(op_spi.getOperatorDescriptor().getName()))
        print('Op alias: {}\n'.format(op_spi.getOperatorDescriptor().getAlias()))
        print('PARAMETERS:\n')
        param_Desc = op_spi.getOperatorDescriptor().getParameterDescriptors()
        for param in param_Desc:
            print('{}: {}\nDefault Value: {}\n'.format(param.getName(),param.getDescription(),param.getDefaultValue()))

Now I would also like to display all the possible values for each parameter. On the link marpet provided I managed to find the getValueSet method which “Gets the set of values which can be assigned to a parameter field.”, exactly what I want.
The problem is that when I execute the code:

param_Desc = op_spi.getOperatorDescriptor().getParameterDescriptors()
a = param_Desc[0].getValueSet()

the result is a Java string: [Ljava.lang.String;(objectRef=0x0000000030096308) but I don’t know how to print the values in the string :confused: any suggestions? thank you!

1 Like

It’s not only a string. It is an array od strings.
I think you can print it by:

value_set = param_Desc[0].getValueSet()
print(list(value_set))

Yeah thank you, probably that’s the way of showing it, but can you explain why the majority of them result as an empty object?
If, for example, I choose to display the list of possible values for the parameter demName, of the Terrain-Correction operator I get this as the output of my function after adding your last code snippet:

demName: The digital elevation model.
Default Value: SRTM 3Sec
Possible other values: []

Possible other values, where I inserted print(list(value_set)) just gives me an empty object :confused:
Isn’t that supposed to return all the available values among which I can choose using SNAP GUI? (In this case they would be ACE2_5Min, ACE30, ASTER 1sec GDEM,GETASSE30, SRTM 1sec grid, SRTM 1sec HGT, SRTM 3sec, External DEM )

This is often not possible to have this information.
The value_set is a static information. It is specified at development time. For example for the available DEMs can change by adding a or removing a plugin.
For the parameter demResamplingMethod of Terrain-Correction, you should get a value set.

We have already thought about collecting such information at runtime. Also, because we want to have it with the help when using gpt -h. This is not yet implemented.

1 Like

I understand, I will try to infer the values from the GUI then. Thank you for your quick answers!

Hi,
where to find the available operator’s name? Thanks!

In Python you can do the following:

from snappy import GPF
op_spi_it = GPF.getDefaultInstance().getOperatorSpiRegistry().getOperatorSpis().iterator()
while op_spi_it.hasNext():
    op_spi = op_spi_it.next()
    print("op_spi: ", op_spi.getOperatorAlias())

On the command line you can do: gpt -h

1 Like

Many thanks!

Hi, I have some questions
Q1: I want to know how to list the default values of all parameters of each operator?
Q2: How to output the maximum and minimum values of variables of esa.snap.core.datamodel.product type?
Q3: How to output the incidence angle values of sentinel1 SAR data?

Thanks!

Q1:

pDescriptors = op_spi.getOperatorDescriptor().getParameterDescriptors()
gives you a list of descriptors, one for each parameter.
for i in range(len(pDescriptors )):
    print(pDescriptors[i].getAlias(), " default: ", pDescriptors[i].getDefaultValue())

Q2:
product.getBand('bandname').getStx().getMaximum() # or getMinimum()

Q3:
I don’ know how you want to output those values.
But you can get them by:

iangle = product.getTiePointGrid('IW1_incident_angle')
# then you can read the values
data= numpy.zeros(width*height, dtype=numpy.float32)
iangle.readPixels(x,y,width, height, data)
# now you have the values in the data array and can print them.

Code should be like this. Sort of. Have not tested it.

I suggest also checking the Java API and the other developer resources.
Developers – STEP (esa.int)

1 Like

Many thanks!