Collocation problem

I am trying to collocate sentinel 2 with sentinel 3 images using python code. The code is the following:

for i in range(0,len(s2)):
for j in range(0,len(s3)):
if s2[i][0:8]==s3[j][0:8]:

  master=ProductIO.readProduct(outFolder+s3[j])
  slave=ProductIO.readProduct(outFolder+s2[i])
  sourceProducts = HashMap()
  sourceProducts.put('master', master)
  sourceProducts.put('slave', slave)
  parameters = HashMap()
  parameters.put('targetProductType','COLLOCATED')
  parameters.put('renameMasterComponents',True)
  parameters.put('renameSlaveComponents',True)
  parameters.put('masterComponentPattern','${ORIGINAL_NAME}_S3')
  parameters.put('slaveComponentPattern','${ORIGINAL_NAME}_S2')
  parameters.put('resamplingType','NEAREST_NEIGHBOUR')      
  result=GPF.createProduct('Collocate', parameters, sourceProducts)
  ProductIO.writeProduct(result,outFolder+s2[i][0:8]+'_'+'collocate.dim','BEAM-DIMAP')
  print str(outFolder+s2[i][0:8]+'_'+'collocate.dim')

The images were previously masked, c2rcc process was used. Sentinel 3 were also reprojected.

But when i open the image in snap i get the followning error (attach image)
image

When i open the data with arcgis i don t have any problems. They look fine.

Any ideas?

1 Like

Unfortunately, this is a known issue (SNAP-662).
You can fix this by removing the valid-pixel expression from the bands, if you don’t need it.
or you can update the expressions.
In your case, you need to replace ‘c2rcc_flags_S3.Valid_PE_S3’ by ‘c2rcc_flags_S3.Valid_PE’
And for the other flags accordingly.
You can change the valid expression as follows:

        nodes = result.getRasterDataNodes()
        for n in nodes
            validPixelExpression = n.getValidPixelExpression()
            # Change expression
            n.setValidPixelExpression(validPixelExpression)

Sorry, for the inconvenience this is causing. I hope it can be fixed soon.

Is it possible to remove the expression automatically using python code? How can i do that?

Just use the example above and provei an empty expression.

n.setValidPixelExpression('')

I tried the one you are saying and i get the following error.

Traceback (most recent call last):
File “F:\hydromerit\Hydromedit\Ch.py”, line 259, in
for n in nodes:
TypeError: ‘java.util.List’ object is not iterable

Any idea?

Ah, sorry. You need to convert the list into something which Python can iterate. I’m more a Java developer and thus not really used to these specialities when using snappy.
So replace
nodes = result.getRasterDataNodes()
by
nodes = list(product.getRasterDataNodes().toArray())

Instead of using an empty string you could also do
n.setValidPixelExpression(None)

The complete updated script:

    nodes = list(product.getRasterDataNodes().toArray())
    for n in nodes:
        n.setValidPixelExpression(None)
1 Like