1

I'm trying to retrieve pixel values in Sentinel-3 data for specific geographic coordinates using the SNAP-Engine. Until now, I transform the geographic coordinates to the corresponding X and Y with the following code using these links:


import sys
sys.path.append('/path/to/.snap/snap-python')
from snappy import ProductIO
import numpy as np
from snappy import GeoPos

p = ProductIO.readProduct('/path/to/file.xml')
iwv = p.getBand('IWV')

g = p.getSceneGeoCoding()

def XY_from_LatLon(ProductSceneGeoCoding, latitude, longitude):
    #From Latitude, Longitude satellite image, get the x, y position in image
    pixelPos = ProductSceneGeoCoding.getPixelPos(GeoPos(latitude, longitude), None)
    x = pixelPos.getX()
    y = pixelPos.getY()
    if str(x)=='nan':
        raise ValueError('Latitude or Longitude out of this product')
     else:
         return x, y

How can I retrieve the data from a pixel using image coordinates (X, Y) in SNAP-Engine ?


After some more searching in SNAP-Engine docs, I found the method: getPixelFloat() that returns the pixel value given x, y. The code above was updated to the following :

import sys
sys.path.append('/path/to/.snap/snap-python')
from snappy import ProductIO
import numpy as np
from snappy import GeoPos

p = ProductIO.readProduct('/path/to/file.xml')
iwv = p.getBand('IWV')

g = p.getSceneGeoCoding()

def XY_from_LatLon(ProductSceneGeoCoding, latitude, longitude):
    #From Latitude, Longitude satellite image, get the x, y position in image
    pixelPos = ProductSceneGeoCoding.getPixelPos(GeoPos(latitude, longitude), None)
    x = pixelPos.getX()
    y = pixelPos.getY()
    if str(x)=='nan':
        raise ValueError('Latitude or Longitude out of this product')
     else:
         return x, y

x, y = XY_from_LatLon(sg, <lat>, <lon>)
print(iwv.getPixelFloat(x, y))

but it raises the following error:

Traceback (most recent call last):
File "snap.py", line 28, in <module>
print(iwv.getPixelInt(x, y))
RuntimeError: no matching Java method overloads found

1 Answer 1

2

I know it has been two years, but there are three things:

  1. You have to load raster data after retrieving a band

    p=ProductIO.readProduct('/path/to/file.xml')

    iwv=p.getBand('IWV')

    iwv.loadRasterData() #add this line

otherwise you will get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: java.lang.NullPointerException
  1. In this line: x, y = XY_from_LatLon(sg, <lat>, <lon>) you should have 'g' as variable name is g = p.getSceneGeoCoding() #sg was in the original script

  2. According to the SNAP Engine API doc, x and y need to be integers: getPixelInt(int x, int y) (https://step.esa.int/docs/v6.0/apidoc/engine/org/esa/snap/core/datamodel/AbstractBand.html)

I tested on my S3 SL 2 LST dataset, and x & y were returned : x = 729.5 y = 581.5

lst.getPixelFloat(x,y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: no matching Java method overloads found
lst.getPixelFloat(int(x), int(y))
309.7099914550781

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.