Operate GPT in python

Hello. I’m a student currently studying Remote Sensing.
I want to operate GPT with SNAP in Python.
After making what I want in Graph builder and saving it as xml file, I want to operate the xml file in Python.
Is there any python code for this?

Is it really necessary to use Python? If you already have the graph xml file you can simply use gpt on the command line.
It is not straight forward to simply run the graph. Here you can see what is needed in java to run the graph file.

To run a graph of operators in python it is easier to run the operators separatly and use the result of the one operator in the succeeding operator.
Maybe reading this thread might help you.

1 Like

Thank you for answer :slight_smile:
I used gpt on the command line before using python but when running my code I got error message about parameter. ( Error : [NodeId: Read] ‘file’ parameter must be set )

My code is below.
gpt “C:\Users\Geoinfo.snap\graphs\Radar\InSAR Graphs\TOPSAR Coreg Interferogram IW All Swaths2.xml” -Pfile=“C:\Users\Geoinfo\target.dim” -t “C:\Users\Geoinfo\result.dim”

Could advise me about the code?

Could you also post the xml file please. I think this must be corrected, In particular the read node.

> <graph id="Graph">
>   <version>1.0</version>
>   <node id="Read">
>     <operator>Read</operator>
>     <sources/>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement"/>
>   </node>
>   <node id="Read(2)">
>     <operator>Read</operator>
>     <sources>
>       <sourceProduct refid="Apply-Orbit-File(2)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement"/>
>   </node>
>   <node id="TOPSAR-Split">
>     <operator>TOPSAR-Split</operator>
>     <sources>
>       <sourceProduct refid="Apply-Orbit-File"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <subswath>IW1</subswath>
>       <selectedPolarisations>VV</selectedPolarisations>
>       <firstBurstIndex>1</firstBurstIndex>
>       <lastBurstIndex>9999</lastBurstIndex>
>       <wktAoi/>
>     </parameters>
>   </node>
>   <node id="TOPSAR-Split(2)">
>     <operator>TOPSAR-Split</operator>
>     <sources>
>       <sourceProduct refid="Apply-Orbit-File(2)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <subswath>IW1</subswath>
>       <selectedPolarisations>VV</selectedPolarisations>
>       <firstBurstIndex>1</firstBurstIndex>
>       <lastBurstIndex>9999</lastBurstIndex>
>       <wktAoi/>
>     </parameters>
>   </node>
>   <node id="Apply-Orbit-File">
>     <operator>Apply-Orbit-File</operator>
>     <sources>
>       <sourceProduct refid="Read"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <orbitType>Sentinel Precise (Auto Download)</orbitType>
>       <polyDegree>3</polyDegree>
>       <continueOnFail>false</continueOnFail>
>     </parameters>
>   </node>
>   <node id="Apply-Orbit-File(2)">
>     <operator>Apply-Orbit-File</operator>
>     <sources>
>       <sourceProduct refid="Read(2)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <orbitType>Sentinel Precise (Auto Download)</orbitType>
>       <polyDegree>3</polyDegree>
>       <continueOnFail>false</continueOnFail>
>     </parameters>
>   </node>
>   <node id="Back-Geocoding">
>     <operator>Back-Geocoding</operator>
>     <sources>
>       <sourceProduct refid="TOPSAR-Split"/>
>       <sourceProduct.1 refid="TOPSAR-Split(2)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <demName>SRTM 3Sec</demName>
>       <demResamplingMethod>BILINEAR_INTERPOLATION</demResamplingMethod>
>       <externalDEMFile/>
>       <externalDEMNoDataValue>0.0</externalDEMNoDataValue>
>       <resamplingType>BILINEAR_INTERPOLATION</resamplingType>
>       <maskOutAreaWithoutElevation>true</maskOutAreaWithoutElevation>
>       <outputRangeAzimuthOffset>false</outputRangeAzimuthOffset>
>       <outputDerampDemodPhase>false</outputDerampDemodPhase>
>       <disableReramp>false</disableReramp>
>     </parameters>
>   </node>
>   <node id="Interferogram">
>     <operator>Interferogram</operator>
>     <sources>
>       <sourceProduct refid="Back-Geocoding"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <subtractFlatEarthPhase>true</subtractFlatEarthPhase>
>       <srpPolynomialDegree>5</srpPolynomialDegree>
>       <srpNumberPoints>501</srpNumberPoints>
>       <orbitDegree>3</orbitDegree>
>       <includeCoherence>true</includeCoherence>
>       <cohWinAz>2</cohWinAz>
>       <cohWinRg>10</cohWinRg>
>       <squarePixel>true</squarePixel>
>     </parameters>
>   </node>
>   <node id="TOPSAR-Split(3)">
>     <operator>TOPSAR-Split</operator>
>     <sources>
>       <sourceProduct refid="Apply-Orbit-File"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <subswath>IW2</subswath>
>       <selectedPolarisations>VV</selectedPolarisations>
>       <firstBurstIndex>1</firstBurstIndex>
>       <lastBurstIndex>9999</lastBurstIndex>
>       <wktAoi/>
>     </parameters>
>   </node>
>   <node id="TOPSAR-Split(4)">
>     <operator>TOPSAR-Split</operator>
>     <sources>
>       <sourceProduct refid="Apply-Orbit-File(2)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <subswath>IW2</subswath>
>       <selectedPolarisations>VV</selectedPolarisations>
>       <firstBurstIndex>1</firstBurstIndex>
>       <lastBurstIndex>9999</lastBurstIndex>
>       <wktAoi/>
>     </parameters>
>   </node>
>   <node id="Back-Geocoding(2)">
>     <operator>Back-Geocoding</operator>
>     <sources>
>       <sourceProduct refid="TOPSAR-Split(3)"/>
>       <sourceProduct.1 refid="TOPSAR-Split(4)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <demName>SRTM 3Sec</demName>
>       <demResamplingMethod>BILINEAR_INTERPOLATION</demResamplingMethod>
>       <externalDEMFile/>
>       <externalDEMNoDataValue>0.0</externalDEMNoDataValue>
>       <resamplingType>BILINEAR_INTERPOLATION</resamplingType>
>       <maskOutAreaWithoutElevation>true</maskOutAreaWithoutElevation>
>       <outputRangeAzimuthOffset>false</outputRangeAzimuthOffset>
>       <outputDerampDemodPhase>false</outputDerampDemodPhase>
>       <disableReramp>false</disableReramp>
>     </parameters>
>   </node>
>   <node id="Interferogram(2)">
>     <operator>Interferogram</operator>
>     <sources>
>       <sourceProduct refid="Back-Geocoding(2)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <subtractFlatEarthPhase>true</subtractFlatEarthPhase>
>       <srpPolynomialDegree>5</srpPolynomialDegree>
>       <srpNumberPoints>501</srpNumberPoints>
>       <orbitDegree>3</orbitDegree>
>       <includeCoherence>true</includeCoherence>
>       <cohWinAz>2</cohWinAz>
>       <cohWinRg>10</cohWinRg>
>       <squarePixel>true</squarePixel>
>     </parameters>
>   </node>
>   <node id="TOPSAR-Split(5)">
>     <operator>TOPSAR-Split</operator>
>     <sources>
>       <sourceProduct refid="Apply-Orbit-File"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <subswath>IW3</subswath>
>       <selectedPolarisations>VV</selectedPolarisations>
>       <firstBurstIndex>1</firstBurstIndex>
>       <lastBurstIndex>9999</lastBurstIndex>
>       <wktAoi/>
>     </parameters>
>   </node>
>   <node id="TOPSAR-Split(6)">
>     <operator>TOPSAR-Split</operator>
>     <sources>
>       <sourceProduct refid="Apply-Orbit-File(2)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <subswath>IW3</subswath>
>       <selectedPolarisations>VV</selectedPolarisations>
>       <firstBurstIndex>1</firstBurstIndex>
>       <lastBurstIndex>9999</lastBurstIndex>
>       <wktAoi/>
>     </parameters>
>   </node>
>   <node id="Back-Geocoding(3)">
>     <operator>Back-Geocoding</operator>
>     <sources>
>       <sourceProduct refid="TOPSAR-Split(5)"/>
>       <sourceProduct.1 refid="TOPSAR-Split(6)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <demName>SRTM 3Sec</demName>
>       <demResamplingMethod>BILINEAR_INTERPOLATION</demResamplingMethod>
>       <externalDEMFile/>
>       <externalDEMNoDataValue>0.0</externalDEMNoDataValue>
>       <resamplingType>BILINEAR_INTERPOLATION</resamplingType>
>       <maskOutAreaWithoutElevation>true</maskOutAreaWithoutElevation>
>       <outputRangeAzimuthOffset>false</outputRangeAzimuthOffset>
>       <outputDerampDemodPhase>false</outputDerampDemodPhase>
>       <disableReramp>false</disableReramp>
>     </parameters>
>   </node>
>   <node id="Interferogram(3)">
>     <operator>Interferogram</operator>
>     <sources>
>       <sourceProduct refid="Back-Geocoding(3)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <subtractFlatEarthPhase>true</subtractFlatEarthPhase>
>       <srpPolynomialDegree>5</srpPolynomialDegree>
>       <srpNumberPoints>501</srpNumberPoints>
>       <orbitDegree>3</orbitDegree>
>       <includeCoherence>true</includeCoherence>
>       <cohWinAz>2</cohWinAz>
>       <cohWinRg>10</cohWinRg>
>       <squarePixel>true</squarePixel>
>     </parameters>
>   </node>
>   <node id="TOPSAR-Deburst">
>     <operator>TOPSAR-Deburst</operator>
>     <sources>
>       <sourceProduct refid="Interferogram"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <selectedPolarisations/>
>     </parameters>
>   </node>
>   <node id="TOPSAR-Deburst(2)">
>     <operator>TOPSAR-Deburst</operator>
>     <sources>
>       <sourceProduct refid="Interferogram(2)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <selectedPolarisations/>
>     </parameters>
>   </node>
>   <node id="TOPSAR-Deburst(3)">
>     <operator>TOPSAR-Deburst</operator>
>     <sources>
>       <sourceProduct refid="Interferogram(3)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <selectedPolarisations/>
>     </parameters>
>   </node>
>   <node id="TOPSAR-Merge">
>     <operator>TOPSAR-Merge</operator>
>     <sources>
>       <sourceProduct refid="TOPSAR-Deburst"/>
>       <sourceProduct.1 refid="TOPSAR-Deburst(2)"/>
>       <sourceProduct.2 refid="TOPSAR-Deburst(3)"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <selectedPolarisations/>
>     </parameters>
>   </node>
>   <node id="Multilook">
>     <operator>Multilook</operator>
>     <sources>
>       <sourceProduct refid="TOPSAR-Merge"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <sourceBands/>
>       <nRgLooks>1</nRgLooks>
>       <nAzLooks>1</nAzLooks>
>       <outputIntensity>true</outputIntensity>
>       <grSquarePixel>true</grSquarePixel>
>     </parameters>
>   </node>
>   <node id="Write">
>     <operator>Write</operator>
>     <sources>
>       <sourceProduct refid="Multilook"/>
>     </sources>
>     <parameters class="com.bc.ceres.binding.dom.XppDomElement">
>       <file>C:\Users\Geoinfo\target.dim</file>
>       <formatName>BEAM-DIMAP</formatName>
>     </parameters>
>   </node>
>   <applicationData id="Presentation">
>     <Description/>
>     <node id="Write">
>       <displayPosition x="971.0" y="125.0"/>
>     </node>
>     <node id="Multilook">
>       <displayPosition x="834.0" y="134.0"/>
>     </node>
>     <node id="TOPSAR-Merge">
>       <displayPosition x="649.0" y="137.0"/>
>     </node>
>     <node id="TOPSAR-Deburst(3)">
>       <displayPosition x="511.0" y="252.0"/>
>     </node>
>     <node id="TOPSAR-Deburst(2)">
>       <displayPosition x="519.0" y="135.0"/>
>     </node>
>     <node id="TOPSAR-Deburst">
>       <displayPosition x="513.0" y="10.0"/>
>     </node>
>     <node id="Interferogram(3)">
>       <displayPosition x="396.0" y="253.0"/>
>     </node>
>     <node id="Interferogram(2)">
>       <displayPosition x="402.0" y="135.0"/>
>     </node>
>     <node id="Interferogram">
>       <displayPosition x="403.0" y="7.0"/>
>     </node>
>     <node id="Back-Geocoding(3)">
>       <displayPosition x="265.0" y="254.0"/>
>     </node>
>     <node id="Back-Geocoding(2)">
>       <displayPosition x="276.0" y="137.0"/>
>     </node>
>     <node id="TOPSAR-Split(6)">
>       <displayPosition x="128.0" y="262.0"/>
>     </node>
>     <node id="Back-Geocoding">
>       <displayPosition x="276.0" y="8.0"/>
>     </node>
>     <node id="TOPSAR-Split(4)">
>       <displayPosition x="128.0" y="232.0"/>
>     </node>
>     <node id="TOPSAR-Split(2)">
>       <displayPosition x="129.0" y="200.0"/>
>     </node>
>     <node id="Read(2)">
>       <displayPosition x="9.0" y="192.0"/>
>     </node>
>     <node id="Apply-Orbit-File(2)">
>       <displayPosition x="8.0" y="161.0"/>
>     </node>
>     <node id="TOPSAR-Split(5)">
>       <displayPosition x="124.0" y="70.0"/>
>     </node>
>     <node id="TOPSAR-Split(3)">
>       <displayPosition x="123.0" y="36.0"/>
>     </node>
>     <node id="TOPSAR-Split">
>       <displayPosition x="125.0" y="6.0"/>
>     </node>
>     <node id="Apply-Orbit-File">
>       <displayPosition x="10.0" y="102.0"/>
>     </node>
>     <node id="Read">
>       <displayPosition x="9.0" y="68.0"/>
>     </node>
>   </applicationData>
> </graph>

There is something really wrong in the xml.
For example node Read(2) tries to read from the node Apply-Orbit-File(2) but the node Apply-Orbit-File(2) reads from the node Read(2). So this is an infinite loop.
The Read operator also needs the file parameter not the sources. The sources are not used.
Call gpt Read -h on the command line for help.