Open-EO / openeo.org

openeo.org landing page
https://openeo.org
Apache License 2.0
5 stars 15 forks source link

export as JSON process graph #50

Closed jonathom closed 2 years ago

jonathom commented 2 years ago

@m-mohr can you add the js part or point me in the right direction? toJSON seemed to only export the current process node.

m-mohr commented 2 years ago

Have you tried JSON.stringifly(builder.toJSON(), null, 2)?

jonathom commented 2 years ago

Ah, thanks! But pasting the graph into the web editor and clicking "visual model", I get No result node found for process graph. That seems to be because the property "result": true is not set in "process_id": "save_result", when doing

    let graph = JSON.stringify(builder.toJSON(), null, 2)
    console.log(graph)

Example graph from JSON.stringify without "result": true:

{
  "process_graph": {
    "loadco1": {
      "process_id": "load_collection",
      "arguments": {
        "id": "SENTINEL2_L2A_SENTINELHUB",
        "spatial_extent": {
          "west": 8.5464,
          "south": 54.4473,
          "east": 9.0724,
          "north": 54.5685
        },
        "temporal_extent": [
          "2021-03-05",
          "2021-03-05"
        ],
        "bands": [
          "B02",
          "B04",
          "B08",
          "SCL"
        ]
      }
    },
    "reduce1": {
      "process_id": "reduce_dimension",
      "arguments": {
        "data": {
          "from_node": "loadco1"
        },
        "reducer": {
          "process_graph": {
            "arraye1": {
              "process_id": "array_element",
              "arguments": {
                "data": {
                  "from_parameter": "data"
                },
                "index": 2
              }
            },
            "arraye2": {
              "process_id": "array_element",
              "arguments": {
                "data": {
                  "from_parameter": "data"
                },
                "index": 1
              }
            },
            "normal1": {
              "process_id": "normalized_difference",
              "arguments": {
                "x": {
                  "from_node": "arraye1"
                },
                "y": {
                  "from_node": "arraye2"
                }
              },
              "result": true
            }
          }
        },
        "dimension": "bands"
      }
    },
    "savere1": {
      "process_id": "save_result",
      "arguments": {
        "data": {
          "from_node": "reduce1"
        },
        "format": "GTiff"
      }
    }
  }
}
m-mohr commented 2 years ago

Yes, on the last node you need to set node.result = true. The client does that automatically for the normal use-cases, but JSON export is not meant to be a best-practice so it's not optimized for that.

jonathom commented 2 years ago

Ok as it is @m-mohr?

m-mohr commented 2 years ago

I'll do a review on Monday at the latest, I think some wording should be improved. But don't have the time right now...

jonathom commented 2 years ago

all changes from review have been added.

m-mohr commented 2 years ago

Thank you.