![]() ![]() ![]() Note that this page is concerned with Code Components specifically, and not all cases in which you might use python syntax within the Builder. To see what other variables you might want to use, and also what terms you need to avoid in your chunks of code, compile your script before inserting the code object and take a look at the contents of that script. So if you have a Routine called trial, there will be a Clock called trialClock and so you can get the time (in sec) from the beginning of the trial by using:: currentT = trialClock.getTime() For example, all routines have a stopwatch-style Clock associated with them, which gets reset at the beginning of that repeat of the routine. Within your code you can use other variables and modules from the script. You can move Components up and down the Routine by right-clicking on their icons. You may want the code not to take effect until next frame however, in which case put it at the bottom of the Routine. If you want your Code Component to alter a variable to be used by another component immediately, then it needs to be above that component in the view. See code uses below.īe aware that the code for each of the components in your Routine are executed in the order they appear on the Routine display (from top to bottom). writing code to interact with the serial/parallel ports). This might be create a variable that you want for another Component, to manipulate images before displaying them, to interact with hardware for which there isn’t yet a pre-packaged component in PsychoPy (e.g. If you are interesting in another randomization script using PsychoPy click here.The Code Component can be used to insert short pieces of python code into your experiments. However, if you know a better method I would love to see it. The script solved my problem of quazi-randomization and it is pretty quick. ![]() #We need to run again if the constrains we need is not satisfiedĮlif freq != ntrials/2 and freq !=ntrials/2 or sum(freq) !=ntrials: The last line of code call the function, with a list, and number of trials. That is, it is 50% items that are of a color and then followed by a different color? An additional check is also made to make sure that there are as many items that were required (i.e-, number of trials ntrials). That is, sometimes the randomization will fail and, therefore, the code below first checks that the wanted output has been generated. The last code snippet, below, crucial for the script to be fully functional since. NEachstim = ntrials/len(liststim) #Number of each stim is going to be evenĬountOfStim = dict((el,0) for el in stimList) Ntrials is an integer indicating number of trials Liststim.append(col + '-' + figure + '_' + figure2)īased on that each filename (of the images) starts with Black or Blue. Fifty percent of the items in the list are followed by a stimulus in the same colour and the remaining 50 % are followed by a stimulus in a different colour. For this experiment, I needed a list of stimuli names that were quasi-randomized. This was written, specifically, for a psychological experiment ( a shifting/task-switching task) I was planning to conduct. Here you will find a Python function for randomization with constrains. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |