Masks are removed from S2 products when saved as dimap format

Hi,

Original S2 products contain lots of useful built-in masks like information about clouds. However, when I save the original product in *.dim format none of the masks are saved. It is not related with version of SNAP. I tried it in 6.0 and versions before it, same results. I guess it is a bug but could you please check this behaviour?

Thanks in advance

This is a known limitation. The masks are of a special type and are not yet handled correctly by the generic SNAP framework. If you need one of them you can turn it into a raster by Band Maths. Simply use the name of the mask as expression and uncheck the checkbox for creating a virtual band.

I tried it in SNAP UI and it works. Do you have any suggestion about how to do that in an operator? (within the code). I want to create a target product that will contain specific mask from sourceProduct.

Here is how I succeeded,

Firsty, I create new band and setSourceImage as following

String = “cirrus_clouds_10m” //maskNameAsExpression
newBand.setSourceImage(VirtualBand.createSourceImage(newBand, expression));

Then I copied newBand from source to target using

ProductUtils.copyBand(newBand.getName(), sourceProduct, targetProduct, true);

Thanks.

1 Like