Masking and subsetting

Hi I am working with sentinel2 level 1C. I need to mask the clouds out, and make a subset of the scene using only the bands of 10 m resolution:2,3,4,8. I have been trying a lot but I only manage to do single steps , and the masking of the clouds out as been a tragedy even if I have a cloud mask given by the product.
I open the sentinel2 image using the metadata where all tiles are included, then I remove all the bands which are not of my interest, then I try to subset, but its says that it has different resolutions and resample is needed so I resample to 10 m , even if it is supposed to be at 10 already becasuse I ave already deleted the bands with lower resolutions. Then I subset to the area I want and save it as tiff. this works good. But now if I look at the metadata I do not have the mask anymore.

So I tried to mask the clouds before doing the subset using land/Sea Mask, and choosing the option of Use Geometry as mask and te option invert . Then it says successful , but The image when I open is empty or an error appears and is unable to load. I do not save it as dim, because a message tells me that there are memory problems.

I am trying to do the masking now before resmapling, if i do not save into disk it does not work , but if i save into disk it takes ages. I am now waiting for the process to finish and I am not even sure if it will work.
DOes anyone have an idea on how I can process my images, please?

Did you save the product to disk after you deleted the bands?

NO, there was memory problems, but I did save the ladn /sea mask from the 1 m clouds,it took ages but is not working properly

Where do you need the data afterward? Do you want to use them in a GIS?

If so you could just copy the needed tiles and bands from the GRANULE directory (subdirectory IMG_DATA, the *.jp2 files). The masks you can find in the subdirectory QI_DATA, for example S2A_OPER_MSK_CLOUDS_SGS… gml. If you want to use this cloud mask then you can convert it to a geotiff with the following script I made for myself: (3.2 KB)

There are two more advanced Cloud Masks available:


You can export your mask-area as a shapefile and re-load it after sampeling the data. :slight_smile: