|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
Re: A simple problem?
Quote:
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! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > A simple problem? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|