Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old February 3rd, 2004, 01:26 PM
adavidso adavidso is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 12 adavidso User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 3 m 2 sec
Reputation 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()

Reply With Quote
  #2  
Old February 3rd, 2004, 01:38 PM
adavidso adavidso is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 12 adavidso User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 3 m 2 sec
Reputation Power: 0
Re: A simple problem?

Quote:
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > A simple problem?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway