Building a Watershed pipeline using C#


This page will show you how to create a watershed workflow pipeline that would calculate the average rain fall inside a watershed that been extracted from an elevation model. This example should help you understand how to choose the needed processes to achieve different DGGS operations. at the end of the this example you would have the following Pipeline built:



The colors reflect the different steps of building this pipeline. In this example we would provide code examples using the C# SDK.

Step 0: initialize PYXIS Engine

In order to work with C# SDK, the first step is to initialize the PYXIS DGGS SDK.

 



Step 1: import elevation model

the first step is to get elevation data, so we can generate a watershed selection from it. Loading data using PYXIS Pipeline is made from several processes working togther:
  1. File - the first process is a pointer to the source data file. from example: gtopo30.dem. a Data File process is responsible to locate the required file in local file system, network file system, HDF or any other supported protocols in the future.
  2. Reader - the second process initialize a native format reader. currently this example show a GDAL Reader that leverage the GDAL library to ready the given file. 
  3. Sampler - we connect the native reader (xy coverage) into a sampler that perform quantization algorithms to assign a value for every given cell. from this point on - the rest of pipeline lives on DGGS structure.
  4. Cache - in order to speed up future operations, we can cache (memory/disk/network) the results per tile for future reference. 
PYXIS DGGS SDK provide simple methods to generate those pipelines from urls:

 


Step 2: create a watershed process for a given location.

In the second step we are using a watershed selector processes to generate a selection from the elevation model. the watershed process is an implementation of a custom version weighted shortest path algorithm to create a selection of cells.
That process require 2 inputs:
  1. Elevation values - we are going to use the Cache from the previous step as the calculator of elevation values.
  2. a Cell - A target cell to specify the origin for the watershed algorithm to run from.

Here is an example of PYXIS DGGS Pipeline API that allow you to create individual processes and connect them together:

 


Step 3: import rain fall data & use average aggregate function on rain-fall data and watershed selection

now that we have generated a new selection of cells. we can use it to calculate geo-spatial summaries on any other DGGS datasets. In this example we would use a rainfall NetCDF data, as it a raster data we would built similar pipeline as we did in step 1.
Once we have the rainfall data quantisize into DGGS, we can use Coverage Histogram process to generate a summary.

That process require 2 inputs:
  1. DGGS Values - values to aggregate.
  2. Selection - region to perform aggregation on.
The PYXIS DGGS SDK provides a simple interface to perform simple aggregations on pipelines. Behind the sense, these functions build the required pipelines on demand.

 


Step 4: import OGC WCS crops data set to refine selection

In the last step we are going to use WCS Process to connect to a remote OGC WCS server to load crop data information. We would also connect this process into a Cache process to reduce network traffic. However, this dataset would be used to refine the watershed selection. we refine the selection using 3 processes:
  1. Calculator - we would add a condition process that would check if the WCS value for a given cell is corn (value == 1). this is a calculator process because it assigns a true/false value for every cell.
  2. Selector - the true/false values can be converted into a refined selection by intersecting the watershed selection with all cells that have value == true.
  3. Aggregator - the new selection can be used as input to the Coverage Histogram process to calculate the new average rainfall on the new and refined selection.

 


Comments