Band data types -

I’m reading OLCI L3 water products (S3A_OL_2_WRR* and S3A_OL_2_WFR*) with snappy.

All the bands’ data are stored as integers with a scaling factor and an offset.
The call
reads the data as floats, thus applying the scaling factor and offset (as shown by readvar.getScalingFactor() and readvar.getScalingOffset() )

Is there a way to access the raw integers, instead of the floats?
I’m trying to do something like this:
band_nptype=np.dtype(band_type) # band_ntype is e. g. dtype(‘uint16’)
# for band_name ‘Oa01_reflectance’
band=np.zeros(w*h, band_nptype)
but it fails with a
RuntimeError: no matching Java method overloads found

readPixels returns ScalingFactor*value + ScalingOffset
Is there an alternative to readPixels to access the raw data?


The reason why you get the RuntimeError is that you call the readPixels method with an array which has an unsupported data type.
There are only three readPixels methods.

readPixels(int x, int y, int w, int h, int[] pixels)
readPixels(int x, int y, int w, int h, float[] pixels)
readPixels(int x, int y, int w, int h, double[] pixels)

So you need to init you band array differently.
Just distinguish between floating point and integer

if read_band.isFloatingPointType():
    band=np.zeros(w*h, np.dtype('int32'))
    band=np.zeros(w*h, np.dtype('float32'))

I don’t know why you want to access the raw data but there is a way.
For example you can set scaling factor and offset of the band.


This is kind of hackish, but should work.

Another way is to get the source image and read the data directly from this image and not from the band. This will return the unscaled values.

rawImage = read_band.getSourceImage()
rawImage.getData(Rectangle(0, 0, w, h).getPixels(0, 0, w, h, band)

The same as for the readPixels method applies for the getPixels method. There are only three different versions.

Thanks Marco
I just want to re-project and cut the product on a predefined grid, using pyresample package.
As I’m using the nearest neighbor method, I’m considering, in order to save computation time and disk space, to work with the integers and copy the scaling factor and offset in the destination netcdf file.
The hack works ok!
I had no success with the second way you suggest, but I’m trying.

Thanks a lot!