Data fusion with python using request builder

Hello,

I have watched the toturial with Monja (this one) it was great but I had little question regard the last part of the datafusion.

In the last part Monja has shown how she changes the ID based on Maxim script:
image
My question is, if I want to bring another script, for example from my configuration utility, which ID should I insert?
I tried to do as she did, and to write there “S1GRD” for sentinel1 and S2L2A for sentinel2, and then I got error, so I tried the ID of my sentinel 2 layes.

My end goal is to be able to get one tiff image that has bands of sentinel1 and sentinel2 together

Dear Reut,

As the configurator works only with OGC requests, it does not support data fusion - data fusion only works via process API. So it won’t be possible for you to grab an evalscript from your configurator and insert it, as no script in the configuration utility can be a datafusion script. The configurator ID’s have no correlation to datafusion IDs as well, due to the same reason.

The datafusion ID’s can be anything you want. The only important thing is, that it should match the ID referenced in the evalscript function setup() and in the function evaluatePixel(). The process API has two parts - the request and the evalscript. In the request part, at least 2 data collections (can be any two of the available ones) and their ID are set up. You can name the ID to be anything you want, in case you would find it easier to work with the evalscript, if the ID was something else (but often we just use the same ID as the data collection name). Then when you reference this ID in the evalscript, the system connects it to the data collection. Process API requests are completely stand-alone, they are not connected to e.g. layers in the configuration utility or anything like that.

To demonstrate this, let me choose an unusual example: lets suppose you select your first data collection to be S1GRD and name the ID to be “banana”. You choose your second data collection to be S2L2A and name it “strawberry”. When you reference “banana” and “strawberry” in your evalscript, the request will know that you are using S1GRD and S2L2A, as they are connected in your request.

If you set the S1GRD to banana and S2L2A to strawberry like this:

You can see in the data part of the request the ID set up for each data collection:

 "data": [
      {
        "type": "S1GRD",
        "id": "banana",
        "dataFilter": {
          "timeRange": {
            "from": "2021-01-17T00:00:00Z",
            "to": "2021-02-17T23:59:59Z"
          }
        }
      },
      {
        "type": "S2L2A",
        "id": "strawberry",
        "dataFilter": {
          "timeRange": {
            "from": "2021-01-17T00:00:00Z",
            "to": "2021-02-17T23:59:59Z"
          }
        }
      }
    ]

And you can set the evalscript to use these IDs to reference S1GRD and S2L2A for example like this:

function setup() {
  return {
    input: [{
        datasource: "banana",
        bands: ["VV"]
      },
      {
        datasource: "strawberry",
        bands: ["B04", "B08"]
      }
    ],
    output: [{
      bands: 3
    }]
  }
}
function evaluatePixel(samples) {
  var s1 = samples.banana[0]
  var s2 = samples.strawberry[0]
  return [s1.VV, s2.B04, s2.B08]
}

In the webinar, I changed the IDs in another direction - I checked which IDs are referenced in Maxim’s evalscript, and inserted those exact ID’s, as in this case I can just check that the ID’s in the request and evalscript setup function match and be sure the request would work. I could also name the ID “banana” and then change each ID reference in the evalscript to be banana as well, and it would work, but that would take more time and the probability for a mistake would be higher, as I could easily miss one mention of the ID.

So you can choose any combination of data collections, even more than 2, name the ID’s anything you want, and then it’s all about how you set up your datafusion evalscript. In the evalscript above, I just used some of S1 bands and some of S2 bands to make a (not particullarly) useful RGB composite. But you could combine the bands of different datasets in so many ways - check out the repository and our data fusion documentation for some examples.

Also, next week on Thursday, we have a webinar on data fusion! You can join and even ask questions at the end. :slight_smile:

I hope this helps.

Best,
Monja

1 Like