Image returned with no data for one day using TILE mosiacking

I am trying to obtain one cloud free image from an FOI for every last week in a month. But I am doing this manually at the moment using the following request in request builder. I am getting images with no data almost all the time. Until I use a simple mosaic for every 1-2 months.

//VERSION=3
    function setup() {
        return {
            input: [{
                bands: ["B01", "B02", "B03", "B04", "B08", "B05", "B06", "B07", "B8A", "B11", "B12"],
                units: "DN"
            }],
            output: {
                bands: 12,
                sampleType: "INT16"
            },
            mosaicking: "ORBIT"
        };
    }
    function evaluatePixel(sample) {
        return [sample.B01,
                sample.B02,
                sample.B03,
                sample.B04,
                sample.B05,
                sample.B06,
                sample.B07,
                sample.B08,
                sample.B8A,
                sample.B11,
                sample.B12];
    }

I need help to troubleshoot what is the actual problem. Thanks

Hi @aswinbio!

When you use mosaicking: "SIMPLE", the object which gets passed to the evaluatePixel function is a single sample, however, when you use mosaicking: "ORBIT" or "TILE", then the passed object is samples. Please find more info on this here.

To quote the docs:

When mosaicking is TILE or ORBIT samples is an array of samples as defined in the SIMPLE case.

Meaning that you have to parse through them and select the appropriate return values.

If you want to get the exact timestamp of the scene in question, you also have to make use of the scenes object (info here).

Try again with rewriting the evalscript like in the third example here, where we loop through the samples, calculate the average for all valid samples, and return the mean.

function evaluatePixel(samples) {
  var sum = 0;
  var nonZeroSamples = 0;
  for (var i = 0; i < samples.length; i++) {
    var value = samples[i].B04;
    if (value != 0) {
      sum += value;
      nonZeroSamples++;
    }
  }
  return [sum / nonZeroSamples];
}

Let me know how it goes!

Cheers,
Matic

Thanks for the quick response @matic.lubej . To clarify further, is “SIMPLE” a better option for time series analysis? since it returns only one sample per month? but however, I am still confused if it is a mosaick or just one sample obtained in one of the orbit passage?

I will try this, however, I am looking for for least cloud cover image per month without mosaicking for time series analysis. is there a way to achieve this?

At the moment, I download simple mosaicks for every two months and I am not sure how to account for the of pixel brightness due to orbit angle and other artifacts.

Hi @aswinbio,

To clarify further, is “SIMPLE” a better option for time series analysis?

It depends. The “SIMPLE” mosaicking offers one of 3 methods of temporal aggregation:

  • mostRecent
  • leastRecent
  • leastCC

This means that the images are ordered by the above and the image is equal to the “top” of the image stack.

If you want to do filtering based on some custom code (using s2cloudless, filtering to max NDVI, …), then you need to switch to “TILE”/“ORBIT” and filter and define the image on your own.

but however, I am still confused if it is a mosaick or just one sample obtained in one of the orbit passage?

The “SIMPLE” will return mosaic in the form of a single image for the time_interval that you are requesting (in your case 1 month).

I will try this, however, I am looking for for least cloud cover image per month without mosaicking for time series analysis. is there a way to achieve this?

Are you interested in the tile-level cloud cover filtering, or on the selected geometry/bbox ?

Thanks for the response @matic.lubej . To reiterate your explanation - ‘SIMPLE’ will return a mosaic of all least cloud cover acquisitions in the months I specified. Alright, understood. However, the ORBIT and TILE will do that same, but based on number of TILES/ORBITS available per month, whereas, “SIMPLE” will only care about the order and not if it is TILE/ORBIT?.

I am interested in cloud filtering for the selected geometry, it is only few hundred km2.

Well, can you explain what is the process behind this approach. It returns a mosaic of all least cloud cover acquisition that fall within 17 percent or below (The CC percentage in question)?

Hi,

To reiterate your explanation - ‘SIMPLE’ will return a mosaic of all least cloud cover acquisitions in the months I specified

Yes, but depends if you specify the leasCC mosaicking order option in the request, by default this is mostRecent.

However, the ORBIT and TILE will do that same, but based on number of TILES/ORBITS available per month, whereas, “SIMPLE” will only care about the order and not if it is TILE/ORBIT?.

Perhaps I wasn’t so clear, so let me try again. Let’s say you make a request for a time interval 2022-02-05 to 2022-06-20. In this time interval there is a number of observations for the specific area you’re making the request.

  1. If mosaicking is TILE, then your samples object will loop through all of these available observations for the requested time interval. The order of these observations is defined by the parameter mosaickingOrder, meaning it can be mostRecent/leastRecent/leastCC (check docs for more info). If you want to obtain an image with such a request, you have to specify which sample you want to return (e.g. the first, the middle, the last, the one with max NDVI, the one with lowest B03, etc. - usually done with a for-loop returning the specific value (see evalscript example above for this)

  2. If mosaicking is ORBIT, it’s very similar as with TILE, but in principle there will be fewer samples in the samples array, because the observations from the same orbit are already merged together.

  3. If mosaicking is SIMPLE, then the mosaicking is already done for you, but in a simplistic way, you will already get a single sample/image, which is stacked accordingly to the mosaicking order you provide

Well, can you explain what is the process behind this approach. It returns a mosaic of all least cloud cover acquisition that fall within 17 percent or below (The CC percentage in question)?

So, if you say leastCC, the image will show the observation coming from the tile with the least cloud coverage (on the S2 tile level). If this tile has a part which was not covered by the satellite, the next least cloudy observation will fill those gaps, and so on. There are no thresholds here, just the order. If you want to limit observations from S2 tiles to a certain cloud coverage value, then I suggest you use the maxcc parameter in the request, which will just ignore all observations coming from such tiles and ignore them also in the mosaicking more info here.

But let’s take a step back. You say the following:

I am trying to obtain one cloud free image from an FOI for every last week in a month.

I suggest you create a separate request for each of the time intervals (one week time interval before end of month) using the SIMPLE mosaicking and the leastCC mosaicking order. Provided there are any cloud-free observations, this will return that observation.

However, a warning - one week long time interval is relatively short, it’s possible that you won’t get any observations this way if you’re unlucky.

2 Likes

It is perfectly clear! Thanks for the elaborate answer.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.