Snappy: Mask (Clouds and others)

When you call getValidMaskImage() on the result of product.getMaskGroup().get('opaque_clouds_10m') then you retrieve the valid mask for the cirrus mask. It is possible that masks of valid and invalid areas. That’s what the valid mask will provide.

If you already have a mask you can use getSampleInt(x, y) to retrieve the value of the mask at xy-position. The value will be 0 or 255.
You can also get the image of the mask. For this use mask.getSourceImage(). From this image you can get the data by sourceImage.getData().getSample(x, y, 0).

You can also change the valid mask of band by the the valid pixel expression and the no-data value.
For example
b4.setValidPixelExpression(‘opaque_clouds_10m == 0’)
b4.setNoDataValue(-1)
b4.setNoDataValueUsed(True)
If you now do b4.getValidMaskImage() this image should reflect the settings.
Should also work with b4.readValidMask(0, y, width, 1, v4).

I hope this makes it clearer and answers at least some of your questions.