Cloud mask - SNAP sentinel 2

If both, the cloudy and the clear reference scene, have the same extent and at the same location (same S2 tile) then you can also use Band Maths.

Use as expression the following:

IF (scl_cloud_high_proba  || scl_cloud_medium_proba || scl_thin_cirrus) THEN $2.B01 ELSE B01

If they don’t have the same extent then you would need to collocate them first. and then apply the expression.

But you can also do a mosaic.

1 Like

@marpet, Thank you so much for you help. I have done Mosaicing of cloudy sentinel 2B_L2A image. i have attached the cloud masking image here. please tell me how can i replace the mask areas with reference image. Thank you in advance.

if both the masked and the reference image have the same pixel extent and size, you can replace the masked values in the band maths with an IF statement as demonstrated here: Replacing NaN with 3x3 average

@ABraun, Thank you for your response. My two images are same extent ( same tile number). i have attached the image here.

. In the picture, 2 no. image is cloudy, 3 no. image is clear image and 4 no. image that i have masked the cloud using Moasaicing option in SNAP 6. Now i want to replace the cloud mask areas from 4 no. image by 3 no. clear image. i do not want to replace with average values of around the NaN value areas. I exactly want to replace the cloudy areas by their corresponding clear areas. Otherwise, the my mapping result will not be good. Thank you so much

I understood that - the principle to replace the values is the same. Instead of the average raster you simply use image number 4 (I4). But you have to do this band by band:

IF I2_b1 == 0 THEN I4_b1 ELSE I1_b1
IF I2_b2 == 0 THEN I4_b2 ELSE I1_b2
IF I2_b3 == 0 THEN I4_b3 ELSE I1_b3

You can use the Band Maths as I said before. I attache some screenshots.
Maybe you don’t have enough images to replace all cloud pixels.
image

If you are not bound to the date you currently use. The S2GM service might be useful for you. For your region (53TLN) L2A data is only available from December 2018 onwards.

There is also Theia which is providing mosaics of Sentinel-2 but I think your region is also not available. (@OHagolle)

Thank you @marpet,
Yes, the region (53TLN) is not among the ones processed by Theia, but the softwares are available.

@shamimcaas: You will need to use MAJA to get L2A products, and then WASP to make the monthly syntheses.
To use MAJA : https://github.com/CNES/Start-MAJA
To use WASP: https://github.com/CNES/WASP

Both tools work on linux only. There are executable versions which are easy to install.
Olivier

@ABraun,and @marpet Thank you all for your information.

@marpet, i have created Cloud mask band using band math given in picture(Cloud_mask). Then i have resampled the the S2B_MSIL2A image considering 10 m pixel size, not the reference band.

. After i have mosaiced the image cloud_Mask image (Mosaic) and i have got the cloud mask image given in picture. I have an clear image near date. Now i want replace the Could_mask areas by corresponding parts of clear image. could you tell me the steps, procedures or ways how will i replace the cloud areas. i have uploaded cloudy, cloud_mask image and clear image previous time. Thank you in advance.

What about my suggestion with the band maths above?

@ABraun, sorry, i can not run your Band math expression.

Could you Provide details with picture? Thank you so much.

@ABraun, could you tell me which image i will use? only mosaic? how will i use the clear image?

You use both the maskes image and the mosaic. Open the band maths and go to the advanced expression editor. You find a dropdown menu in the top where you can switch between both products and create the statement by selecting the bands as formulated above.

@ABraun, i am sorry to disturb you again, i can not do it. could you write the band math according to my image. i can not match your band math with my image. could you tell me which will be my target image? During Mosaic as target product there is no product option in Band math Expression Editor page. i am showing some pictures below.

. Thank you in advance.

for band 2:
IF $1.cloud_mask == 0 THEN $2.B2 ELSE $1.B2

(given that the mask is 0 in clouded areas, otherwisee you have to adjust this value)

@ABraun, Thank you so much. I am trying to do so.

Hey, could you please share with us the steps for cloud masks creation?
I have a Sentinel 2A L2A image that has clouds and I want to mask them.

Hey, I tried to do this and this is what I got as a result

@Rim: Your rasters should not be named band_1, band_2 ect. in SNAP. If you import the L2A product they should have correct names and also there should be quality bands in the product.
You can then check “show masks” in the band maths to create your expression, but currently the statement refers to raster names which are not there.

Have you done anything before applying the band maths?

I haven’t done anything so far besides importing my raster image to SNAP