Strange borders with NaN values, OLCI

Hello,

I am working with Sentinel-3 OLCI products. In my code I made bands subset by creating new .dim file with selected bands. Those bands have geocoded pixels with NaN values on each side of every scene (behind the borders of scene). After opening .dim file with selected bands in SNAP, I can see nice and clear image, without any borders.

However, after computing albedo using

r4 = b4.readPixels(0, y, width, 1, r4)
albedo = r4*ESD/10
albedoBand.writePixels(0, y, width, 1, albedo)

New, albedo bands will be created with borders:

Instead of NaN values, the pixels have certain values with unknown origin. Is it somehow possible not to use NaN values (ignore them) with computing albedo ?

Thank you for your quick response.

On your b4 band you can use
readValidMask(int x, int y, int w, int h, boolean[] validMask)
to get the mask where the data is valid.
The value you get at the borders is probably the no-data value of the band.
image

Thank you Marco,

that solved my problem ! My code:

    albedoBand = albedoProduct.addBand('albedo04', ProductData.TYPE_FLOAT32)
    albedoBand.setNoDataValue(numpy.nan)
    albedoBand.setNoDataValueUsed(True)
    ESD_float = float(ESD)
    writer = ProductIO.getProductWriter('BEAM-DIMAP')

    ProductUtils.copyGeoCoding(product, albedoProduct)

    albedoProduct.setProductWriter(writer)
    albedoProduct.writeHeader('/home/lubomir/Desktop/Sentinel3_OLCI/albedo/albedo_20180729_0835.dim')

    r4 = numpy.zeros(width, dtype=numpy.float32)
    v4 = numpy.zeros(width, dtype=numpy.uint8)
    r6 = numpy.zeros(width, dtype=numpy.float32)
    v6 = numpy.zeros(width, dtype=numpy.uint8)
    r9 = numpy.zeros(width, dtype=numpy.float32)
    v9 = numpy.zeros(width, dtype=numpy.uint8)
    #r6 = numpy.zeros(width, dtype=numpy.float32)
    #r9 = numpy.zeros(width, dtype=numpy.float32)


    print("Creating albedo")
    for y in range(height):
        print("processing line", y, " of ", height)
        b4.readPixels(0, y, width, 1, r4)
        b4.readValidMask(0, y, width, 1, v4)
        invalidMask4 = numpy.where(v4 == 0,1,0)
        ma4 = numpy.ma.array(r4, mask=invalidMask4, fill_value=numpy.nan)
        albedo = (ma4*ESD_float)/10
        albedoBand.writePixels(0, y, width, 1, albedo.filled(numpy.nan))