Error while performing Mosaic on Snappy

Hi everybody,

I’m trying to perform an Mosaic operation on Snappy, but I found the error below, that don’t specify so much:

Traceback (most recent call last):
  File "/scratch/acorroch/opt/img/snappy_test1.py", line 46, in <module>
    mosaickImage =  mosOp.getTargetProduct()
RuntimeError: org.esa.snap.core.gpf.OperatorException

This is my code:

products = jpy.array('org.esa.snap.core.datamodel.Product', 2)
products[0] = fileOneResampled
products[1] = fileTwoResampled

MosaicOp = esa_snappy.jpy.get_type('org.esa.snap.core.gpf.common.MosaicOp')

mosOp = MosaicOp()
mosOp.setSourceProducts(products)
mosOp.setParameter('westBound','116.99984025621173')
mosOp.setParameter('northBound','32.53731013088188')
mosOp.setParameter('eastBound','118.16895344915102')
mosOp.setParameter('southBound','30.639816504441374')

mosaickImage =  mosOp.getTargetProduct()

I checked the gpt Mosaic -h to see the options because I think that maybe I need to specify the bands, but I don’t see how to do it.

Description:
  Creates a mosaic out of a set of source products.


Source Options:
  -SupdateProduct=<file>    A product to be updated.
                            This is an optional source.

Parameter Options:
  -Pcombine=<string>               Specifies the way how conditions are combined.
                                   Value must be one of 'OR', 'AND'.
                                   Default value is 'OR'.
  -Pcrs=<string>                   The CRS of the target product, represented as WKT or authority code.
                                   Default value is 'EPSG:4326'.
  -PeastBound=<double>             The eastern longitude.
                                   Valid interval is [-180,180].
                                   Default value is '30.0'.
  -PelevationModelName=<string>    The name of the elevation model for the orthorectification.
  -PnorthBound=<double>            The northern latitude.
                                   Valid interval is [-90,90].
                                   Default value is '75.0'.
  -Porthorectify=<boolean>         Whether the source product should be orthorectified.
                                   Default value is 'false'.
  -PpixelSizeX=<double>            Size of a pixel in X-direction in map units.
                                   Default value is '0.05'.
  -PpixelSizeY=<double>            Size of a pixel in Y-direction in map units.
                                   Default value is '0.05'.
  -Presampling=<string>            The method used for resampling.
                                   Value must be one of 'Nearest', 'Bilinear', 'Bicubic'.
                                   Default value is 'Nearest'.
  -PsouthBound=<double>            The southern latitude.
                                   Valid interval is [-90,90].
                                   Default value is '35.0'.
  -PwestBound=<double>             The western longitude.
                                   Valid interval is [-180,180].
                                   Default value is '-15.0'.

May I need to specify the bands some way or may I do something else?

Thanks,

Álvaro

Could you not run mosaic generation with a graph using gpt, as that is the recommended and probably far more performant option?

1 Like

Hi, I want to automate the process for a lot of images (I want to perform some operations on the Chaohu Lake, that are between two images), so for that reason I tried to automate the process on Snappy (read, resampling, mosaicking, subset and so on).

I tried to do some Graphs in the last days with relative success, but another problem with that is that on the interface, there are only Multi-size Mosaic, not Mosaic.

Mosaic is available via the GUI but not in the Graph Builder, is that what you mean?

You can manage your input data with Python but the performant option is calling gpt-graphs for the processing.

1 Like

Yes, I mean that the Graph Builder don’t have the operation. But If it have it, I prefer using Snappy for the automate reason, but I don’t know how to set the bands to perform it (if this is the error).

I check a graph that I have and the bands are on the parameter section but the structures is more difficult:

 <parameters class="com.bc.ceres.binding.dom.XppDomElement">
      <variables>
        <variable>
          <name>B1</name>
          <expression>B1</expression>
        </variable>
        <variable>
          <name>B11</name>
          <expression>B11</expression>
        </variable>
...
      </variables>
...
</parameters>

And I don’t know how to say the parameter that I want all that inside “variables”

Also, I don’t know what do you mean with “You can manage your input data with Python but the performant option is calling gpt-graphs for the processing.”

Do you mean I can execute the graph from Python?

You can set up the graph parameters in Python and then call gpt to execute it. @diana_harosa can you point towards instructions for doing this?

1 Like

I have achieved it!

I follow this other topic where there is explain how to initialize the variable list.

This is my code now:

Variable = jpy.get_type('org.esa.snap.core.gpf.common.MosaicOp$Variable')
variables = jpy.array('org.esa.snap.core.gpf.common.MosaicOp$Variable', 13)
variables[0] = Variable('B1', 'B1')
variables[1] = Variable('B2', 'B2')
variables[2] = Variable('B3', 'B3')
variables[3] = Variable('B4', 'B4')
variables[4] = Variable('B5', 'B5')
variables[5] = Variable('B6', 'B6')
variables[6] = Variable('B7', 'B7')
variables[7] = Variable('B8', 'B8')
variables[8] = Variable('B8A', 'B8A')
variables[9] = Variable('B9', 'B9')
variables[10] = Variable('B10', 'B10')
variables[11] = Variable('B11', 'B11')
variables[12] = Variable('B12', 'B12')

...

MosaicOp = esa_snappy.jpy.get_type('org.esa.snap.core.gpf.common.MosaicOp')

mosOp = MosaicOp()

mosOp.setSourceProducts(products)

mosOp.setParameterDefaultValues()
mosOp.setParameter('variables', variables)
mosOp.setParameter('westBound','116.99984025621173')
mosOp.setParameter('northBound','32.53731013088188')
mosOp.setParameter('eastBound','118.16895344915102')
mosOp.setParameter('southBound','30.639816504441374')

mosaickImage =  mosOp.getTargetProduct()

And the process ends succesfully.

I still interested on the call gpt from Python thing that you commented before.

If you can explain it to me, I’ll be so grateful.

Thanks!

Álvaro