Skip to content

How to create conditional workflows

  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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
cwlVersion: v1.2

$graph:
- class: Workflow

  id: main

  requirements: 
  - class: MultipleInputFeatureRequirement
  - class: ScatterFeatureRequirement
  - class: InlineJavascriptRequirement

  inputs:

    red: 
      type: string
    green: 
      type: string
    blue: 
      type: string
    epsg_code: 
      type: string

  outputs:

    preview: 
      type: File[]
      outputSource: 
      - node_warp/preview
      - node_translate/preview
      pickValue: all_non_null
      linkMerge: merge_flattened

  steps:

    node_translate:

      in: 
        band: [red, green, blue]
        epsg_code: epsg_code
      out: 
      - preview

      run:
        "#translate"

      when: $( inputs.epsg_code == "native")


      scatter: band
      scatterMethod: dotproduct 

    node_warp:

      in: 
        band: [red, green, blue]
        epsg_code: epsg_code

      out: 
      - preview

      run:
        "#warp"

      when: $( inputs.epsg_code != "native")

      scatter: band
      scatterMethod: dotproduct

- class: CommandLineTool

  id: translate

  requirements:
    InlineJavascriptRequirement: {}
    EnvVarRequirement:
      envDef:
        PROJ_LIB: /srv/conda/envs/notebook/share/proj
    NetworkAccess:
      networkAccess: true
  hints: 
    DockerRequirement: 
      dockerPull: docker.io/osgeo/gdal 

  baseCommand: gdal_translate

  arguments: 
  - -of
  - COG
  - -ot 
  - Byte
  - valueFrom: $( inputs.band )
  - valueFrom: $( inputs.band.split("/").slice(-1)[0] )

  inputs:

    band: 
      type: string

  outputs:

    preview: 
      type: File
      outputBinding:
        glob: "*.tif"


- class: CommandLineTool

  id: warp

  requirements:
    InlineJavascriptRequirement: {}
    EnvVarRequirement:
      envDef:
        PROJ_LIB: /srv/conda/envs/notebook/share/proj
    NetworkAccess:
      networkAccess: true
  hints:
    DockerRequirement: 
      dockerPull: docker.io/osgeo/gdal  

  baseCommand: gdalwarp

  arguments: 
  - -of
  - COG
  - -ot 
  - Byte
  - -t_srs 
  - valueFrom: $( inputs.epsg_code )
  - valueFrom: $( inputs.band )
  - valueFrom: $( inputs.band.split("/").slice(-1)[0].replace(".TIF", ".tif") )

  inputs:

    band: 
      type: string
    epsg_code:
      type: string

  outputs:

    preview: 
      type: File
      outputBinding:
        glob: "*.tif"
red: '/vsicurl/https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/10/T/FK/2021/7/S2B_10TFK_20210713_0_L2A/B04.tif'
green: '/vsicurl/https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/10/T/FK/2021/7/S2B_10TFK_20210713_0_L2A/B03.tif'
blue: '/vsicurl/https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/10/T/FK/2021/7/S2B_10TFK_20210713_0_L2A/B02.tif'
epsg_code: "EPSG:4326"
# epsg_code: "native"

Reference