Cloud masking using band math in graph builder for L2A

I converted sentinel 2 images from L1C to L2A using SNAP and now would like to remove the cloud from the image using band math expression in graph builder. Can anyone tell me the expression that I can use to get an image without the clouds?? I am mainly confused with the mathematical expression to be used in band math.
Thank you.

the only thing that you can do is to remove all pixels which were identified as clouds in the automated scene classification done by snap. You can do that in the band properties by creating a valid pixel expression. sen2cor already produced cloud masks which you can use for this, just make sure to display the maks in the band maths as well. Similar as here: Export for unwrapping
I tried to give an example here in another context: Cloud related problem

Some more topics on cloud masking can be found via the search function: https://forum.step.esa.int/search?q=“Cloud masking”

Thanks a lot but again the expression is said to be invalid. Can I apply the same mask to all the bands available in the image?

1 Like

Maybe you haven’t selected an L2A product as source in the read operator? This would explain why it says invalid.
Or you haven’t selected it as the first step. It seems that the BandMath dialog does not detect the changes in the read operation properly.
And I think that you actually want to use || and not &. You want to set 1 if the value is either 4 or 5, right?

Thank you. But can we use or instead for this operation?

Yes, or should work too, instead of ||

1 Like

Thanks a lot …

Professor @marpet I tried to use band maths from graph for a Sentinel-2 image and I am getting every time the error which shown below in the image. If I calculate this equation outside from the graph its working but I want to make an xml with this equation for batch processing.

I tried also to add brackets or " " but I am getting the same error. Is there a bug or something else?
Thanks in advance and for your patience.

can you please express in words what you want to calculate with this expression?
The variables you use are binary masks, not raster bands, so if you want to combine them you should use the Mask Manager, select all and then use the Intersect button:

As ABraun already said. You are using binary masks, with values either true or false. They cannot be simply summed up. You need to use the logical operators like ‘||’ or ‘or’ and ‘&&’ or ‘and’.
Your expression should look like:
scl_cloud_high_proba or scl_cloud_medium_proba or scl_cloud_shadow

For more help on how to write expression see also the help page:

I will try both of your advices. Thank you very much and I appreciate your quick response. :slight_smile: