Sentinel 2A preprocessing

I have two Sentinel 2 A product:

  • the first is a S2A_MSIL1C on which I applied sen2cor and obtained atmospherically corrected product which now is similar to a S2A_MSIL2A product. Now I would like to further clean up by masking shadows, cloud shadows and water for this purpose I used Optical>Processing>Masking>IdePix>IdePix Sentinel-2 MSI which is supposed to give a number of bands including “radiometric land value”; “radiometric_water_value”, etc as well as Masks like “IDEPIX_Cloud_shadow”, “IDEPIX_Cloud”; “IDEPIX_water” etc, etc… for all categories in the values classified in the table.

However I got a result in which the obtained bands are not visible at all…

  • the second is a S2A_MSIL2A product that already brings with it a band called “quality_scene_classification” that can function as a mask with the following classification values:

  • My question is why in the first case it did not work for me and how can I use the “quality_scene_classification” to get a masked image of the categories of my choice from the table?

Thanks a lot for your help and guidance.

Hi Gabi,
Idepix only works with MSI-L1C data, not L2. The solution would be to use Idepix on L1C and run Sen2Cor on L1C and later merge both using gpt.

1 Like

Dear Ana,

Thanks a lot for the helpful information and guidance, it is very useful for me. I appreciate you help.

Do you know how to solve the second case, that is, the SNAP process to be followed using S2A_MSIL2A data with the “quality_scene_classification” band for masking some of the categories I the table?

Thanks a lot again.
Kind regards,

You can create masks out of the quality_scene_classification. Use the Mask Manager for doing this.
There is a video tutorial showing its usage:

You should also resample the data before. Otherwise the masks you create are only applicable on the 20m resolution.

In this screen shot I created a mask for the water (value=6)

In a next step you can use it in the valid-pixel expression of a band. For example to only show water pixels.

1 Like

Thanks a lot for the helpful and useful guidance and information.
Kind regards,


I have followed the septs you indicated me in your last post and tried in S2A_MSIL2A product to use the “quality_scene_classification” for masking and worked really well for water

However when tried to mask clouds I find the following issue, clouds in the sea are clearly visible and detected

while clouds are in general visible in RGB image in land and sea, although, for clouds on land when I zoom in an extremely large number of pixels (which in the RGB don’t appear to have any visible clouds by eye), show to be with clouds cover all over the image taking a very large number of the total pixels in the whole image. Thus, it captured my attention the very large and important amount of pixels the mask indicates to be with clouds. I used the "cloud (high probability) mask. While it does not look to be any clouds in the RGB image in the the mask such large number of pixels appear in the cloud (high probability) mask… In RGB as you can see besides the could in the sea there does not appear to be major clouds?

Why could this be happening ?

How I can get a reliable and more appropriate mask for clouds and clouds shadows on land from “quality_scene_classification”?

My objective is to make a union mask (which I actually could do) of the water, clouds and clouds shadow aiming at using such mask to set null those pixels in the image.

How can I use the mask to set null pixels in the image?
For instance to set null the mask resulting from the union of water, clouds and shadows?
Is there a setnull() function in SNAP such as in ArcGIS?
If exists how could be the syntax for setting null in the image the mask values?

Then, finally with an appropriate making of all water, cloud and shadow, pixels my preprocessing steps will finish to start using the image for research purposes.

For that I would need to extract as GeoTIFF several bands (not all of them) from the product, this I think can be done by separating the bands from the product using subset function, and only then export as GeoTIFF is this correct?

After that for completing the process I think I have to multiply the GeoTIFF times the scaling factor if is not in reflectance between 0 and 1 as in other post in this forum was discussed.

Looking forward to your response.
Thanks a lot for your help.
Kind regards,

Automatic cloud detection is not a simple task. So most algorithms have issues to detect all clouds and cloud shadows properly.
You can try to improve the cloud mask by combining it with some additional radiometric tests. but this is out of my knowledge.
Other options are to use a different masking tool or a different atmospheric correction.
They might give better results in some cases, in other cases they might be worse.

For masking there are other tools like FMASK or Idepix. You could also try sen2cor itself or Maja.
There are some links in this post, you might find interesting:

I’m not sure what you mean by ‘set to null’.
As said in the previous post you can change the valid-pixel expression then those pixel are not shown in the image and not considered in further processing. Or you can create new bands by Band Maths.
The expression would be like:

cloud_mask ? NaN : B5

When ever the cloud_mask is set the pixel value is set to NaN (maybe the equivalent to null in ArcGIS) otherwise the band value is used.

Regarding the export you are right. It works as you said.
Except if you create new bands with the Band Maths the scaling is already included.


Thank you very much for your help and all the useful information you provided me.
Yes indeed, with “set to null” I meant to put NaN values in the image pixels according to the mask values. My question what math expression should I use to do so, and as I see in your answer I should use the following,

cloud_mask ? NaN : B5,

I understand this expression will turn NaN all values in the image which are covered by the cloud_mask, or water_mask or any other… then I will get an image with NaN for the pixels under the mask, a new band will be automatically created is this correct, right?

Thanks a lot again for your help and guidance.
Kind regards,

Yes, a new band will be created.

Thanks a lot