Skip to content

Water bodies detection

Goal

Wrap the CommandLineTool with a CWL Workflow

Lab

This step has a dedicated lab available at /workspace/quickwin/practice-labs/Workflow.ipynb

How to wrap a CWL CommandLineTool with a CWL Workflow

The Cloud native Workflow orchestrates the wrapped Python application command line tool as a CWL CommandLineTool step with input parameters:

  • a SpatioTemporal Asset Catalog (STAC) Item
  • a bounding box area of interest (AOI)
  • the EPSG code of the bounding box area of interest
  • a list of common band names (["green", "nir"])
graph TB A[STAC Item URL] A --> B(("Detect water bodies")); B --> C[STAC Catalog]

The CWL Workflow is shown below and the lines highlighted chain the water bodies detection step:

app-water-body-cloud-native.cwl
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
cwlVersion: v1.0
$namespaces:
  s: https://schema.org/
s:softwareVersion: 1.0.0
schemas:
  - http://schema.org/version/9.0/schemaorg-current-http.rdf
$graph:
  - class: Workflow
    id: main
    label: Water bodies detection based on NDWI and the otsu threshold
    doc: Water bodies detection based on NDWI and otsu threshold applied to a single Sentinel-2 COG STAC item
    requirements: []
    inputs:
      aoi:
        label: area of interest
        doc: area of interest as a bounding box
        type: string
      epsg:
        label: EPSG code
        doc: EPSG code
        type: string
        default: "EPSG:4326"
      bands:
        label: bands used for the NDWI
        doc: bands used for the NDWI
        type: string[]
        default: ["green", "nir"]
      item:
        doc: Reference to a STAC item
        label: STAC item reference
        type: string
    outputs:
      - id: stac_catalog
        outputSource:
          - node_detect/stac-catalog
        type: Directory
    steps:
      node_detect:
        run: "#detect-water-body"
        in:
          item: item
          aoi: aoi
          epsg: epsg
          band: bands
        out:
          - stac-catalog
  - class: CommandLineTool
    id: detect-water-body
    requirements:
        InlineJavascriptRequirement: {}
        EnvVarRequirement:
          envDef:
            PYTHONPATH: /app
        ResourceRequirement:
          coresMax: 1
          ramMax: 512
    hints:
      DockerRequirement:
        dockerPull: localhost/detect-water-body:latest
    baseCommand: ["python", "-m", "app"]
    arguments: []
    inputs:
      item:
        type: string
        inputBinding:
            prefix: --input-item
      aoi:
        type: string
        inputBinding:
            prefix: --aoi
      epsg:
        type: string
        inputBinding:
            prefix: --epsg
      band:
        type:
          - type: array
            items: string
            inputBinding:
              prefix: '--band'

    outputs:
      stac-catalog:
        outputBinding:
            glob: .
        type: Directory

To run this CWL document, one does:

terminal
export WORKSPACE=/workspace/quickwin

command -v podman >/dev/null 2>&1 && { 
    flag="--podman"
}

cwltool ${flag} \
    --outdir ${WORKSPACE}/runs \
    ${WORKSPACE}/cwl-workflow/app-water-body-cloud-native.cwl \
    --item "https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2B_10TFK_20210713_0_L2A" \
    --aoi="-121.399,39.834,-120.74,40.472" \
    --epsg "EPSG:4326" \
    --band "green" \
    --band "nir" 

Expected outcome

The folder /workspace/quickwin/runs contains:

(base) jovyan@jupyter-fbrito--training:~/quickwin$ tree runs
runs
└── jtv7v57e
    ├── S2B_10TFK_20210713_0_L2A
    │   ├── S2B_10TFK_20210713_0_L2A.json
    │   └── otsu.tif
    ├── catalog.json
    └── otsu.tif

2 directories, 4 files