Sentinel 2A Level 2 data masking

I would like, to mask (give NaN value) to water, clouds and clouds shadows, to a single band of a Sentinel 2 A Level 2 data (already atmospherically corrected). I have, on one hand the “quality scene classification” and on the other hand the single “band” to be masked. Is there any way to do such a process within SNAP and get it out of snap as GeoTIFF file to be open in QGIS?
Are values of Sentinel 2 A Level 2 data in Reflectance, because appears dl as units, if are I export it to GeoTIFF will still be in reflectance? since I “resample” then “subset” and then “export” and values once I export to GeoTIFF seams to be in radiance, not between 0 and 1, but from 0 to 1200, how can I pass to surface reflectance?
Thanks a lot.
Regards,
Gabriel

In SNAP you can use band math to set pixels specified by some logical expression to a “no data” value and use a valid data expression. In the GUI, pixels that aren’t valid will be shown as NaN, but in some cases it is important to distinguish between data masked for low quality and NaN’s produced by a calculation (e.g., division by zero). For reflectances, you can assign different negative values for each mask, which then allows you do some analysis of reasons data were masked. To display valid data in the GUI you would use valid pixel expression to mask all negative values.

GeoTIFF files do not provide the level of metadata you can get from NetCDF4-CF files. In particular, NetCDF4-CF has explicit support for missing data values. Note that QGIS uses GDAL routines to import a single band from a NetCDF4-CF file by using GDAL notation “NETCDF:<file_name>:<band_name>”.

As for the range of values in reflectances exported to GeoTiff, the data may have been rescaled to integers (gdalinfo should tell you if the image is stored as integer data). The same can happen when exporting to NetCDF4-CF, but the CF convention ensures that data are properly scaled when they are imported, so you don’t need to manage the scaling yourself.

Thanks a lot maybe could be that the scaling factor from snap format to GeoTIFF is in this information, probably dividing the data output as GeoTIFF apparently in Radiance by the scaling factor in that 1.0E-4 (divided by 10000 or multiplied by 0.0001) is this correct?
Thanks a lot.

The scaling looks normal. We need floating point to compute reflectances, but the scaling and conversion to uint16 makes files smaller. Note that this scaling doesn’t support use of negative values for “no-data” values, but the largest unin16 is 65535. Since reflectances can’t exceed 1.0 (10^4 scaled unit16), you have many values that can be used to represent different reasons the data aren’t valid, but I don’t think GIS software suports the “Valid pixel expression” so there is still some work needed.

Years ago, (before NetCDF4-CF existed) GIS users had to manually rescale most remote sensing images and and set missing data values. GeoTIFF metadata lacks the level of detail and standardization of NetCDF4-CF. Whatever format you use, it is of course, good practice to check a few values in QGIS to make sure they agree with SNAP, and also compare a few image statistics (number of valid pixels, mean of valid pixels).

2 Likes

Thanks a lot is very clear explanation.
Very helpful for me.
Regards,
Gabriel