I have been working on creating an experiment in the builder. When I go to the data folder there is no longer an excel/csv sheet with the trial-by-trial data and I am not sure why. I did not change any settings in the Setting → Data menu. I have the CSV file (trial-by-trial) box checked. I am trying to work out the issues in my experiment by creating columns in the data file to track what is going on, but there’s just not a data file. Any advice is very appreciated!
Is your experiment running well? Did you upload the correct conditions file? There can be some issue with the variable names in the condition file or builder. Sometimes, reuploading conditions file and restarting the PsychoPy helps.
Sometimes it runs fine, other times it will close out mid trial. I have been trying to figure out what is causing it to close out midtrial by adding my variables into columns in the data file, but since I have no data file I can’t figure it out. I am still getting a .psydat file.
There is no conditions file for this experiment.
I have restarted psychopy several times and am still having the same issue.
There is no conditions file for this experiment.
If you don’t have a condition file then do you define a condition using a code component? Perhaps, it would be easier to understand if you can explain your design, type of stimuli and share some code or screenshot.
I removed the last bit of code and started over and I am getting data files now. Thanks!
I think there may be some versions of PsychoPy that don’t cope well with experiments that have no loops.
The experiment has loops, just no excel condition files. My experiment file is below if that helps at all. I just have all of the variables and stimuli created in custom code. Luckily I am getting data files now. I do however run into a problem where the program freezes up and closes out. It doesn’t happen very often, and when it happens there is no data file created. This is a concern because the program will be left up for our nonhuman animals to work on 24/7 and I am not there overnight to ensure that it’s not freezing and not saving their data.
Declare.zip (102.2 KB)
Personally I think that the most likely issue is going to be with the file access.
You are writing to a file whenever the following is true.
if(Match_avg_acc >=0.80 and Symbol_avg_acc >=.80 and total_trials >= 16):
Why aren’t you using a variable to remember the current task? I’m guessing it’s so you can restart from where you left off, but it might be better for the operator to scroll to the bottom of the most recent data file rather than having these frequent accesses.
You could do away with file access altogether by adding Task as an expInfo parameter.
I work with non human animals and they have access to their tasks 24/7. So it’s important that the program starts at the task they left off at the previous session, and that the program is checking at the beginning of the first routine to see if criterion was met and the task number has changed.
I had posted a few times on the best way to go about this but never received on a response so using the .txt file with the number was what I came up with. I’ve used it for other experiments and I do notice that they take longer to startup, but this is the first time a program with this code has just stopped working mid task and not created a data file.
I’m not entirely sure what an expinfo parameter is? Is this the same as the participant ID box at the beginning of the experiment? Would using that allow me to update the number mid task and also change task mid run? Or would the task only change when the program is reopened?
A human starts the experiment by selecting Run from PsychoPy. The expInfo dialogue box is indeed the one with participant and session by default.
My assumption is that your non-human participants start the task while it is technically already running, and cannot start it from the PsychoPy interface. Therefore the current value for task can be held in a variable.
At the moment does a human operator sometimes edit parameters.txt without stopping the experiment?
The expInfo dialogue box is only available at the start. You could copy this to a Task variable using
Task = expInfo['Task']
In your reward code you could use
if Task < 7:
Task += 1
It looks like Task 7 just keeps repeating
You could have a keyboard override in one of the routines where the researcher can select 1-7 on a keyboard and the value for Task is updated correspondingly. However, the only way to know the current value would be to have, for example, a small text component displaying $str(Task) in a corner of the screen.
If researchers do ever open parameters.txt to check or update the current value for task and then forget to close it, a crash is likely to happen when PsychoPy next tries to update the value.
A researcher is never opening or changing the parameters.txt file manually. The code is set up so no one has to change the task number. I am not there 7 days a week, and the researchers in charge days I’m not there are not in my lab, so I can’t really ask them to change anything for me, I must rely on the program making changes for me when I am not there. So, it is only the code in my End Routine tab that is changing the parameters.txt.
Typically, someone comes in once a day and closes out of the program, checks a few things on the system to verify it is running properly, and then open the program via the .py shortcut, the participant ID window pops up and is already filled out with the animal name and they just hit OK.
I am not sure what you mean that they start the task while it is technically already running? My apologies.
Yes, Task 7 is the last task so it just runs forever that way even if the animal meets criterion they are not left without some form of enrichment.
From what I understand, you are suggesting that I save the Task # in the expInfo box, then when the program is re-opened the Task variable is read from there. Would I be able to rewrite the Task variable when criterion met if it is stored in the expInfo parameter? Or would someone still need to manually update this?
I added the Task parameter, and added the code you suggested in the Begin Experiment tab and in the End Routine tab.
Begin Experiment tab:
import random
import os
Task = expInfo['Task']
Triangle = 'images/Triangle.png'
Circle = 'images/Circle.png'
Star = 'images/Star.png'
Moon = 'images/Moon.png'
Ellipse = 'images/Ellipse.png'
Plus = 'images/Plus.png'
Diamond = 'images/Diamond.png'
Bell = 'images/Bell.png'
color_list = ['red','green','darkcyan','saddlebrown','magenta','cornflowerblue']
shape_list = [Triangle, Circle, Star, Moon, Ellipse, Plus]
LeftShape = ''
LeftColor = ''
RightShape = ''
RightColor = ''
NoVar = 'None'
CorrectDim = ''
DimTrial = ['Color','Shape']
SidethisTrial = ['Left','Right']
Task6DiceRoll = ['OneMatch','OneMatch','OneMatch','OneMatch','OneMatch','BothMatch','BothMatch','BothMatch','BothMatch','BothMatch']
Task6ColorSide = ['CoLeft','CoRight']
Task7Colors = ['palegreen', 'gray','red','green','darkcyan','saddlebrown','magenta','cornflowerblue']
Task7Shapes = [Diamond, Bell, Triangle, Circle, Star, Moon, Ellipse, Plus]
if Task == 1 or Task == 2 or Task == 3 or Task == 4 or Task == 5 or Task == 6:
SampShape = random.choice(shape_list)
SampColor = random.choice(color_list)
if Task == 7:
SampShape = random.choice(Task7Shapes)
SampColor = random.choice(Task7Colors)
End Routine tab of last routine:
total_trials = trial_loop.thisN + 1
Symbol_acc_hist.append(Sscore1)
Match_last50 = Match_acc_hist[-Width:]
Symbol_last50 = Symbol_acc_hist[-Width:]
Match_avg_acc = (sum(Match_last50))/Width
Symbol_avg_acc = (sum(Symbol_last50))/Width
if(Match_avg_acc >=0.80 and Symbol_avg_acc >=.80 and total_trials >= 6):
Mscore = 0
Sscore = 0
Match_acc_hist = []
Symbol_acc_hist = []
if Task < 7:
Task += 1
When I try to run the experiment, I am now getting errors saying my SampColor variable is not defined. It is defined in the same tab at the Task = expInfo[‘Task’] code. I have also tried moving the Task = expInfo[‘Task’] code to the Begin Routine tab and have the same issue.
Thank you for the additional information about your use case.
I think thank the best option for you would not be to use the expInfo dialogue box, but instead have the Task value read from parameters.txt in Begin Experiment, handled during the experiment as a variable and then saved to parameters.txt in End Experiment. You should then add a keyboard override where, for example, the q key breaks the loops.
I’ve made edits for you to review in the attached file.
DeclareMonkey.psyexp (95.7 KB)
I’m not sure why it seems to have parameters.txt.csv as a file in my test.
As an aside, I think I should have told you to use Task = int(expInfo[‘Task’]) to ensure that Task was coded as a number, not a string.
What is the ‘q’ key doing? Currently nothing happens when I press it.
Thanks!
Edit:
The q only exits if it is in the “Symbols” loop and then the parameters.txt is updated. But the Symbols loop is conditional, they only move to this loop if they match correctly. I tried copying the routine but it causes the screen to go black and I have to force exit. So I added custom code to the matchtrial routine so it sets conditional = False and forces ends the loop.
The other issue I am having is that it is also now creating a new parameters.txt each time I run the program so I have multiple copies of the parameters.txt, and the data is saving to the parameters.txt file instead of the data folder with the expInfo parameters as the name. Attached is an example of the paramters file I am now getting in my main experiment folder.
parameters.txt_1.csv (2.9 KB)
Hi,
I’m sorry that I haven’t been able to be more helpful here. I’ve made some more edits so that the ‘q’ key will quit in more places. However, I don’t understand why parameter.txt isn’t getting overwritten and why the additional csv and psydat files are being created.
One thing that you could try with your original file is to only open the file once rather than multiple times.
In principle I feel that
f = open(filename, 'r')
if '1' in f.read():
Task = 1
elif '2' in f.read():
Task = 2
elif '3' in f.read():
Task = 3
elif '4' in f.read():
Task = 4
elif '5' in f.read():
Task = 5
elif '6' in f.read():
Task = 6
elif '7' in f.read():
Task = 7
f.close()
should be better than
with open(filename) as f:
if '1' in f.read():
Task = 1
with open(filename) as f:
if '2' in f.read():
Task = 2
with open(filename) as f:
if '3' in f.read():
Task = 3
with open(filename) as f:
if '4' in f.read():
Task = 4
with open(filename) as f:
if '5' in f.read():
Task = 5
with open(filename) as f:
if '6' in f.read():
Task = 6
with open(filename) as f:
if '7' in f.read():
Task = 7
Best wishes,
Wakefield
DeclareMonkey.psyexp (104.7 KB)
For some reason it is still creating a bunch of parameters files and never creating a real data file. And when I try to run the program when anything besides 1 is in the parameters I get a bunch of error messages saying none of my variables are defined. So it is still only working the way I had it originally where it has to read the parameters file every trial. It definitely opens and runs very slowly this way, but is the only way I’ve gotten it to work.
Thanks for you help!
Hi bjackson
I have probably the same problem. when I attach a loop of less than 15 conditions, it works fine. However, when I attach more that 15 conditions, i just have many data no in an excel file. I wonder how did you resolve that please?
Unfortunately, I was never able to identify what the issue was. I ended up just remaking my experiment from scratch and it is working.
thank you very much