View Single Post
  #1  
Old 04-10-2008, 01:02 PM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Flagging the Data

So I'm collecting position data through a flock of birds and writing the data to text files on the computer. I have:

Code:
flock1 = viz.add('flockofbirds.dls')	
flock2 = viz.add('flockofbirds.dls')	
flock3 = viz.add('flockofbirds.dls')	
flock4 = viz.add('flockofbirds.dls')	

flock1.command(6)						
flock2.command(6)						
flock3.command(6)						
flock4.command(6)

tracking_data = open('prism_ve data/headdata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')
tracking_data2 = open('prism_ve data/hipdata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')
tracking_data3 = open('prism_ve data/kneedata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')
tracking_data4 = open('prism_ve data/ankledata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')
#"""

flags = ['A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y']
flagIndex = 0														
def WriteFlag():													
	global flags, flagIndex											
	letter = flags[flagIndex]										
	flagIndex = flagIndex + 1										
	tracking_data.write('*** Reached point ' + letter + 'in', clock(), 'seconds' + '\n')		
	tracking_data2.write('*** Reached point ' + letter + 'in', clock(), 'seconds' + '\n')		
	tracking_data3.write('*** Reached point ' + letter + 'in', clock(), 'seconds' + '\n')	
	tracking_data4.write('*** Reached point ' + letter + 'in', clock(), 'seconds' + '\n')	
vizact.onkeydown('f',WriteFlag)

#('*** Reached point ' + letter + '\n'+ "Elapsed time =", clock(), " seconds")

def WriteFlag2():																				
	tracking_data.write('*** Time of Trial =', clock(), "seconds" + '\n')		
	tracking_data2.write('*** Time of Trial =', clock(), "seconds"+ '\n')		
	tracking_data3.write('*** Time of Trial =', clock(), "seconds"+ '\n')		
	tracking_data4.write('*** Time of Trial =', clock(), "seconds"+ '\n')		
vizact.onkeydown('w',WriteFlag2)
Ok...so the commented out line in between the two different "flags" is really what I want the first flag to say. The second flag is only there because I want to be able to write to the data file how long each trial was. Later on in the script I have:
Code:
def onkeydown(key):	
	if key == 'q':
		viz.quit()
		print "Time of Trial =", clock(), "seconds"
#		WriteFlag2()
		
viz.callback(viz.KEYDOWN_EVENT,onkeydown)
So i can get the time of the trial to print in the input/output screen but I can't get it to write to the data file. If I don't comment out WirteFlag2 in the "onkeydown" then it gives me an error as well but I can't remember what it is (although I think it might be the same as the one I'm asking about now...)

So when I run my script I get this error:
raceback (most recent call last):
File "C:\Program Files\Vizard25\vizact.py", line 1981, in __onkeydown
item.call()
File "C:\Program Files\Vizard25\vizact.py", line 1897, in call
_paramargs_(self.func,0)(*(_paramargs_(self.args,0 )))
File "Prism_VE_Updated_Maze_7_BASELINE.py", line 152, in WriteFlag
tracking_data.write('*** Reached point ' + letter + 'in', clock(), 'seconds' + '\n')
TypeError: function takes exactly 1 argument (3 given)
Traceback (most recent call last):
File "C:\Program Files\Vizard25\vizact.py", line 1981, in __onkeydown
item.call()
File "C:\Program Files\Vizard25\vizact.py", line 1897, in call
_paramargs_(self.func,0)(*(_paramargs_(self.args,0 )))
File "Prism_VE_Updated_Maze_7_BASELINE.py", line 162, in WriteFlag2
tracking_data.write('*** Time of Trial =', clock(), "seconds" + '\n')
TypeError: function takes exactly 1 argument (3 given)

And I have no idea why it thinks I'm trying to give it 3 arguments. If I change the WriteFlag function to:

Code:
flags = ['A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y']
flagIndex = 0														
def WriteFlag():													
	global flags, flagIndex											
	letter = flags[flagIndex]										
	flagIndex = flagIndex + 1										
	tracking_data.write('*** Reached point ' + letter + '\n')
	tracking_data2.write('*** Reached point ' + letter + '\n')		
	tracking_data3.write('*** Reached point ' + letter + '\n')
	tracking_data4.write('*** Reached point ' + letter + '\n')
vizact.onkeydown('f',WriteFlag)
then everything works fine and it write to the data file, but I can't get the time.

I would love to be able to press "f" and get which letter was reached and at what time it was reached and I would like to know how to make it so that when I press "q" to quit the program that the time at that point could be written to the file as well.

Last edited by Elittdogg; 04-10-2008 at 01:04 PM.
Reply With Quote