## GPT Cookbook: Subset

Creates a file which is subset copy of a source input file. There are several dimensions in which you can subset the file: 1. You can reduce the number of raster bands, selecting only your desired bands. 2. You can do an area crop of the geometric bounds of the file, where the area crop is done in either pixel space, or in geographic coordinate space. 3. You can subsample the file such that you retain only every other, 3rd, 4th, etc. pixel in the raster. 4. You can retain/discard file metadata.

Example 1 Geographic Region Crop

This performs an area crop in geographic coordinate space. The bounded region is over the Gulf of Mexico.

Command Line Entry

    gpt SubsetGraphEx01.xml -p SubsetEx01.par -Pifile=A2017023193500.L2_LAC_OC.nc -Pofile=A2017023193500_SubsetEx01.dim

File = SubsetGraphEx01.xml

    <graph id="GeoCropGraph">
        <version>1.0</version>
        <node id="Read">
            <operator>Read</operator>
            <sources/>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <file>${ifile}</file>
                <formatName>SeaDAS-L2</formatName>
            </parameters>
        </node>
        <node id="Subset">
            <operator>Subset</operator>
            <sources>
                <sourceProduct refid="Read"/>
            </sources>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <geoRegion>POLYGON((${west} ${north}, ${east} ${north}, ${east} ${south}, ${west} ${south}, ${west} ${north}))</geoRegion>
            </parameters>
        </node>
        <node id="Write">
            <operator>Write</operator>
            <sources>
                <sourceProduct refid="Subset"/>
            </sources>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <file>${ofile}</file>
                <formatName>BEAM-DIMAP</formatName>
            </parameters>
        </node>
    </graph>

File = SubsetEx01.par

    north=31.0
    south=17.5
    west=-98.5
    east=-80.0

Example 2 Pixel Area Crop

This performs an area crop in pixel space.

Note: Here we will crop off 240 pixels at both the beginning and end of the scan. In other words the easternmost and westernmost pixels. One reason for doing this might be to eliminate high sensor zenith angle (low resolution) pixels from the scene. For a standard MODIS level-2 1km LAC file, this approximates the removal of pixels above a 40 degree sensor zenith angle. The level-2 file was imaged January 23 2017 over the Gulf of Mexico by the MODIS Aqua instrument.

Command Line Entry

    gpt SubsetGraphEx02.xml -p SubsetEx02.par --Pifile=A2017023193500.L2_LAC_OC.nc -Pofile=A2017023193500_SubsetEx02.dim

File = SubsetGraphEx02.xml

    <graph id="PixelCropGraph">
        <version>1.0</version>
        <node id="Read">
            <operator>Read</operator>
            <sources/>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <file>${ifile}</file>
                <formatName>SeaDAS-L2</formatName>
            </parameters>
        </node>
        <node id="Subset">
            <operator>Subset</operator>
            <sources>
                <sourceProduct refid="Read"/>
            </sources>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <region>${x},${y},${width},${height}</region>
            </parameters>
        </node>
        <node id="Write">
            <operator>Write</operator>
            <sources>
                <sourceProduct refid="Subset"/>
            </sources>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <file>${ofile}</file>
                <formatName>BEAM-DIMAP</formatName>
            </parameters>
        </node>
    </graph>

File = SubsetEx02.par

    x=240
    y=0
    width=873
    height=2030

Example 3 Full Scene Subsample

This uses the SeaDAS Subset tool in GPT (command line) mode to generate a subsampled copy of an input file. In this case, we will subsample the input file by a factor of two evenly in both the x and y direction.

Note: this is not a statistical mean based downsampling, but an incremental walk through subsampling of the pixels, throwing away the in-between skipped over pixels.

Caution: there is currently a bug which prevents usage of the boolean parameter "fullSwath" which would ideally be used when retaining the full scene dimensions of the original file. The workaround here is to specifically define the pixel crop dimensions for the full input file as shown in this example.

Command Line Entry

    gpt SubsetGraphEx03.xml -p SubsetEx03.par --Pifile=A2017023193500.L2_LAC_OC.nc -Pofile=A2017023193500_SubsetEx03.dim

File = SubsetGraphEx03.xml

    <graph id="SubsampleGraph">
        <version>1.0</version>
        <node id="Read">
            <operator>Read</operator>
            <sources/>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <file>${ifile}</file>
                <formatName>SeaDAS-L2</formatName>
            </parameters>
        </node>
        <node id="Subset">
            <operator>Subset</operator>
            <sources>
                <sourceProduct refid="Read"/>
            </sources>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <region>${x},${y},${width},${height}</region>
                <subSamplingX>${subsampling}</subSamplingX>
                <subSamplingY>${subsampling}</subSamplingY>
            </parameters>
        </node>
        <node id="Write">
            <operator>Write</operator>
            <sources>
                <sourceProduct refid="Subset"/>
            </sources>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <file>${ofile}</file>
                <formatName>BEAM-DIMAP</formatName>
            </parameters>
        </node>
    </graph>

File = SubsetGraphEx03.par

    subsampling=2
    x=0
    y=0
    width=1354
    height=2030

Example 4 Full Scene Band Subset

This example generates an output file which is essentially a copy of the original file, but retaining only a few select bands.

Caution: there is currently a bug which prevents usage of the boolean parameter "fullSwath" which would ideally be used when retaining the full scene dimensions of the original file. The workaround here is to specifically define the pixel crop dimensions for the full input file as shown in this example.

Command Line Entry

    gpt SubsetGraphEx04.xml -p SubsetEx04.par -Pifile=A2017023193500.L2_LAC_OC.nc -Pofile=A2017023193500_SubsetEx04.dim

File = SubsetGraphEx04.xml

    <graph id="BandSubsetGraph">
        <version>1.0</version>
        <node id="Read">
            <operator>Read</operator>
            <sources/>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <file>${ifile}</file>
                <formatName>SeaDAS-L2</formatName>
            </parameters>
        </node>
        <node id="Subset">
            <operator>Subset</operator>
            <sources>
                <sourceProduct refid="Read"/>
            </sources>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <bandNames>${bands}</bandNames>
                <region>${x},${y},${width},${height}</region>
            </parameters>
        </node>
        <node id="Write">
            <operator>Write</operator>
            <sources>
                <sourceProduct refid="Subset"/>
            </sources>
            <parameters class="com.bc.ceres.binding.dom.XppDomElement">
                <file>${ofile}</file>
                <formatName>BEAM-DIMAP</formatName>
            </parameters>
        </node>
    </graph>

File = SubsetEx04.par

    bands=chlor_a,Kd_490,Rrs_443,Rrs_547
    x=0
    y=0
    width=1354
    height=2030