Skip to content

Normalized difference

Goal

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

CWL CommandLineTool wrapping the step

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

cwl-cli/norm-diff.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
cwlVersion: v1.0

class: CommandLineTool
id: norm_diff
requirements:
  InlineJavascriptRequirement: {}
  EnvVarRequirement:
    envDef:
      PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      PYTHONPATH: /app
  ResourceRequirement:
    coresMax: 1
    ramMax: 512
hints:
  DockerRequirement:
    dockerPull: localhost/norm-diff:latest
baseCommand: ["python", "-m", "app"]
arguments: []
inputs:
  rasters:
    type: File[]
    inputBinding:
      position: 1
outputs:
  ndwi:
    outputBinding:
      glob: '*.tif'
    type: File

Steps

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
export WORKSPACE=/workspace/app-package-training-bids23

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/runs contains:

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

0 directories, 3 files