Skip to content

Normalized difference

Goal

Wrap the norm_diff step as a Common Workflow Language CommandLineTool and execute it with a CWL runner.

Lab

This step has a dedicated lab at practice-labs/3-CWL-CommandLineTools/normalized-difference.ipynb.

CWL CommandLineTool wrapping the step

The CWL document below shows the norm_diff step wrapped as a CWL CommandLineTool:

cwl-cli/norm-diff.cwl
cwlVersion: v1.2
$namespaces:
  s: https://schema.org/
# Training-example authors and creation date mirror codemeta.json.
s:name: Normalized difference
s:description: Compute the normalized difference water index from cropped raster bands.
s:dateCreated: '2022-09-01'
s:license:
  s:name: Creative Commons Attribution-ShareAlike 4.0 International
  s:url: https://creativecommons.org/licenses/by-sa/4.0/
  s:identifier: CC-BY-SA-4.0
s:softwareHelp:
  s:name: Mastering Earth Observation Application Packaging with CWL
  s:url: https://eoap.github.io/mastering-app-package
s:publisher:
  s:name: EO Application Packaging
  s:identifier: https://github.com/eoap
s:author:
  - s:givenName: Jane
    s:familyName: Doe
    s:email: jane.doe@acme.earth
    s:affiliation:
      s:name: ACME
  - s:givenName: John
    s:familyName: Doe
    s:email: john.doe@acme.earth
    s:affiliation:
      s:name: ACME
s:softwareRequirements:
  - container runtime
  - cwl runner
s:softwareVersion: 2.0.2

class: CommandLineTool
id: norm_diff
requirements:
  InlineJavascriptRequirement: {}
  EnvVarRequirement:
    envDef:
      PATH: /app/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  ResourceRequirement:
    coresMax: 1
    ramMin: 2048
    ramMax: 2048
  NetworkAccess:
    networkAccess: false
  DockerRequirement:
    dockerPull: localhost/norm-diff:latest
baseCommand: norm_diff
arguments: []
inputs:
  rasters:
    type:
      type: array
      items: File
      inputBinding:
        prefix: --rasters
    inputBinding:
      position: 1
    label: Input rasters
    doc: Raster files used for normalized difference computation or catalog generation.
outputs:
  ndwi:
    outputBinding:
      glob: '*.tif'
    type: File
    label: Normalized difference water index
    doc: Water index raster computed from the input bands.

Steps

Run the CWL document using the cwltool CWL runner to execute the norm_diff step with:

export WORKSPACE=/workspace/mastering-app-package
export RUNTIME=${WORKSPACE}/runs
mkdir -p ${RUNTIME}
cd ${RUNTIME}

cwltool \
    --podman \
    --outdir ${WORKSPACE}/runs \
    ${WORKSPACE}/cwl-cli/norm-diff.cwl \
    --rasters \
    ${WORKSPACE}/runs/crop_green.tif \
    --rasters \
    ${WORKSPACE}/runs/crop_nir.tif
sh -x ${WORKSPACE}/scripts/cwl-cli-norm-diff.sh

Expected outcome

The folder /workspace/mastering-app-package/runs contains:

(base) jovyan@coder-mrossi:~/runs$ tree .
.
├── crop_green.tif
├── crop_nir.tif
└── norm_diff.tif

0 directories, 3 files