Use of multitemporal data inside evalscript


I have shape and I want to get the two last available NDVI images for them and run calculation on these two images, to get in the end 1 image.
For that I have used the “orbit” mosaic,
as following:

function setup() {
  return {
    input: ["B04", "B08", "CLM"],
    output: {
      bands: 1, 
      mosaicking: "ORBIT"
      sampleType: "FLOAT32"

function evaluatePixel(sample) {
    if (sample.CLM == 1) {
        return [null]
    let date1=index(sample[0].B08, sample[0].B04);
    let date2=index(sample[1].B08, sample[1].B04);
    let difference=index(date1,date2)
    return [difference];

My questions are:

  1. I use date range (‘2022-05-31’,‘2022-06-16’). How do I know which dates are taken? I know that there are three images between these two dates.
  2. which date is earlier? the samples[0] or samples[1]?

thanks :slight_smile:

The order of samples depends on the mosaickingOrder parameter in your request. If you use mostRecent, samples[0] will represent latest observation, samples[1] the before-latest, and so on.

To get the actual date, you can make use of the scenes meta-data parameters. Note, however, that this functionality is somehow experimental.

1 Like