Combination View Flat View Tree View
Threads [ Previous | Next ]
Scripting Band Arithmetic
toggle
Scripting Band Arithmetic
6/30/09 10:36 PM
I am new to Java and BEAM. I have several different Band Arithmetic functions I want to apply to an image, and I was wondering if I could write a script that would complete them all at once rather than doing the mundane copy/paste into the GUI for each image.
Flag Flag
RE: Scripting Band Arithmetic
6/30/09 11:31 PM as a reply to Anthony Lawrence Nguy-Robertson.
Yes, you can use the BandArithmetic Graph Processing Operator for that. Graph processing operators can be invoked using the BEAM Graph Processing Tool gpt, which you find in the bin folder of your BEAM installation.

For usage and a listing of available operators, type
1gpt -h

and for the special usage of the BandArithmetic operator, type
1gpt -h BandArithmetic

We will provide a usage example tomorrow.

The gpt is still an undocumented feature, in BEAM 4.7 we describe each operator and also provide a complete documentation for BEAM Graph Processing in general. Note that the list of operators will be extended in the future. In the cue are
  • Reprojection - Reprojection to various coordinate systems / map projections
  • Orthorectification - Reprojection including orthorectification using an external elevation model (DEM)
  • Subset - spatial and spectral subsets
  • Merge - merge bands of products with same grids
  • Export - export pixel data


Norman
Flag Flag
RE: Scripting Band Arithmetic
7/1/09 3:34 PM as a reply to Anthony Lawrence Nguy-Robertson.
A usage example:

Command:

./gpt.sh /home/.../request.xml -e -f BEAM-DIMAP -t /home/.../out/bandArithmetic /home/.../MER_RR__1PNMAP20070729_....N1 /home/.../MER_RR__2PNMAP20070729_022435_....N1

request.xml file

 1<graph>
 2  <version>1.0</version>
 3    <node id="node_ba">
 4      <operator>BandArithmetic</operator>
 5        <sources>
 6           <input1>${sourceProduct1}</input1>
 7           <input2>${sourceProduct2}</input2>
 8        </sources>
 9      <parameters>
10        <targetBands>
11          <targetBand>
12            <name>arithmBand1</name>
13            <expression>X &lt; 300 and Y &lt; 300 ? $input1.radiance_13 : $input2.reflec_13</expression>
14            <description>test1</description>
15            <type>float32</type>
16            <validExpression>arithmBand3 &lt; 70</validExpression>
17            <noDataValue>-99999</noDataValue>
18            <spectralBandIndex>0</spectralBandIndex>
19            <spectralWavelength>0.0</spectralWavelength>
20            <spectralBandwidth>0.0</spectralBandwidth>
21          </targetBand>
22          <targetBand>
23            <name>arithmBand2</name>
24            <expression>$input2.algal_2</expression>
25            <description>test2</description>
26            <type>float32</type>
27            <validExpression></validExpression>
28            <noDataValue>NaN</noDataValue>
29            <spectralBandIndex>0</spectralBandIndex>
30            <spectralWavelength>0.0</spectralWavelength>
31            <spectralBandwidth>0.0</spectralBandwidth>
32          </targetBand>
33          <targetBand>
34            <name>arithmBand3</name>
35            <expression>$input1.radiance_7</expression>
36            <description>test3</description>
37            <type>float32</type>
38            <validExpression></validExpression>
39            <noDataValue>NaN</noDataValue>
40            <spectralBandIndex>0</spectralBandIndex>
41            <spectralWavelength>0.0</spectralWavelength>
42            <spectralBandwidth>0.0</spectralBandwidth>
43          </targetBand>
44        </targetBands>
45      </parameters>
46    </node>
47  </graph>
Flag Flag
RE: Scripting Band Arithmetic
7/12/09 5:55 AM as a reply to Olga Faber.
As I said before I am new to Java. How do you reference this xml file in a Java IDE such as eclipse? My goal is to eventually write a program to process an entire directory of files. Unfortunately my programming experience lies in Matlab.
Flag Flag
RE: Scripting Band Arithmetic
7/13/09 12:50 AM as a reply to Olga Faber.
I have tried the command line approach without much success. Here is my xml code:

 1<graph>
 2<version>1.0</version>
 3  <node id = "1">
 4    <operator>BandArithmetic</operator>
 5      <sources>
 6         <input1>C:\MER_FR__2PNUPA20070520_154651_000000982058_00183_27291_7744.N1</input1>
 7      </sources>
 8    <parameters>
 9      <targetBands>
10        <targetBand>
11          <name>arithmBand1</name>
12          <expression>('reflec_3' >=0) ? (222.61*((1/reflec_7 - 1/reflec_9)* reflec_10) + 22.416) : NaN</expression>
13          <description>test1</description>
14          <type>float32</type>
15        </targetBand>
16      </targetBands>
17    </parameters>
18  </node>
19</graph>


This is the error I get on the command line:

1Error:  Missing source. Node Id: '1' Source Id:  'C:\MER_FR__2PNUPA2007020_154651_000000982058_00183_27291_7744.N1


Since the source is copy/paste I think the problem lies in the node id. How is that determined?
Flag Flag
RE: Scripting Band Arithmetic
7/13/09 6:48 PM as a reply to Olga Faber.
Could you provide a valid xml file for one of the example images? I am still having trouble with the command line. if I include the target in the command line (-t \filelocation), I now get a different error "Output format unknown'. Thanks!
Flag Flag
RE: Scripting Band Arithmetic
7/14/09 8:55 AM as a reply to Anthony Lawrence Nguy-Robertson.
Try to use:
command:
gpt.bat request.xml C:\MER_FR__2PNUPA20070520_154651_000000982058_00183_27291_7744.N1

request.xml file
 1<graph>
 2<version>1.0</version>
 3  <node id = "1">
 4    <operator>BandArithmetic</operator>
 5      <sources>
 6         <input1>${sourceProduct}</input1>
 7      </sources>
 8    <parameters>
 9      <targetBands>
10        <targetBand>
11          <name>arithmBand1</name>
12          <expression>('reflec_3' >=0) ? (222.61*((1/reflec_7 - 1/reflec_9)* reflec_10) + 22.416) : NaN</expression>
13          <description>test1</description>
14          <type>float32</type>
15        </targetBand>
16      </targetBands>
17    </parameters>
18  </node>
19</graph>
Flag Flag
RE: Scripting Band Arithmetic
7/14/09 9:04 AM as a reply to Anthony Lawrence Nguy-Robertson.
At the moment it is no possible to reference products directly from within the xml files. You have to give them on the commandline.

Please the see the newer example given by Olga.
Flag Flag
RE: Scripting Band Arithmetic
7/14/09 9:11 AM as a reply to Anthony Lawrence Nguy-Robertson.
The output format will be derived from the file extension.
Then your output file has to end with either ".dim", ".hdf" or ".tiff" to select BEAM-DIMAP, HDF-5 or GeoTIFF.
Or you give the format explicitly with the "-f" option.

Hope that helps,
Marco
Flag Flag
RE: Scripting Band Arithmetic
3/1/10 3:29 PM as a reply to Norman Fomferra.
Norman Fomferra:


The gpt is still an undocumented feature, in BEAM 4.7 we describe each operator and also provide a complete documentation for BEAM Graph Processing in general.

Norman


Any updates on this? I can't find anything from the documentation.
Flag Flag
RE: Scripting Band Arithmetic
3/2/10 10:24 AM as a reply to Mikko Kervinen.
Unfortunately we were not able to include the documentation for GPF for this release.
Time was to short at the end.

The best documentation we currently have is the one generated by gpt and the tutorial we have in our wiki.

best wishes
Marco
Flag Flag

 

Welcome to the BEAM Forum!

We encourage you to sign in our forum and participate in the BEAM community. The forum is maintained by the BEAM project team who will most likely answer your questions within 24 hours (except during common holidays) - if not done by other community members. Collaborate, share your knowledge and learn from other users!

If you don't find what you are looking for, please also consider the following external forums: