goseph
March 19th, 2010, 05:23 PM
Hi everyone!
I'm attempting to make a program to draw some graphs for me but am having teething troubles.
Here is what happens when I run:
luke@brick:~/Documents/Auto-Grapher$ python graph.py
Traceback (most recent call last):
File "graph.py", line 15, in <module>
g.makegraph()
File "graph.py", line 10, in makegraph
Vg = d.data[1]
IndexError: index out of bounds
So it seems that the interpreter refuses to look at "data" because it was previously declared as being too small, but it is resized at run-time. Any bright ideas? (or simple ones)
here is my sauce:
graph.py:
import read
import plot
class Grapher:
def makegraph(self):
d = read.Datareader()
data = d.readdata("/home/luke/Documents/Auto-Grapher/12 March/Device 1/Channel 1/Vg-Id 60V")
Vg = d.data[1]
Id = d.data[2]
plotdata(Vg, Id)
g = Grapher()
g.makegraph()
import scipy
class Datareader:
# Array containing array of column data read from datafile
data = scipy.zeros((1,1))
def readdata(self,path):
# File containing Vg-Id data and related parameters
datafile = open(path, 'r').readlines()
numberofcolumns = 6
# Row to start reading from
rowstart = 1
numberofrows = len(datafile)-rowstart
data = scipy.zeros((numberofcolumns, numberofrows))
# Read in a line of data at a time
for rowindex in range(rowstart,numberofrows+1):
# dataline is an array of the data on row $rowindex
dataline = datafile[rowindex].split('\t')
# print dataline
# Read each datum into the array of data)
for columnindex in range(0,numberofcolumns):
data[columnindex][rowindex-rowstart] = dataline[columnindex]
I'm attempting to make a program to draw some graphs for me but am having teething troubles.
Here is what happens when I run:
luke@brick:~/Documents/Auto-Grapher$ python graph.py
Traceback (most recent call last):
File "graph.py", line 15, in <module>
g.makegraph()
File "graph.py", line 10, in makegraph
Vg = d.data[1]
IndexError: index out of bounds
So it seems that the interpreter refuses to look at "data" because it was previously declared as being too small, but it is resized at run-time. Any bright ideas? (or simple ones)
here is my sauce:
graph.py:
import read
import plot
class Grapher:
def makegraph(self):
d = read.Datareader()
data = d.readdata("/home/luke/Documents/Auto-Grapher/12 March/Device 1/Channel 1/Vg-Id 60V")
Vg = d.data[1]
Id = d.data[2]
plotdata(Vg, Id)
g = Grapher()
g.makegraph()
import scipy
class Datareader:
# Array containing array of column data read from datafile
data = scipy.zeros((1,1))
def readdata(self,path):
# File containing Vg-Id data and related parameters
datafile = open(path, 'r').readlines()
numberofcolumns = 6
# Row to start reading from
rowstart = 1
numberofrows = len(datafile)-rowstart
data = scipy.zeros((numberofcolumns, numberofrows))
# Read in a line of data at a time
for rowindex in range(rowstart,numberofrows+1):
# dataline is an array of the data on row $rowindex
dataline = datafile[rowindex].split('\t')
# print dataline
# Read each datum into the array of data)
for columnindex in range(0,numberofcolumns):
data[columnindex][rowindex-rowstart] = dataline[columnindex]