WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 5 votes, 5.00 average. Display Modes
  #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
  #2  
Old 04-10-2008, 01:06 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You are passing the write function 3 arguments and it only accepts 1. Change the code in your WriteFlag2 function to concatenate the flock value to the string:
Code:
tracking_data.write('*** Time of Trial =' + str(clock()) + "seconds" + '\n')
Reply With Quote
  #3  
Old 04-10-2008, 01:17 PM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Is there a way to get it to say what I want (even though it's 3 arguments?) Can I make it so that the write function can handle 3 arguments?

And is there a way to include WriteFlag2 to ONLY write the time of the trial when I quit the program by pressing "q"?
Reply With Quote
  #4  
Old 04-10-2008, 01:26 PM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Or would it be better to write a 3rd flag with the same button press that reports the time. So i'd have one write which letter and another the time both would work while pressing "f"?
Reply With Quote
  #5  
Old 04-11-2008, 09:51 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Here is a function that wraps calls around the write function and allows multiple arguments:
Code:
def writeData(f,*args):
	f.write(''.join([str(v) for v in args]))
Here is some code that will use this function:
Code:
writeData(tracking_data,'*** Reached point ' + letter + 'in', clock(), 'seconds' + '\n')
Reply With Quote
  #6  
Old 04-11-2008, 11:40 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Thank you for the help. I really appreciate it.
Reply With Quote
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flock of Birds recognized, but no data sent sjroorda Vizard 9 03-01-2016 08:48 PM
data glove navigation arielasso Vizard 6 10-24-2007 02:15 PM
Data Files betancourtb82 Vizard 6 05-04-2006 02:43 PM
Get position data in an own little program Researcher Precision Position Tracker (PPT) 2 02-01-2006 02:55 AM
tracking using quaternarion data jfreeman Vizard 2 06-01-2005 08:48 AM


All times are GMT -7. The time now is 05:45 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC