Issues with GPT via Python's subprocess.run()

Cross posted and updating here

Hi,

I can successfully run GPT via command line:

(eodag) C:\Users\User\Documents\SARShipDetection>gpt workspace\SNAP_Preprocessing.xml -Pinputproduct=workspace\S1A_IW_GRDH_1SDV_20170501T165806_20170501T165831_016391_01B235_9CD1.zip -Pvectorfile=workspace\auxdata\Gulf_of_Trieste_seamask_UTM33.shp -Poutputproduct=workspace\outputs\S1A_IW_GRDH_1SDV_20161009T165807_4550_Orb
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.
Executing processing graph
INFO: org.hsqldb.persist.Logger: dataFileCache open start
....10%....20%....30%....40%....50%....60%....70%....80%....90% done.

However, if I try to run the above using subprocess.run() in a Python script:

graph_preprocess = "workspace\\SNAP_Preprocessing.xml"
product_selected_path = "workspace\\S1A_IW_GRDH_1SDV_20170501T165806_20170501T165831_016391_01B235_9CD1.zip"
vector_filepath = "workspace\\auxdata\\Gulf_of_Trieste_seamask_UTM33.shp"
output_dir = "workspace\\outputs"
outfn_preprocessed = "S1A_IW_GRDH_1SDV_20161009T165807_4550_Orb"

subprocess.run(["gpt", graph_preprocess, "-Pinputproduct=", product_selected_path, "-Pvectorfile=", vector_filepath, "-Poutputproduct=", os.path.join(output_dir, outfn_preprocessed)], stdout=subprocess.PIPE)

I get the following output with a returncode=1:

CompletedProcess(args=['gpt', 'workspace\\SNAP_Preprocessing.xml', '-Pinputproduct=', 'workspace\\S1A_IW_GRDH_1SDV_20170501T165806_20170501T165831_016391_01B235_9CD1.zip', '-Pvectorfile=', 'workspace\\auxdata\\Gulf_of_Trieste_seamask_UTM33.shp', '-Poutputproduct=', 'workspace\\outputs\\S1A_IW_GRDH_1SDV_20161009T165807_4550_Orb'], returncode=1, stdout=b'Executing processing graph\r\n done.\r\n')
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.

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

If I understand the error, GPT run via Python’s subprocess.run() cannot find the ‘file’ parameter in supplied .xml file (workspace\\SNAP_Preprocessing.xml)? If this interpretation is correct, why can it find this parameter when running from the command line? Is there some nuance about running GPT via Python’s subprocess.run() that I’m missing?

Any advice would be greatly appreciated!

Cheers,

Dennis

SNAP_Preprocessing.xml (1.2 KB)

PS - If I substitute the subprocess.run() line in the above Python script with a properly formatted IPython Bang (!) command, the processing completes successfully:

!gpt {graph_preprocess} -Pinputproduct={product_selected_path} -Pvectorfile={vector_filepath} -Poutputproduct={os.path.join(output_dir, outfn_preprocessed)}

Development Environment:
Python 3.11.3
eodag 2.10.0 pyhd8ed1ab_0 conda-forge
eodag-cube 0.3.0 pypi_0 pypi
Windows 10 (unfortunately…)
SNAP Desktop 9.0.6
SNAP Engine 9.0.6
OpenJDK Runtime Environment 1.8.0_242-b20
OpenJDK 64-bit Server VM by Azul Systems, Inc.

Have you tried to remove the quotes in your subprocess.run “-Pinputproduct=” and so on? I am not sure if you need them.
gpt_example.sh (403 Bytes)

I think the problem is that you’ve put both the parameter name and parameter in separate portions of the list, which puts a space between each. You’ll need to concatenate the parameter name and the parameter in each list item of subprocess.run,

subprocess.run(["gpt", graph_preprocess, "-Pinputproduct=" + product_selected_path, "-Pvectorfile=" + vector_filepath, "-Poutputproduct=" + os.path.join(output_dir, outfn_preprocessed)], stdout=subprocess.PIPE)
1 Like