Attach pixel geocoding in graph builder

Thank you so much for your help! I still need documentation to create an algorithm for S5p pre-processing.

With such an algorithm for S5p I can’t help.
What pre-processing do you want to do? What is the final goal?
Might be good to know if others want to help you.

-Apply pixel geocoding
-Subset
-Export to netcdf4
-Reproject to WGS84

Currently I just want to do this.

When executing the code you provided I get this error


----> 7 pixelGeoCoding = GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, validMask=None, searchRadius=6)

RuntimeError: no matching Java method overloads found

Maybe it must be an empty String in Python.
So try:
validMask = ‘’

This can all be done by operators (except the pixel geocoding)
Please have a look at this post:

For subetting there is the ‘Subset’ operator and for reprojection you use the ‘Reproject’ operator.
Saving as NetCDF4 can be done with the ‘Write’ operator.

You can also get the parameters names when you invoke the gpt from the command line:

gpt Subset -h

This will show the help for the Subset operator.

As output format for the Write operator you should use ‘NetCDF4-CF’

You were right Marco, string will do it but I still had to force searchRadius with int and validMask with str to get it to work. Thank you so much!

1 Like

Okay, good that it works now.
I’m not really a Python programmer, so I’m not very familiar with it.

Do you have any ideia how to run a graph file generated in SNAP using the gpt in a python script? I have done this in bash but i cannot run it using a similar syntax for python.

Bash Version:

gpt D:/Startup_Voucher/Projetos/Movimento_Gaio/Processing/STEP1Graph_Prep.xml -PInput=$i -POutput=$Output_pathname

Python Version:

gpt “D:/Startup_Voucher/Projetos/Artigo/Export_netcdf4.xml” -PInput=p -POutput=Output_pathname

I’ve also seen the other post from you.

I’m not sure but if you haven’t simplified the command and you use it as you have written here, than it could be that the variables are not replaced.

In order to validate the created command you could add

print(command)

before executing it.

If this doesn’t help you should provide more of your code. Then it is easier to help.

I have this code. Parameters not mentioned here are all defined. The problem seems is that the Input, Bandname and Output are not recognized from the preprocessing I do in the loop. Does Input and Output only take file paths?

for i in range(0, fileNumber):

p = ProductIO.readProduct(filePathList[i])
# list(p.getBandNames())

p_basename = os.path.basename(filePathList[i]) # extract file name for each selected file

latBand = p.getBand("latitude_PRODUCT")

lonBand = p.getBand("longitude_PRODUCT")

searchRadius = int(6)

validMask = str("")

GeoCodingFactory= snappy.jpy.get_type("org.esa.snap.core.datamodel.GeoCodingFactory")

pixelGeoCoding = GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, validMask,searchRadius)

p_preprocessed = p.setSceneGeoCoding(pixelGeoCoding)

p_preprocessed_name =  nameStart + p_basename
# print(p_preprocessed_name)
Output_pathname = os.path.join(output_folder,p_preprocessed_name)


command = 'cmd /k "gpt D:\Startup_Voucher\Projetos\Artigo\Export_netcdf4.xml" -PInput=p_preprocessed -PBandname=Bandname -POutput=Output_pathname'
print(command)
os.system(command)

Some suggestion you can try:

  • invoke gpt with ‘cmd /k’ and use directly “gpt …”
  • use the absolute path to the gpt executable
  • Split the command and let the variables be replaced:
    “gpt D:\Startup_Voucher\Projetos\Artigo\Export_netcdf4.xml -PInput=” + p_preprocessed + " -PBandname=" + Bandname + " -POutput=" + Output_pathname

I still get this:

C:\Users\Eduardo Godinho\p_preprocessed’ file didn’t exist

It seems it cannot input a variable but only files.

It still seems that the variable name is still used in the command string and not the content of the variable. Have you tried my third hint?

  • Split the command and let the variables be replaced:
    “gpt D:\Startup_Voucher\Projetos\Artigo\Export_netcdf4.xml -PInput=” + p_preprocessed + " -PBandname=" + Bandname + " -POutput=" + Output_pathname

The variable problem got solved I guess but now I’m get this error:

Error: Operator SPI not found for operator [graph_path]

Almost solved. I think.
graph_path is also a variable in your code, I guess.
So instead of the actual path the variable name is still included in the command.

It’s always looking for a file:

Error: [NodeId: Read] The ‘file’ parameter is not set

It seems that it is not possible to read a product, apply the pixel geocoding and use it in graph directly. I have also tried to save this product directly with:

ProductIO.writeProduct(p_preprocessed,“NetCDF4-CF”,“p_preprocessed.nc”, None)

But still no success.

Can you post your graph?

Here it is:

Export_netcdf4.xml (1.3 KB)

The xml look good.
Strange that you get the error

Error: [NodeId: Read] The ‘file’ parameter is not set

You set the variable Input in the command.
So If there is an error I would have expected something like

File not found: "p_preprocessed"

or

File not found: "${Input}"

But that it says “not set” means that the variable p_preprocessed is probably empty