The GPT Cookbook

BandMaths


Creates a new file with math band(s) based on an input source file with the option to retain source file bands in the new file.


Example 1  Create Math Bands and Retain Source Bands

Example 2  Create Math Bands and Retain Source Bands (Variables Option)

Example 3  Create only Math Bands

Example 4  Remove the "_count" Bands from a Mosaic File (OC Level2)








Example 1    Create Math Band and Retain Source Bands


This creates a copy of a file adding math band(s) to it.


Command Line Entry

gpt BandMaths.xml -p BandMathsEx01.par -Ssource=A2010283180500.L2_LAC_OC.nc -t A2010283180500.L2_LAC_OC_BandMathsEx01.dim

File = BandMaths.xml

<graph id="BandMathsGraph">
  <version>1.0</version>
  <node id="BandMathsNode">
    <operator>BandMaths</operator>
    <sources>
      <source>${source}</source>
    </sources>
    <parameters>
      <copySourceFile>${copySourceFile}</copySourceFile>
      <targetBands>
        <targetBand>
          <name>${band1Name}</name>
          <type>${band1Type}</type>
          <expression>${band1Expression}</expression>
          <description>${band1Description}</description>
          <unit>${band1Unit}</unit>
          <validExpression>${band1ValidExpression}</validExpression>
          <noDataValue>${band1NoDataValue}</noDataValue>
          <spectralWavelength>${band1SpectralWavelength}</spectralWavelength>
          <spectralBandwidth>${band1SpectralBandwidth}</spectralBandwidth>
        </targetBand>
      </targetBands>
    </parameters>
  </node>
</graph>

File = BandMathsEx01.par

copySourceFile=true
band1Name=aod
band1Type=float64
band1Expression=if (Kd_490 != 0) then 1.3/Kd_490 else NaN
band1Description=apparent optical depth
band1Unit=meters
band1ValidExpression=Kd_490 &gt;= 0.01000 and Kd_490 &lt;= 6.00000
band1NoDataValue=-0.19837031
band1SpectralWavelength=490.0
band1SpectralBandwidth=10.0




Example 2    Create Math Band and Retain Source Bands (Variables Option)


This creates a copy of a file adding math band(s) to it.

This is exactly the same as example 1 except it illustrates the use of the variable options.

Note: variables only apply to parameter "expression" and not to parameter "validExpression".


Command Line Entry

gpt BandMathsVariables.xml -p BandMathsEx02.par -Ssource=A2010283180500.L2_LAC_OC.nc -t A2010283180500.L2_LAC_OC_BandMathsEx02.dim

File = BandMathsVariables.xml

<graph id="BandMathsVariablesGraph">
  <version>1.0</version>
  <node id="BandMathsNode">
    <operator>BandMaths</operator>
    <sources>
      <source>${source}</source>
    </sources>
    <parameters>
      <copySourceFile>${copySourceFile}</copySourceFile>
      <targetBands>
        <targetBand>
          <name>${band1Name}</name>
          <type>${band1Type}</type>
          <expression>${band1Expression}</expression>
          <description>${band1Description}</description>
          <unit>${band1Unit}</unit>
          <validExpression>${band1ValidExpression}</validExpression>
          <noDataValue>${band1NoDataValue}</noDataValue>
          <spectralWavelength>${band1SpectralWavelength}</spectralWavelength>
          <spectralBandwidth>${band1SpectralBandwidth}</spectralBandwidth>
        </targetBand>
      </targetBands>
      <variables>
        <variable>
          <name>${var1Name}</name>
          <type>${var1Type}</type>
          <value>${var1Value}</value>
        </variable>
      </variables>
    </parameters>
  </node>
</graph>

File = BandMathsEx02.par

copySourceFile=true
band1Name=aod
band1Type=float64
band1Expression=if (Kd_490 != 0) then (AOD_KD490_FACTOR/Kd_490) else NaN
band1Description=apparent optical depth
band1Unit=meters
band1ValidExpression=Kd_490 &gt;= 0.01000 and Kd_490 &lt;= 6.00000
band1NoDataValue=-0.19837031
band1SpectralWavelength=490.0
band1SpectralBandwidth=10.0
var1Name=AOD_KD490_FACTOR
var1Type=float64
var1Value=1.3




Example 3    Create only Math Bands


This creates a new file based off an input source file adding math band(s) to it (the bands and masks of the source file are not transferred to the output file).

This uses the graph file of example 1 and this is identical to example 1 except that the band1ValidExpression does not point to the source band Kd_490 since it does not exist in the created file.


Command Line Entry

gpt BandMaths.xml -p BandMathsEx03.par -Ssource=A2010283180500.L2_LAC_OC.nc -t A2010283180500.L2_LAC_OC_BandMathsEx03.dim

File = BandMathsEx03.par

copySourceFile=false
band1Name=aod
band1Type=float64
band1Expression=if (Kd_490 != 0) then 1.3/Kd_490 else NaN
band1Description=apparent optical depth
band1Unit=meters
band1ValidExpression=aod &gt; (1.3/6.0) and aod &lt; (1.3/0.01)
band1NoDataValue=-0.19837031
band1SpectralWavelength=490.0
band1SpectralBandwidth=10.0




Example 4    Remove the "_count" Bands from a Mosaic File (OC Level2)


For each band in a Mosaic file there is a corresponding "count" band used in its validPixelExpression (for instance the chlor_a band sets it's validPixelExpression based on the chlor_a_count band: expr= chlor_a_count > 0). In this example we take a Mosaic file and by using the BandMaths operator to apply the validPixelExpression, we create a new file which does not contain these "count" bands.

This example is doing the full set of 20 bands in the OC suite (Note: this example has been prepared during the SeaDAS 7.5 release, so any product changes in the future for the OC suite are not accounted for here).

The source file A2017023193500_MosaicEx05.dim used here was produced by Mosaic Example 5


Command Line Entry

gpt BandMathsEx04.xml -p BandMathsEx04.par -Ssource=A2017023193500_MosaicEx05.dim -t A2017023193500_BandMathsEx04.dim

File = BandMathsEx04.xml

<graph id="BandMathsGraph">
  <version>1.0</version>
  <node id="BandMathsNode">
    <operator>BandMaths</operator>
    <sources>
      <source>${source}</source>
    </sources>
    <parameters>
      <targetBands>
        <targetBand>
          <name>${band1Name}</name>
          <type>float64</type>
          <expression>if (${band1Name}_count &gt; 0) then ${band1Name} else ${noDataValue}</expression>
          <description>${band1Description}</description>
          <unit>${band1Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band1SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band2Name}</name>
          <type>float64</type>
          <expression>if (${band2Name}_count &gt; 0) then ${band2Name} else ${noDataValue}</expression>
          <description>${band2Description}</description>
          <unit>${band2Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band2SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band3Name}</name>
          <type>float64</type>
          <expression>if (${band3Name}_count &gt; 0) then ${band3Name} else ${noDataValue}</expression>
          <description>${band3Description}</description>
          <unit>${band3Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band3SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band4Name}</name>
          <type>float64</type>
          <expression>if (${band4Name}_count &gt; 0) then ${band4Name} else ${noDataValue}</expression>
          <description>${band4Description}</description>
          <unit>${band4Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band4SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band5Name}</name>
          <type>float64</type>
          <expression>if (${band5Name}_count &gt; 0) then ${band5Name} else ${noDataValue}</expression>
          <description>${band5Description}</description>
          <unit>${band5Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band5SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band6Name}</name>
          <type>float64</type>
          <expression>if (${band6Name}_count &gt; 0) then ${band6Name} else ${noDataValue}</expression>
          <description>${band6Description}</description>
          <unit>${band6Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band6SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band7Name}</name>
          <type>float64</type>
          <expression>if (${band7Name}_count &gt; 0) then ${band7Name} else ${noDataValue}</expression>
          <description>${band7Description}</description>
          <unit>${band7Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band7SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band8Name}</name>
          <type>float64</type>
          <expression>if (${band8Name}_count &gt; 0) then ${band8Name} else ${noDataValue}</expression>
          <description>${band8Description}</description>
          <unit>${band8Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band8SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band9Name}</name>
          <type>float64</type>
          <expression>if (${band9Name}_count &gt; 0) then ${band9Name} else ${noDataValue}</expression>
          <description>${band9Description}</description>
          <unit>${band9Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band9SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band10Name}</name>
          <type>float64</type>
          <expression>if (${band10Name}_count &gt; 0) then ${band10Name} else ${noDataValue}</expression>
          <description>${band10Description}</description>
          <unit>${band10Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band10SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band11Name}</name>
          <type>float64</type>
          <expression>if (${band11Name}_count &gt; 0) then ${band11Name} else ${noDataValue}</expression>
          <description>${band11Description}</description>
          <unit>${band11Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band11SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band12Name}</name>
          <type>float64</type>
          <expression>if (${band12Name}_count &gt; 0) then ${band12Name} else ${noDataValue}</expression>
          <description>${band12Description}</description>
          <unit>${band12Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band12SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band13Name}</name>
          <type>float64</type>
          <expression>if (${band13Name}_count &gt; 0) then ${band13Name} else ${noDataValue}</expression>
          <description>${band13Description}</description>
          <unit>${band13Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band13SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band14Name}</name>
          <type>float64</type>
          <expression>if (${band14Name}_count &gt; 0) then ${band14Name} else ${noDataValue}</expression>
          <description>${band14Description}</description>
          <unit>${band14Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band14SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band15Name}</name>
          <type>float64</type>
          <expression>if (${band15Name}_count &gt; 0) then ${band15Name} else ${noDataValue}</expression>
          <description>${band15Description}</description>
          <unit>${band15Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band15SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band16Name}</name>
          <type>float64</type>
          <expression>if (${band16Name}_count &gt; 0) then ${band16Name} else ${noDataValue}</expression>
          <description>${band16Description}</description>
          <unit>${band16Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band16SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band17Name}</name>
          <type>float64</type>
          <expression>if (${band17Name}_count &gt; 0) then ${band17Name} else ${noDataValue}</expression>
          <description>${band17Description}</description>
          <unit>${band17Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band17SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band18Name}</name>
          <type>float64</type>
          <expression>if (${band18Name}_count &gt; 0) then ${band18Name} else ${noDataValue}</expression>
          <description>${band18Description}</description>
          <unit>${band18Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band18SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band19Name}</name>
          <type>float64</type>
          <expression>if (${band19Name}_count &gt; 0) then ${band19Name} else ${noDataValue}</expression>
          <description>${band19Description}</description>
          <unit>${band19Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band19SpectralWavelength}</spectralWavelength>
        </targetBand>

        <targetBand>
          <name>${band20Name}</name>
          <type>float64</type>
          <expression>if (${band20Name}_count &gt; 0) then ${band20Name} else ${noDataValue}</expression>
          <description>${band20Description}</description>
          <unit>${band20Unit}</unit>
          <noDataValue>${noDataValue}</noDataValue>
          <spectralWavelength>${band20SpectralWavelength}</spectralWavelength>
        </targetBand>

      </targetBands>
    </parameters>
  </node>
</graph>

File = BandMathsEx04.par

noDataValue=NaN

band1Name=aot_869
band1Description=Aerosol optical thickness at 869 nm
band1Unit=
band1SpectralWavelength=869

band2Name=angstrom
band2Description=Aerosol Angstrom exponent, 443 to 865 nm
band2Unit=
band2SpectralWavelength=0.0

band3Name=chlor_a
band3Description=Chlorophyll Concentration, OCI Algorithm
band3Unit=mg m^-3
band3SpectralWavelength=0.0

band4Name=chl_ocx
band4Description=Chlorophyll Concentration, OC3 Algorithm
band4Unit=mg m^-3
band4SpectralWavelength=0.0

band5Name=ipar
band5Description=Instantaneous Photosynthetically Available Radiation
band5Unit=einstein m^-2 s^-1
band5SpectralWavelength=0.0

band6Name=Kd_490
band6Description=Diffuse attenuation coefficient at 490 nm, KD2 algorithm
band6Unit=m^-1
band6SpectralWavelength=490.0

band7Name=nflh
band7Description=Normalized Fluorescence Line Height
band7Unit=W m^-2 um^-1 sr^-1
band7SpectralWavelength=0.0

band8Name=Rrs_412
band8Description=Remote sensing reflectance at 412 nm
band8Unit=sr^-1
band8SpectralWavelength=412

band9Name=Rrs_443
band9Description=Remote sensing reflectance at 443 nm
band9Unit=sr^-1
band9SpectralWavelength=443

band10Name=Rrs_469
band10Description=Remote sensing reflectance at 469 nm
band10Unit=sr^-1
band10SpectralWavelength=469

band11Name=Rrs_488
band11Description=Remote sensing reflectance at 488 nm
band11Unit=sr^-1
band11SpectralWavelength=488

band12Name=Rrs_531
band12Description=Remote sensing reflectance at 531 nm
band12Unit=sr^-1
band12SpectralWavelength=531

band13Name=Rrs_547
band13Description=Remote sensing reflectance at 547 nm
band13Unit=sr^-1
band13SpectralWavelength=547

band14Name=Rrs_555
band14Description=Remote sensing reflectance at 555 nm
band14Unit=sr^-1
band14SpectralWavelength=555

band15Name=Rrs_645
band15Description=Remote sensing reflectance at 645 nm
band15Unit=sr^-1
band15SpectralWavelength=645

band16Name=Rrs_667
band16Description=Remote sensing reflectance at 667 nm
band16Unit=sr^-1
band16SpectralWavelength=667

band17Name=Rrs_678
band17Description=Remote sensing reflectance at 678 nm
band17Unit=sr^-1
band17SpectralWavelength=678

band18Name=par
band18Description=Photosynthetically Available Radiation, R. Frouin
band18Unit=einstein m^-2 day^-1
band18SpectralWavelength=0.0

band19Name=pic
band19Description=Calcite Concentration, Balch and Gordon
band19Unit=mol m^-3
band19SpectralWavelength=0.0

band20Name=poc
band20Description=Particulate Organic Carbon, D. Stramski, 2007 (443/555 version)
band20Unit=mg m^-3
band20SpectralWavelength=0.0