Batch processing_Gpt_python_snap

This ESA BEAM batch processing with GPT document gives examples using bash (linux) .sh and cmd (Windows) .bat that should also work with ESA SNAP.

There is an updated version of the document @gnwiii mentioned.

Bulk Processing with GPT - SNAP Wiki


Dear marpet,
I run your code to learn, but we get an error:

G:\crop_mapping>setlocal ENABLEDELAYEDEXPANSION

G:\crop_mapping>set gptPath=“C:\Program Files\snap\bin\gpt.exe”

G:\crop_mapping>set graphXmlPath=“G:\crop_mapping”

G:\crop_mapping>set parameterFilePath=“G:\crop_mapping”

G:\crop_mapping>set sourceDirectory=“G:\crop_mapping\inpt_s”
The syntax of the command is incorrect.
G:\crop_mapping>if "==\ set sourceDirectory="G:\crop_mapping\inpt_s

mycode.bat (1.9 KB) (47 Bytes) resample_s2.xml (543 Bytes)

Follow the example in Bulk Processing with GPT. In particular, do not edit the original batch file to set the file and directory names. These are meant to be passed on the command line, as in:

processDataset.bat "G:\crop_mapping\resample_s2.xml" “G:\crop_mapping\" "G:\crop_mapping\inpt_s" "G:\crop_mapping\outpt_s"

[Edit: fix closing double-quotes ”->"]

Thank you.
Gives the following error again.

G:\crop_mapping>setlocal ENABLEDELAYEDEXPANSION

G:\crop_mapping>set gptPath=“C:\Program Files\snap\bin\gpt.exe”

G:\crop_mapping>set graphXmlPath=“G:\crop_mapping\resample_s2.xml”

G:\crop_mapping>set parameterFilePath=“G:\crop_mapping\”

G:\crop_mapping>set sourceDirectory=“G:\crop_mapping\inpt_s”
The syntax of the command is incorrect.
G:\crop_mapping>if "==\ set sourceDirectory="G:\crop_mapping\inpt_s

The closing double quotes in my post were replaced with the wrong double quotes, which are visible in your output. Hopefully fixed in an edit.

Deal all ,
I downloaded sentinel-2 data and now I want to calculate LAI, I created an xml file,graph_cal_lai.xml (3.1 KB)
Now how do I made the file .bat?
Please help

Thank you

Did you follow the steps from some document for the LAI calculation? If so, it would be good to mention the document so any lack of clarity can be corrected. How was the graph_cal_lai.xml file created? Do you have experience creating and running batch files?

The names of the input and output (GeoTIFF) data files appears to be embedded in the .xml file. In that case, there is no need for a .bat file. Try running:

<snap_install_dir>\bin\gpt -e <full_name_with_drive_and_directory_of_xmlfile>

A batch file may be useful if you want to do the same calculation for more than a few input files, but first you should verify that the processing works as needed with one example. The .xml file is an ordinary text file, and can be edited with any editor to change the filenames or other settings, but many advanced editors have helpful modes for .xml files.

Note that Microsoft has several command-line scripting programs: cmd and powershell are the most recent. If you have never written scripts for cmd you may find powershell is a better choice – it provides an integrated development environment (IDE) and more advanced tools for monitoring and controlling processes.

1 Like

Thank you very much
G:\crop_mapping><C:\Program Files\snap>\bin\gpt -e <graph_cal_lai.xml G:\crop_mapping>
The syntax of the command is incorrect.

The angle brackets should not be included (a convention in Microsoft documentation), so it appears you don’t have much experience
with the Windows command-line. You will find time spent learning command-line basics is paid back with interest by saving time using tools like gpt.

The parent document of the above link recommends:

You are using the older “Windows Commands”, but the simple one-line command should also work using PowerShell.

On a command-line the angle brackets indicate input or output redirection, so you may have created some unwanted files.

C:\Program Files\snap replaces <snap_install_dir> and
G:\crop_mapping\graph_cal_lai.xml replaces <full_name_with_drive_and_directory_of_xmlfile>.


G:\crop_mapping> C:\Program Files\snap\bin\gpt -e G:\crop_mapping\graph_cal_lai.xml 

Dear Marco ,
When I run the resampling code, it does not output. I even have three input files.
What is the problem?

G:\crop_mapping>processDataset.bat resample_s2.xml "G:\crop_mapping\input" "G:\crop_mapping\output" resampled20m

G:\crop_mapping>setlocal ENABLEDELAYEDEXPANSION

G:\crop_mapping>set gptPath="C:\Program Files\snap\bin\gpt.exe"

G:\crop_mapping>set graphXmlPath=resample_s2.xml


G:\crop_mapping>set sourceDirectory="G:\crop_mapping\input"

G:\crop_mapping>set targetDirectory="G:\crop_mapping\output"

G:\crop_mapping>set targetFilePrefix=resampled20m

G:\crop_mapping>md "G:\crop_mapping\output"
A subdirectory or file G:\crop_mapping\output already exists.

G:\crop_mapping>for / %F in (S2*.SAFE) do (
 set sourceFile=%~fF
 echo Processing !sourceFile!
 set targetFile="G:\crop_mapping\output"\resampled20m_%~nF.dim
 set procCmd="C:\Program Files\snap\bin\gpt.exe" resample_s2.xml -e -p -t "!targetFile!" "!sourceFile!"
 call !procCmd!

The for loop your batch file seems to be missing the options to search in %sourceDirectory. The original script has:

:: '/D' is for directories like Sentinel data. Remove '/D' when you open files.
for /D /R %sourceDirectory% %%F in (S2*.SAFE) do (

See Windows Commands: for.

Please help me
It’s been a week, I want to calculate LAI , I can’t because when I try to do this from inside Snap, my laptop hangs
Please help me to calculate from GPT.

Do you need more help getting processDataset.bat to work or with the LAI calculation in SNAP? Note that the underlying problem might also cause processDataset.bat to hang.

It could be that your process hangs because of an issue with the SRTM data. You can set the useSRTM option to false. If you need SRTM you can follow this post to fix the SRTM problem.

Yse, l need it for processDataset.bat

Dear all,
When I calculate lai for some images in SNAP, the output is as follows, why?

looks like the writing of the raster has not finished.

Perhaps you want to share the specs of your laptop… SNAP can be very heavy and you may require top specs to process large images or complicate graphs.

@omid - you are getting support from very knowledgeable and active members… perhaps you want to give more details of your data and intentions so that people have a better idea of what is your real problem.