Time-series from single Sentinel-2 band (cloud filter)

Hi,

I’m looking around in EOBrowser and i am looking for an answer to the question of how to include% cloudiness in the created time series from one spectral channel. This function is available when selecting a predefined layer, eg NDVI, then in the graph window we have a slider that allows filtering the cloud cover. I would like to achieve a similar effect by analyzing a single channel, eg B04. I return such a layer with a short script return [B04], but in the window when generating the time series, there is no slider with% cloudiness. Is there any way to be able to manipulate the cloud cover in this case? I also wonder what the y axis represents when analyzing a single channel. I conclude that this is the rebound value (just why do values ​​higher than 1 appear - how to explain this). Is there any way to get to the raw data, which stores a DN (Digital Number) in a pixel unprocessed into a reflection value? I have attached two screenshots below to illustrate the situation: NDVI analysis and B04 analysis.

Anyone know the answers to these questions?

Hi @AGat,

The reason the slider isn’t available for your custom script whereas it is for a defautl layer (e.g. NDVI) is because the system is configured slightly differently in the background. However, you can change your Evalscript to mimic the behaviour of the default service.

The last layer returned in the Evalscript is considered to be the cloud mask by the statistical tool. The tool will count the pixels that are cloudy (1) or not (0) in the last band to offer the functionality of having a slider that allows filtering the cloud cover. In your case, you could do the following:

//VERSION=3
function setup() {
  return {
    input: ["B04", "SCL"], // Band 4 and the Scene classification data, based on Sen2Cor processor, codelist
    output: { bands: 2 }
  };
}


function isCloud (scl) {
  // Compute clouds based on SCL layer
  if (scl == 3) { // SC_CLOUD_SHADOW
    return false;
  } else if (scl == 9) { // SC_CLOUD_HIGH_PROBA
    return true; 
  } else if (scl == 8) { // SC_CLOUD_MEDIUM_PROBA
    return true;
  } else if (scl == 7) { // SC_CLOUD_LOW_PROBA
    return false;
  } else if (scl == 10) { // SC_THIN_CIRRUS
    return true;
  } else if (scl == 11) { // SC_SNOW_ICE
    return false;
  } else if (scl == 1) { // SC_SATURATED_DEFECTIVE
    return false;
  } else if (scl == 2) { // SC_DARK_FEATURE_SHADOW
     return false;
  }
  return false;
}



function evaluatePixel(sample) {
 var cloud = isCloud(sample.SCL);
 return [sample.B04, cloud];
}

With the Evalscript above, you will then have the statistical tool with the the cloud cover slider.

However, you will quickly notice that the display service will also interpret the last band as a transparency layer and will only display cloudy pixels :frowning: . If you can live with that and just need access to the stats, I would stop here. If you need a visualisation and the statistics, keep reading… :slight_smile:

To have a nice visualisation and at the same time have the statistical features with your layer in EO Browser, I would recommend you create your own layers in a custom configuration. You can find how to do this in our FAQ. Once you have your layers set (they can be as simple as returning B04), you can then set up the system to compute statistics whilst taking in account cloud cover. There is a whole section on this in the FAQ also.

If you try this approach and get stuck don’t hesitate to post here!

1 Like

Hi maxim.lamare,

your answer is really very helpful and on point, thank you very much.
Having statistics, no visualization - that’s enough for me at the moment. Now statistics are crucial for me.
Do you know what it is like with the values displayed on the y axis? I was working locally on Sentinel-2 data and the pixel values for each channel were in the order of 1000. I understand that the data shared on the portal is already converted to the reflection value, which should be 0-1, and the peaks visible in the graph up to 1.2 and more are caused by clouds? Is that where these values over 1 come from?

Indeed, the values returned are in reflectance (DN/10000). Values above 1 are physically possible, sometimes related to clouds but not only. I wrote a brief note about this a while back: L2A images to range 0 to 1 - #4 by maxim.lamare

1 Like