Batch processing_Gpt_python_snap

Dear all,
I want to calculate ndvi with gpt. I do it according to the attached file, but I get the following error when I run in CMD.
‘sh’ is not recognized as an internal or external command,
operable program or batch file.

my code:

ndvi_Graph.xml (2.8 batch_pro_gpt.sh (392 Bytes) KB)

Thank you

Hi omid! Files with .sh are bash scripts for Linux. You have Windows i suppose (you try to run your script in cmd) and your .sh file must be properly configured to run in it into your CMD. Also the files that will run through your cmd must be .bat files.

Thanks for your help
Please if anyone has an example of a batch snap run and might share it.

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

3 Likes

Dear marpet,
I run your code to learn, but we get an error:
G:\crop_mapping>mycode.bat

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
G:\crop_mapping>

mycode.bat (1.9 KB) resample_20m.properties (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\resample_20.properties" "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\resample_20.properties”

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>.

Try:

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

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


G:\crop_mapping>processDataset.bat resample_s2.xml resample_20m.properties "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 parameterFilePath=resample_20m.properties

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 (
echo.
 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 resample_20m.properties -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.
Please
Thanks

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?