Get numpy array using readPixels

Hi there,

(I’m a snappy newbie. ;-))
I am trying to get a numpy array from a S3A_SY_2_VGP product.
It works for one line, or a rectangle starting in the top left corner, but it won’t work for a rectangle somewhere in the middle.
This is (part of) my code:

import numpy as np
from snappy import ProductIO



line=b0.readPixels(0,0,width,1,dataline) #this seems to works fine

box=b0.readPixels(0,0,100,100,databox) #this works too

box2=b0.readPixels(100,100,200,200,databox2) #this won’t work!

I get an error message:

RuntimeError: java.lang.IllegalArgumentException: The length of the given array is less than 40000

What are the correct arguments for readPixels() ? I interpreted it as (startcolumn, startrow, endcolumn, endrow, outputarray), but this seems incorrect.

Thanks in advance for your help.

Hi cartot,
I’ve started to use snappy some months ago and this is a problem I also got stuck into at the beginning.
I solved this and many other issues by looking at the snappy API reference page --> (

By the way, the arguments of readPixels are not as you interpreted but are readPixels(x,y,w,h,Array) with:

  • x: x offset of upper left corner
  • y: y offset of upper left corner
  • w: width of the desired data array
  • h: height of the desired data array
  • Array: the Output Array to be filled with data

So in your case, if you want to get pixels data inside a m x n rectangle, you have to set w = m and h = n inside readPixels (no matter which offset you select), thus:


will do the job!

Hope this helps :wink:


Hi Davide,
It works! :clap:
Thanks a lot. This snappy API reference page will be very helpful…

Hi, for further examples and applications of snappy you can refer to this exteranl resource in the STEP website :

The repository is not rich at the moment, but it is still active and more elements will be added in the next months
Hope it can be useful!

1 Like