Snappy - error terrain corection

I use snappy for terrain corection:

  parameters = HashMap()     
  parameters.put('demResamplingMethod', 'NEAREST_NEIGHBOUR') 
  parameters.put('imgResamplingMethod', 'NEAREST_NEIGHBOUR') 
  parameters.put('demName', 'SRTM 3Sec') 
  parameters.put('pixelSpacingInMeter', 10.0) 
  parameters.put('sourceBands', 'Sigma0_' + polarization)

  terrain = output + date + "_corrected_" + polarization 
  target_2 = GPF.createProduct("Terrain-Correction", parameters, subset) 
  ProductIO.writeProduct(target_2, terrain, 'GeoTIFF')

Subset was created correctly

Appears error:

Traceback (most recent call last):
  File "s1.py", line 71, in <module>
    target_2 = GPF.createProduct("Terrain-Correction", parameters, subset) 
ValueError: cannot convert a Python 'str' to a Java 'org.esa.snap.core.datamodel.Product'

Does anyone know what the problem is?

1 Like

I have the same problem. The error occurs with Terrain-Correction or Speckle-Filter operators are used, but no error when using Calibration or Subset operators.
It would be nice if someone would take a look and explain the reason for this error.

could it be that the “-” sign in the operator somehow raises the error? Can you try another operator with an minus, such as Land-Sea-Mask or Ellipsoid-Correction-GG

I think the cause is the subset. How is it created?
Maybe it is just the Path to the file?
You can try to print the subset

Hey, here is part of the code:

…
subset = output + date + “subset” + polarization
target_1 = GPF.createProduct(“Subset”, parameters, calibration)
ProductIO.writeProduct(target_1, subset, ‘BEAM-DIMAP’)
parameters = HashMap()
parameters.put(‘demResamplingMethod’, ‘BILINEAR_INTERPOLATION’)
parameters.put(‘imgResamplingMethod’, ‘BILINEAR_INTERPOLATION’)
parameters.put(‘demName’, ‘SRTM 3Sec’)
parameters.put(‘pixelSpacingInMeter’, 10.0)
parameters.put(‘sourceBands’, ‘Sigma0_’ + polarization)
parameters.put(‘nodataValueAtSea’, False)
terrain = output + date + “corrected” + polarization
target_2 = GPF.createProduct(“Terrain-Correction”, parameters, subset)
…

Print subset gives D:\sar\dowTEST\terrain-correction\S1B_IW_GRDH_1SDV_20171230T163254_20171230T163319_008951_00FF83_D90F.SAFE\20171230_subset_VH

I tried also Land-Sea-Mask and Ellipsoid-Correction-GG, but also now LandWaterMask and still the same error. For those I hope there are some default parameters because I didn’t bother setting any. Aren’t there?

As I suspected.
In line 3 subset is the path to the file.
but in the last line the product is expected.
Instead of
target_2 = GPF.createProduct(“Terrain-Correction”, parameters, subset)
do
target_2 = GPF.createProduct(“Terrain-Correction”, parameters, target_1)

This should work.

2 Likes

Yeah, I guess this one should be working (it’s in progress). :slight_smile:
Thanks.
Prior to this part of the code I had calibration done where variables were:
calib - which stands for the path and
calibration - which stands for the very product

But afterwards I just had single variable subset which I used for both path and product, I didn’t pay attention to this.
Regards,
Milos

P.S. Do operators have pre-default parameters or do we need to set before using? If they do have, are they the same as when using SNAP GUI?

Yes, they have default values. And they are the same in the GUI, at the command line and via Python.
In some cases, especially if the operators have a special UI the GUI does parameter handling differently and also the defaults can be different. The reliable default values you see when you call the help for an operator on the command line.
You can retrieve the default value also via API. Simplyfied for the first paramter:
GPF.getOperatorSpiRegistry().getOperatorSpi(operatorName).getOperatorDescriptor().getParameterDescriptors()[0].getDefaultValue()

1 Like