Overwrite band with setPixels

Hello,

I am trying to read data from a specific band and then to overwrite some values. My code works as follow:

1- Read the data into a numpy array
2- Perform some operations on the numpy array
3- Update the pixels from the numpy array

    band = product.getBand(name)
    width = band.getRasterWidth()
    height = band.getRasterHeight()
    band_numpy = np.zeros((height, width), dtype=np.float32)
    band.readPixels(0, 0, width, height, band_numpy)
    # Do something
    band.setPixels(0, 0, width, height, band_numpy)

I can read the data into a numpy array without any issue but as soon as I try to use the function setPixels(), I get the following error:

RuntimeError: java.lang.NullPointerException

Did I miss something? Or is there an alternative to way to update the pixel values (without writing to disk)?

Thanks in advance for your help!

SNAP version 8.0 Unix

This is due to the bit confusing API. It has growen over time…

You read the pixel values directly by the readPixels(). This does not create the internal data holder of the band which is necessary when using setPixels().

You can now use instead of setPixels() the writePixels() method or you replace readPixels() by getPixels(). Before the first call to getPixels() you need to call loadRasterData().

There are two pairs of methods, get and set and write and read.