How to export the cloud mask of sentinel2?

I need to export the cloudmask of sentinel to a format that can be read in QGIS orARCGIS or envi. I have tried to export it, but the option it appears is .xml and I cannot open the file on the programs just mentioned. Does anybody can tell me how to use the mask outside snap, please?

Thank you very much,

Alejandra

The (original) cloud mask can be converted with GDAL/Python. Attached a small script which should do it.

You can run the script in the command window with:

[Windows]
python pathToScript/gml_transform.py -i gmlInputPathFile -o shpOutputPath

Cheers,
Andreas

gml_transform.py (3.2 KB)

1 Like

what’s the difference of the .gml mask when compared to the sen2cor mask or fmask?

Hello unnic,

I did not have a detailed look on it, but what I can show you is the following result.

  1. This first picture is the result of the “original” cloud mask. It clearly underestimates the number and extension of the clouds.

  2. This second image is the result of the FMASK. It classifies the cloud (purple), cloud shadow (yellow), water (blue) and snow (not on the printscreen). In this case the clouds are detected almost perfectly. But I recoginized that FMASK has a tendency to overestimate the number of clouds. Sometimes it classifies Buildings and Lake/River coast as clouds.

  3. Regarding sen2cor I have no example for it because I did not process anything in the past months. :slight_smile:

1 Like

I experienced quite the underestimation with sen2cor. thanks for the hint with FMASK, I didn’t know it was available for S2 already, I’ll give it a try.

1 Like

Is the FMASK algorithm implemented in SNAP?

no
A python version is accessbile here

2 Likes

Concerning Sen2Cor, a binary cloud mask is not directly available but a Scene Classification Map with 12 classes is available at 20 m and 60 m resolution. It is possible to construct a simple binary cloud mask by aggregating the three following classes of the Scene Classification Map: (Cloud Medium Probability (8) + Cloud High Probability (9) + Cirrus (10)).

Some examples are given hereafter showing first a L1C TOA colour composition and after the Sen2Cor cloud mask coloured in blue over the L1C TOA image:

  1. Agricultural landscape
    L1C TOA:

Sen2Cor Cloud Mask + L1C TOA:

  1. Sea ice
    L1C TOA SWIR-NIR (ice appears in green):

Sen2Cor Cloud Mask + L1C TOA:

Please keep in mind that Sen2Cor cloud mask can be considered as a "raw"pixel-based cloud mask that can be further processed by users depending on their particular application. Users who privilege very clean pixels would need a more conservative cloud mask and can dilate Sen2Cor cloud mask. One reason why Sen2Cor cloud mask is not provided already dilated is because the dilatation process of the cloud mask is not reversible and in some cases, users may be interested in getting as much information as possible from their data. They can then use the original Sen2Cor cloud mask for their processing.

Sen2Cor Scene Classification Map provides information on Cloud shadow, Water and Snow, like FMASK.

Please note that an improved version of the cloud screening algorithm of Sen2Cor is expected for Spring 2017.

Kind regards,
JĂ©rĂ´me

4 Likes

Bonjour JĂ©rĂ´me,

I am facing a task to generate binary cloud mask from sen2Cor cloud classification map to feed as input to IOTA2 using Python.

You have mentioned that by aggregating the three following classes of the Scene Classification Map: (Cloud Medium Probability (8) + Cloud High Probability (9) + Cirrus (10)), it is possible to construct a simple binary cloud mask.

Could you please offer some detailed information for this aggregation, ie packages, tools or even Github repos can be used in this task? I have searched for a long time. It seems that your answer is the best what I am looking for.

Thank you.
Steve

SNAP with snappy is well suited for your use case. You can create a new band (BandMath) which combines the three cloud values and write this as a new file.

Hi marpet,

Thank you for your reply.

I’m working on a processing chain to process data from Sentinel2. I’m not familiar with SNAP. The only thing I know for SNAP is that it is GUI platform for satellite data processing . Is it possible to embed snappy in Python code or shell code?

Cheers,
Steve

Yes, you can run nearly all processing steps you can do in the GUI also from the command line or invoke it from Python.

If you like to have some starter?
https://senbox.atlassian.net/wiki/spaces/SNAP/pages/19300362/How+to+use+the+SNAP+API+from+Python
https://senbox.atlassian.net/wiki/spaces/SNAP/pages/70503053/Processing

Also via this search, you can find some Python examples in the forum:
https://forum.step.esa.int/search?q=GPF.createProduct(%20%23development%3Apython

However, if you are not yet familiar with processing with SNAP/snappy the overhead might to much for you and some simple python package is better suited for you. But for this I donÄt have a suggestion.

1 Like

Hi marpet,

Thank you for the detail information you provide. They are awesome. I will talk with my supervisor to see if we should get SNAP involved in this processing chain.

You are really helpful! Thank you again.

Best regards,
Steve