#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    12
    Rep Power
    0

    A simple problem?


    Hi Folks -

    First post, and it should be a simple one. I first came across python yesterday, so pls forgive me

    I want to read a 2-byte signed integer satellite image file into an array. I know the number of rows and cols of the image, so I know the total file size.

    However, when I read the file in with this code, I get an error message saying :

    "Traceback (most recent call last):
    File "D:\adavidso\test.py", line 19, in ?
    data.fromfile(file,in_imgsize)
    EOFError: not enough items in file"

    The file size is most definitely correct (I double checked it in case it was corrupt), and the script works no problem when I tested it with 1-byte data. Is there anything obvious that I am doing wrong here? (It thinks that the file is smaller than the specified size? Is there any way I can check to see what size the compiler thinks the file is?)

    Any advice appreciated.

    --------------------------------------------------------------------------------

    srcfile = 'D:\\test16.dat' # Source directory.
    in_rows = 4800 # Number image rows (IN).
    in_cols = 5700 # Number image columns (IN).
    in_bytes = 2 # Number of bytes per cell (IN).
    in_imgsize = in_rows * in_cols * in_bytes # Total image size
    in_imgtype = 'i' # Structure of data.
    in_iswap = 'Y' # In byteswap.

    file = open(srcfile, 'rb')
    data = array.array(in_imgtype)
    data.fromfile(file,in_imgsize)

    if in_iswap == 'Y':
    data.byteswap()
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    12
    Rep Power
    0

    Re: A simple problem?


    Originally posted by adavidso

    srcfile = 'D:\\test16.dat' # Source directory.
    in_rows = 4800 # Number image rows (IN).
    in_cols = 5700 # Number image columns (IN).
    in_bytes = 2 # Number of bytes per cell (IN).
    in_imgsize = in_rows * in_cols * in_bytes # Total image size
    in_imgtype = 'i' # Structure of data.
    in_iswap = 'Y' # In byteswap.

    file = open(srcfile, 'rb')
    data = array.array(in_imgtype)
    data.fromfile(file,in_imgsize)

    if in_iswap == 'Y':
    data.byteswap()
    Inspiration after I posted The problem was in the data.fromfile line. The second argument should have been rows*cols (rather than rows*cols*bytes).

    Love this site, will be a regular from now on!

IMN logo majestic logo threadwatch logo seochat tools logo