Unable to get Mask from Sentinel-2 Image

Hello everyone:

I am trying to get the ‘scl_water’ mask for every image I process. First I resample and reproject the image and then I run the following code:

mask_group = product.getMaskGroup()
mymask = mask_group.get('scl_water')
my_real_mask = jpy.cast(mymask, Mask)
h = product.getSceneRasterHeight()
w = product.getSceneRasterWidth()
data = np.zeros(w * h, np.int32)
data.shape = h,w
my_real_mask.readPixels(0,0,w,h, data)

However, every element in data remains 0. I made the same operations with SNAP Desktop and there wasn’t any problem.

Does anyone know what is the problem?

Thanks

The code looks good. Can you read from a band? Are only the masks not working?
Why do you reproject the data? To which CRS?

Yes, I can read every band, and the reprojection (to EPSG:4326) is not the problem because i tried to remove every operation, and the problem was the same.

I finally got the mask by the function getSample(x,y), after the function getSourceProduct(), but it is a solution quite “dirty”, because it makes me “map” every pixel to every data position .

Yes, I can read every band, and the reprojection (to EPSG:4326) is not the problem because i tried to remove every operation (i.e. I tried to get the mask before the reprojection and even before the resampling), and the problem was the same.

I finally got the mask by the function getSample(x,y), after the function getSourceProduct(), but it is a solution quite “dirty”, because it makes me “map” every pixel to every data position, so it takes more time that it should.