Thanks. let me try this.
Hi marpet, can I read somewhere something more about a PixEx operator in python? If I understand well, I need to put some parmeters here -> GPF.createProduct(‘PixEx’, parameters, product). But what is the name of a parameter in a case of a coordinate (‘org.esa.snap.pixex.Coordinate’)?
And I have also problem with Coord creation. When I try exactly what you write, I got an error:
RuntimeError: no matching Java method overloads found
The code is:
from snappy import jpy
Coord = jpy.get_type(‘org.esa.snap.pixex.Coordinate’)
Date = jpy.get_type(‘java.util.Date’)
import datetime
c1 = Coord(‘name1’, 54.0, 10.0, Date(datetime.datetime.utcnow()))
I have also tried to use ‘java.lang.Float’ and ‘java.lang.String’, but the same error. Do you know where should be a problem? Thank you for reply
Probably the error comes from thi call
The java Date class does not understand the Python datetime object.
Try, removing datetime.datetime.utcnow()
and call only Date()
What might also work is Coord('name1', 54.0, 10.0, none)
if you don’t care about the time.
Regarding the parameters of PixEx you can find them when you call on the command line
gpt -h PixEx
For defining the array of Corrdinates you need to do the following:
coords = jpy.array('org.esa.snap.pixex.Coordinate', 8)
This will create an array with 8 elements.
You can use it for the parameters:
parameters.put('coordinates', coords)
Hallo to all
I tried the following replies in order to extract the pixel value but still i got an error.
Traceback (most recent call last):
File “E:\diplomatiki\doriforikes\statistiki_analysi.py”, line 28, in
Coord(‘name1’,25.12,35.72,none)
NameError: name ‘none’ is not defined
The code i am using is
inf=‘E:\diplomatiki\S2A_MSIL1C.SAFE\S2A_MSL2A\S2A_MSIL2A_20170622T090021_N0205_R007_T35SLV_20170622T090154.SAFE\outputs/’
product=ProductIO.readProduct(inf+‘resample.dim’)
HashMap = jpy.get_type(‘java.util.HashMap’)
parameters = HashMap()
Coord=jpy.array(‘org.esa.snap.pixex.Coordinate’,5)
parameters.put(‘PexportBands’,1)
parameters.put(‘PexportExpressionResult’,0)
parameters.put(‘PexportMasks’,0)
parameters.put(‘PexportTiePoints’,0)
parameters.put(‘PoutputDir’,‘C:\Users\user\Desktop\te’)
Coord(‘name1’,25.12,35.72,‘none’)
parameters.put(‘coordinates’, Coord)
c=GPF.createProduct(‘PixEx’,parameters)
Any help ?
Actually it should be like:
c1 = Coord('name1', 54.0, 10.0, None)
And as said in my post before, the ‘coordinates’ parameter needs as value an array of coordinates. But this can be of length one if there is only a single coordinate
I tried that and i get the following error
Traceback (most recent call last):
File “E:\diplomatiki\doriforikes\statistiki_analysi.py”, line 24, in
Coord(‘name1’,25.12,35.72,None)
TypeError: ‘[Lorg.esa.snap.pixex.Coordinate;’ object is not callable
This happens because Coord in your code is already the array.
HashMap = jpy.get_type('java.util.HashMap')
inf='E:\diplomatiki\S2A_MSIL1C.SAFE\S2A_MSL2A\S2A_MSIL2A_20170622T090021_N0205_R007_T35SLV_20170622T090154.SAFE\outputs/'
product=ProductIO.readProduct(inf+'resample.dim')
my_coordinates=jpy.array('org.esa.snap.pixex.Coordinate', 5)
my_coordinates[0] = Coord('name1',25.12,35.72, None)
parameters = HashMap()
parameters.put('PexportBands', 1)
parameters.put('PexportExpressionResult', 0)
parameters.put('PexportMasks', 0)
parameters.put('PexportTiePoints', 0)
parameters.put('PoutputDir', 'C:\Users\user\Desktop\te')
parameters.put('coordinates', my_coordinates)
c=GPF.createProduct('PixEx', parameters)
In addition you need to remove the leading ‘P’ from the parameter names. They are only needed on the command line. And you need to replace 1 by True and 0 by False.
I tried but when i checked my module i had an error my_coordinates[0]included_bands[0] = Coord(‘name1’,25.12,35.72,‘none’)
so i changed that to
my_coordinates[0]= Coord(‘name1’,25.12,35.72,‘none’)
and i the following error
Traceback (most recent call last):
File “E:\diplomatiki\doriforikes\statistiki_analysi.py”, line 18, in
my_coordinates[0]= Coord(‘name1’,25.12,35.72,‘none’)
NameError: name ‘Coord’ is not defined
Then i also tried to correct the mentioned error
using that my_coordinates[0]= (‘name1’,25.12,35.72,‘none’)
and i get the following error
Traceback (most recent call last):
File “E:\diplomatiki\doriforikes\statistiki_analysi.py”, line 18, in
my_coordinates[0]= (‘name1’,25.12,35.72,‘none’)
ValueError: cannot convert a Python ‘tuple’ to a Java ‘org.esa.snap.pixex.Coordinate’
Try again the above script. There was just something wrongly paste into it.
I tried and i still get the first error i mentioned
Traceback (most recent call last):
File “E:\diplomatiki\doriforikes\statistiki_analysi.py”, line 18, in
my_coordinates[0] = Coord(‘name1’,25.12,35.72,‘none’)
NameError: name ‘Coord’ is not defined
Add this line at the beginning of the script:
Coord = jpy.get_type('org.esa.snap.pixex.Coordinate')
Now i get this error
Traceback (most recent call last):
File “E:\diplomatiki\doriforikes\statistiki_analysi.py”, line 18, in
my_coordinates[0] = Coord(‘name1’,25.12,35.72,‘none’)
RuntimeError: no matching Java method overloads found
Yes, I said it before. it needs to be replaced by. I’ve wrongly taken this from your script.
my_coordinates[0] = Coord('name1',25.12,35.72, None)
Sorry, but I’m not your debugger. All information you need is in this thread.
Sorry that was my mistake
It works but i don t see any files at the output directory.
Am i missing something?
Sorry again for any inconvenience.
One reason could be that the coordinates are not within the product bounds.
Thank you very much for your help marpet!! It worked!!
One last question
How is it possible to give multiple products at the same time so you will have one output file?
For a single product you can do:
GPF.createProduct('PixEx', parameters, product)
or for multiple products, you can create an array similar to the coordinates and then call
GPF.createProduct(‘PixEx’, parameters, productsArray)
But for PixEx it is best to specify the sourceproductsPath Parameter
. In each path, you can use wildcards so it matches multiple product files.
I followed the pin.txt template you shared and it worked!! Thankx
Hello,
this thread is very useful, and I am modifying the script proposed by panagiutos1 and modified by marpet to extract single pixel information from Sentinel 3 OLCI data. I have tried both using xml and netcdf files as source products. I adapted the script suggested, but at the end I get an error. No matter how I try, I can’t understand the cause. Could you please help me?
Here is my script, launched as .py:
;;;;
import snappy
import jpy
import datetime
import snappy
from snappy import GPF
from snappy import File
from snappy import Product
from snappy import ProductUtils
from snappy import ProductIO
from snappy import GeoPos
from snappy import PixelPos
from snappy import HashMap
Coord = jpy.get_type(‘org.esa.snap.pixex.Coordinate’)
HashMap = snappy.jpy.get_type(‘java.util.HashMap’)
inf=‘/OCEANASTORE/progetti/ocean_color/Copernicus/Rrs/cmems_rrs.nc’
#product=ProductIO.readProduct(inf+‘xfdumanifest.xml’)
product=ProductIO.readProduct(inf)
bands = list(product.getBandNames())
print (bands)
Coord = snappy.jpy.get_type(‘org.esa.snap.pixex.Coordinate’)
Date = snappy.jpy.get_type(‘java.util.Date’)
my_coordinates=jpy.array(‘org.esa.snap.pixex.Coordinate’, 5)
my_coordinates[0] = Coord(‘name1’,42.60613, 11.00893, None)
parameters = HashMap()
parameters.put(‘exportBands’, True)
parameters.put(‘exportExpressionResult’, False)
parameters.put(‘exportMasks’, False)
parameters.put(‘exportTiePoints’, False)
parameters.put(‘outputDir’, ‘/home/ocean/projects/snap/examples/output’)
parameters.put(‘coordinates’, my_coordinates)
c=GPF.createProduct(‘PixEx’, parameters, product)
;;;
The error I get is:
Traceback (most recent call last):
File “pixel_extraction_CL.py”, line 44, in
c=GPF.createProduct(‘PixEx’, parameters, product)
RuntimeError: java.lang.NullPointerException
The python version I have is 3.6.15. The java version is 11.0.19. The UBUNTU version is 22.04.2.
The coordinates I give are in the area included in the .nc file.
Thank you in advance, regards
Chiara