I’m trying to read in the Masks present in a subset OLCI reflectance product.
I first load the mask group:
Masks = sub_product.getGroup(‘Masks’)
I then access the mask I am interested in:
glintMask = Masks.get(‘quality_flags_sun_glint_risk’)
However this return an object of type org.esa.snap.core.datamodel.ProductNode. This type does not have the readPixel method as for object types org.esa.snap.core.datamodel.Band. This is an example of what I’d like to do but for the tie points:
lon = rp.getTiePointGrid(‘TP_longitude’).readPixels(0, 0, w, h, np.zeros(w * h, np.float32))
Thus I am struggling to read the data from the [boolean] Masks. Can you help to point to methods to read in the boolean masks?
Instead of getGroup(‘GroupName’) it is besser to use getMaskGroup()
This returns a ProductNodeGroup which will give you the masks you want.
The mask will have integer values, either 0 or 255
I’m still struggling to read in the Mask data to a numpy array.
Masks = sub_product.getMaskGroup(‘Masks’) > org.esa.snap.core.datamodel.ProductNodeGroup
landMask = Masks.get(‘quality_flags_land’) > org.esa.snap.core.datamodel.ProductNode
I don’t see any methods to readPixels for a ProductNode object. Can you help?
I know I can read the masks using flag codings from the Band ‘quality_flags’, but it would be easier I think to read them in directly from the boolean Masks group if possible.
Sorry, but I can’t seem to be able to work out how to create the org.esa.snap.core.datamodel.Mask class to access the mask layer. Please would you be able to provide some more instructions how to turn the org.esa.snap.core.datamodel.ProductNode object into the org.esa.snap.core.datamodel.Mask object?
Hi Marko, again, any advice on which method I can use from org.esa.snap.core.datamodel.Product (or other class object) to access an org.esa.snap.core.datamodel.mask object appreciated, .getband does not work for masks as far as I can tell… Thanks again!
After searching for days, I settled on a work around by reading in the L1 flag band, then accessing the flags using bitget function. However, it may be an issue that the mask layers are not read accessible… since I found no method to do so…
Ah ok. The reason for the error is that Python doesn’t know that mymask is a Mask.
In Java mask_group.get(...) returns a ProductNode<Mask>. This information gets lost in Python.
It should be possible to cast it to a Mask.
from snappy import Mask
my_real_mask = jpy.cast(myMask, Mask)
Afterwards it should be possible to call readPixels on my_real_mask.
The code you mentioned does not work for me now either, I think since the new version of SNAP. We have been discussing that in this thread too, but no solution so far.