Skip to content

Process Graph Building

Florian Lahn edited this page Apr 4, 2018 · 9 revisions

As with client version 0.2.1 onwards we will introduce a small quality of life hack - the ProcessGraphBuilder. It is designed to make life easier in R when creating the process graph description for a particular back-end.

The old way

In the beginning a user would need to familiarize with a back-end and learn its offered processes and their arguments. It looked similar to this:

library(openeo)
con = connect(host = "http://localhost:8000/api/",user = "test",password = "test",rbackend=TRUE)

con %>% listCollections()
str(con %>% describeCollection("sentinel2_subset"))

con %>% listProcesses()
str(con %>% describeProcess("filter_bbox"))

List of 3
$ process_id : chr "filter_bbox"
$ description: chr "Subsets an imagery by a specific extent"
$ args :List of 5
..$ imagery:List of 1
.. ..$ description: chr "the spatio-temporal dataset/collection"
..$ left :List of 1
.. ..$ description: chr "The left value of a spatial extent"
..$ right :List of 1
.. ..$ description: chr "The right value of a spatial extent"
..$ bottom :List of 1
.. ..$ description: chr "The bottom value of a spatial extent"
..$ top :List of 1
.. ..$ description: chr "The top value of a spatial extent"

For the process graph creation it would look like this.

task = collection("sentinel2_subset", id_name="product_id") %>% 
  process("filter_daterange",prior.name = "imagery", from="2017-04-01", to="2017-05-01") %>% 
  process("calculate_ndvi",prior.name = "imagery", nir=8,red=4) %>% 
  process("find_min",prior.name = "imagery")

taskToJSON(task)
{
  "process_id": "find_min",
  "args": {
    "imagery": {
      "process_id": "calculate_ndvi",
      "args": {
        "imagery": {
          "process_id": "filter_daterange",
          "args": {
            "imagery": {
              "product_id": "sentinel2_subset"
            },
            "from": "2017-04-01",
            "to": "2017-05-01"
          }
        },
        "nir": 8,
        "red": 4
      }
    }
  }
} 

You can still do it this way. But if you use a R development environment that supports autocompletion, then the new way is your way to go.

The new way

In the beginning I said that we have created a ProcessGraphBuilder in order to support the process graph creation. Before the instantiation the ProcessGraphBuilder class will not have any functions assigned except the functions inherited from the base R6 class like instantiate and copy. During the instantiation with a back-end connection, all the offered processes are queried - at first the names and afterwards each process is fetched in detail - and registered as functions of the ProcessGraphBuilder class. The function itself is the wrapped process function provided by this package - but the ... parameter is replaced with the actually used parameter of this process.

The above mentioned task creation would look like the following when using the ProcessGraphBuilder.

pgb = pgb(con)

task.alternative = collection("sentinel2_subset", id_name="product_id") %>% 
  pgb$filter_daterange(from = "2017-04-01",to = "2017-05-01") %>%
  pgb$calculate_ndvi(nir = 8,red = 4) %>%
  pgb$find_min()

taskToJSON(task.alternative)
{
  "process_id": "find_min",
  "args": {
    "imagery": {
      "process_id": "calculate_ndvi",
      "args": {
        "imagery": {
          "process_id": "filter_daterange",
          "args": {
            "imagery": {
              "product_id": "sentinel2_subset"
            },
            "from": "2017-04-01",
            "to": "2017-05-01"
          }
        },
        "nir": 8,
        "red": 4
      }
    }
  }
} 

Clone this wiki locally