readPixel Issue on pre-processed S3 L1B OLCI product

Aim: Get Sentinel 3 L1B EFR data, pre-process this with the IdePix Sentinel-3 OLCI to get a cloud mask, use this mask and/or band to create a mask xarray, use this array to mask a band on another dataset of same coordinates. This is due to L1B data not having a cloud pixel flag.

python 3.10.18, esa_snappy, SNAP 11

Current Approach:
from esa_snappy import Band
print(f"\tExtracting IDEPIX_CLOUD mask…")
mask_group = subset_idepix.getMaskGroup()
idepix_cloud_mask = mask_group.get(‘IDEPIX_CLOUD’)

    if idepix_cloud_mask is not None:
        
        mask_image = jpy.cast(idepix_cloud_mask, Band)
        cloud_maskdata = np.zeros((height, width), dtype=np.int16)
        mask_image.readPixels(0, 0, width, height, cloud_mask_data)

  or by just getting the band of the idepix product (geometry subset):

quality_flags = product.getBand(‘pixel_classif_flags’), returns org.esa.snap.core.datamodel.Band[pixel_classif_flags,int16,74,98,-1,-999.0,-1,0.0,0.0,0.0] but any attempt to readPixels gives the error below too.

Tried to get more comprehensive debug logs using the advice on this previous issue:

but nothing stood out in the responses other than ‘annotate_RasterDataNode_methods: Method “readValidMask”: modified parameter 4: mutable = True, return = True’ printing several times

I’ve tried several ways suggested by these similar issues:

such as specifying integers for the readPixels parameters, specifying floats for the cloud_mask_data both as Integer = jpy.get_type(‘java.lang.Integer’) or Float = jpy.get_type(‘java.lang.Float’) or np.int, np.float32 etc. Tried using a progress monitor as the final param but the same issue.

but keep getting the error:
no matching Java method overloads found , presumably because I may have changed int to float or data types mismatching, but even if I specify the types I may get
or ambiguous method calls instead which I think implies that because readPixels methods appear multiple times SNAP Engine API
for Band, Mask etc classes it can’t determine which one (?)

Does anyone know of a solution for this particular method or any different way to approach what I am doing to bypass this entirely (get S3 OLCI cloud mask for the same WKT geometry subset and mask another dataset of s3 processed data) ?

The readPixels method requires double[], float[] or int[] as type for the data. You have int16 which is short int Java. Maybe using int32 for cloud_maskdata will work. Or not using a numpy array but a python array or a list. I haven’t tried but I think this could be the cause.

from esa_snappy import Band
mask_group = product.getMaskGroup()
idepix_cloud_mask = mask_group.get(‘IDEPIX_CLOUD’)
mask_image = jpy.cast(idepix_cloud_mask, Band)
cloud_mask_data = np.zeros(width*height, dtype=np.int32)
mask_image.readPixels(0, 0, width, height, cloud_mask_data)

or,

from esa_snappy import Band
mask_group = product.getMaskGroup()
idepix_cloud_mask = mask_group.get(‘IDEPIX_CLOUD’)
mask_image = jpy.cast(idepix_cloud_mask, Band)
cloud_mask_data = [0] * (width * height)
mask_image.readPixels(0, 0, width, height, cloud_mask_data)

give the error: ambiguous Java method call, too many matching method overloads found

same error from this alternative band method with a list:
quality_flags = product.getBand(‘pixel_classif_flags’)
width = quality_flags.getRasterWidth()
height = quality_flags.getRasterHeight()
# Use Python list instead of numpy array
cloud_mask_data = [0] * (width * height)
quality_flags.readPixels(0, 0, width, height, cloud_mask_data)

That’s strange. But it seems to be an older problem:

Maybe @dolaf can help?