Skip to content

How to capture JSON stdout and re-use it

  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
cwlVersion: v1.0

$graph:
- class: Workflow

  id: main

  requirements: 
  - class: InlineJavascriptRequirement

  inputs:

    stac_item: 
      type: string
    asset_id:
      type: string

  outputs:

    tif:
      outputSource: node_translate/tif
      type: File

  steps:

    node_stac:

      in: 
        stac_item: stac_item

      out: 
      - asset

      run:
        "#stac"

    node_translate:

      in:
        asset: 
          source: node_stac/asset
        asset_id: asset_id

      out: 
      - tif

      run: 
        "#translate"

- class: CommandLineTool

  id: stac

  requirements:
    InlineJavascriptRequirement: {}
  hints:
    DockerRequirement: 
      dockerPull: docker.io/curlimages/curl:latest

  baseCommand: curl

  stdout: message

  arguments: 
  - $( inputs.stac_item )

  inputs:

    stac_item:
      type: string

  outputs:

    asset: 
      type: Any
      outputBinding:
        glob: message
        loadContents: true
        outputEval: ${ return JSON.parse(self[0].contents).assets; }

- class: CommandLineTool

  id: translate

  requirements:
    InlineJavascriptRequirement: {}
    EnvVarRequirement:
      envDef:
        PROJ_LIB: /srv/conda/envs/notebook/share/proj

  hints:
    DockerRequirement: 
      dockerPull: docker.io/osgeo/gdal:latest

  baseCommand: gdal_translate

  arguments: 
  - valueFrom: |
      $( '/vsicurl/' + inputs.asset[inputs.asset_id].href )
  - valueFrom: |
      $( inputs.asset[inputs.asset_id].href.split("/").slice(-1)[0] )

  inputs:

    asset:
      type: Any
    asset_id:
      type: string

  outputs:

    tif: 
      type: File
      outputBinding:
        glob: "*.tif"
stac_item:  "https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2B_53HPA_20210723_0_L2A"
asset_id: "B01"