Otsu threshold
Goal
Wrap the crop step as a Common Workflow Language CommandLineTool and exectute it with a CWL runner.
Lab
This step has a dedicated lab at practice-labs/3-CWL-CommandLineTools/otsu.ipynb.
The CWL document below shows the crop step wrapped as a CWL CommandLineTool:
| cwlVersion: v1.2
$namespaces:
s: https://schema.org/
# Training-example authors and creation date mirror codemeta.json.
s:name: Otsu threshold
s:description: Detect water bodies by applying the Otsu threshold to a water index raster.
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: otsu
requirements:
InlineJavascriptRequirement: {}
EnvVarRequirement:
envDef:
PATH: /app/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ResourceRequirement:
coresMax: 1
ramMin: 1024
ramMax: 1024
NetworkAccess:
networkAccess: false
DockerRequirement:
dockerPull: localhost/otsu:latest
baseCommand: otsu
arguments: []
inputs:
raster:
type: File
inputBinding:
position: 1
prefix: --raster
label: Water index raster
doc: Normalized difference water index raster to threshold.
outputs:
binary_mask_item:
outputBinding:
glob: '*.tif'
type: File
label: Water body mask
doc: Binary raster mask identifying detected water bodies.
|
Steps
Run the CWL document using the cwltool CWL runner to execute the otsu 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/otsu.cwl \
--raster \
${WORKSPACE}/runs/norm_diff.tif
|
sh -x ${WORKSPACE}/scripts/cwl-cli-otsu.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
└── otsu.tif
0 directories, 4 files