PDA

View Full Version : Flagging the Data


Elittdogg
04-10-2008, 01:02 PM
So I'm collecting position data through a flock of birds and writing the data to text files on the computer. I have:


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:

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:


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.

farshizzo
04-10-2008, 01:06 PM
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:tracking_data.write('*** Time of Trial =' + str(clock()) + "seconds" + '\n')

Elittdogg
04-10-2008, 01:17 PM
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"?

Elittdogg
04-10-2008, 01:26 PM
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"?

farshizzo
04-11-2008, 09:51 AM
Here is a function that wraps calls around the write function and allows multiple arguments:def writeData(f,*args):
f.write(''.join([str(v) for v in args]))Here is some code that will use this function:writeData(tracking_data,'*** Reached point ' + letter + 'in', clock(), 'seconds' + '\n')

Elittdogg
04-11-2008, 11:40 AM
Thank you for the help. I really appreciate it.