Snappy geocoding returns wrong Pixel Position from Lat and Lon

Hi everyone,
I’m trying to get pixel position from a given Lat/Lon in snappy.
To do so I wrote this little function below:

def m_getPixelPos(source,lat,lon):
        from snappy import GeoPos,PixelPos
        import numpy as np
        if source.getSceneGeoCoding().canGetPixelPos() is not True:
                raise Exception('Can''t get Pixel Position from this source')
        else:
                pos = GeoPos(lat, lon)
                pixpos=source.getSceneGeoCoding().getPixelPos(pos,None)
                X = np.round(pixpos.getX()) 
                Y = np.round(pixpos.getY())
        return [X,Y]

If I apply the function to a geocoded S-1 image (without subsetting), using lat and lon from a WKT, I get different pixel position from what I see on SNAP GUI:

Lat and Lon are the following

In [37]: lat
Out[37]: 41.473256216059198
In [38]: lon
Out[38]: -5.6008912160591899

If I apply my m_getPixelPos function I get:

In [39]: m_getPixelPos(source,lat,lon)
Out[39]: [3879.0, 3726.0]

By looking at the SNAP GUI though, I see different pixel coordinates for those lat/lon:

Why I get this behaviour?
There is something I’m doing wrong on the PixelPos funtion or is some bug related to snappy?

If I apply the same function using a subsetted portion of the previous image as source, and lat and lon taken randomly from a pixel looking at snap gui, the result I obtain is correct :confused: so I guess I might be doing something wrong…but I can’t really find out what I’m missing.
Can anybody help me?
Thanks a lot!

Best regards,
Davide

1 Like

Mmmmh, this is strange. This can happen if geo-coordinates are contained multiple times. But it seems you have reprojected the data, so there shouldn’t be duplicates
Have you tried the other way around, getting for the pixels [3879.0, 3726.0] and [6091, 3734] the geo-location?
Which CRS are you using or is the scene not reprojected?