Adding breaks

1,618 views
Skip to first unread message

newbie

unread,
Sep 21, 2011, 9:11:14 AM9/21/11
to psychopy-users
Hi-

I am currently trying to present some stimuli- there are 80 randomised
trials. Is there any way of inserting a break after 20, 40, 60
trials?

Thanks!

Emily Ward

unread,
Sep 21, 2011, 10:05:44 AM9/21/11
to psychop...@googlegroups.com
Are you using the builder or coding it? If you're coding it, it's as simple as checking which trial number you're on, using something like enumerate, which allows you to iterate through a list *and* keep track of the index. So, when the trialNum/index is divisible by 20 (and greater than 0, which is the first trial), present a break screen. Like this...

breakText = visual.TextStim(win, color='black',text="Please take a short break. Press any key to continue.")

for trialNum,trial in enumerate(trialList):
   if trialNum > 0 and trialNum % 20 == 0:
breakText.draw()
win.flip()
        event.waitKeys()
   presentTrial(trial)  #Your normal trial presentation lines here






--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To post to this group, send email to psychop...@googlegroups.com.
To unsubscribe from this group, send email to psychopy-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/psychopy-users?hl=en.


newbie

unread,
Sep 21, 2011, 10:44:39 AM9/21/11
to psychop...@googlegroups.com
unfortunately I'm using the builder- I'm not proficient with coding!

Jonathan Peirce

unread,
Sep 21, 2011, 11:34:57 AM9/21/11
to psychop...@googlegroups.com
Could you use 3 loops of 20 trials and insert a 'Break' routine in between them? (you'll have to call it 'Break', because 'break' is a reserved word in the programming language):

In that case your Break Routine would just be something like a keyboard that lasted the length of your break and ended early on a press(?)

If that isn't possible with your trial structure then you could have a Flow like this:

And the Break Routine would then be as above, but also with something that terminates the routine if it isn't rep number
20 or 40.So Break occurs on every pass but terminates immediately nearly every time. The way to do that is to have a Code Component with the following code in the 'Each Frame' section:

if trials.thisTrialN not in [20,40]:
    continueRoutine=False

Jon

PS anyone know what the EPrime way would be? ie Is there something more intuitive we cold allow?

On 21/09/2011 15:44, newbie wrote:
unfortunately I'm using the builder- I'm not proficient with coding! --


-- 
Dr. Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk/

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

Emily Ward

unread,
Sep 21, 2011, 11:36:23 AM9/21/11
to psychop...@googlegroups.com
I don't know builder at all, but you can try add this to the code, if you wanna give a little coding a shot... after you've set up your main trial loop and go to compile the code, look for the line:

for thisTrial in trials:
    currentLoop = trials

and change it to:

for trialNum,thisTrial in enumerate(trials):
    if trialNum > 0 and trialNum % 20 == 0 :
        breakText = visual.TextStim(win, color='white',text="Please take a short break. Press any key to continue.")
        breakText.draw()
        win.flip()
        event.waitKeys()
    currentLoop = trials



On Wed, Sep 21, 2011 at 10:44 AM, newbie <victori...@gmail.com> wrote:
unfortunately I'm using the builder- I'm not proficient with coding!

--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/eiAX6PCJxLsJ.

newbie

unread,
Sep 21, 2011, 11:39:56 AM9/21/11
to psychop...@googlegroups.com
I'll give it a go, thanks!
 
E-Prime has an option to set breaks after so many trials- it's really just a check box thing.
 
thanks

newbie

unread,
Sep 21, 2011, 11:42:13 AM9/21/11
to psychop...@googlegroups.com
Ah- I've just reread what you've said- this means I need to split up my trials into seperate sets- which I prefer not to have to do- I'll have to counterbalance these sets in some way- it would be great if I could just present all 80 of them in a random order!

Jonathan Peirce

unread,
Sep 21, 2011, 11:46:05 AM9/21/11
to psychop...@googlegroups.com
implementing such a thing would be easy enough (e.g. as a box in the
loop dialog if this is something that's commonly needed). With most of
these things the question is whether the feature adds more value
(utility to some users) than cost (clutter/confusion to others)

> --
> You received this message because you are subscribed to the Google
> Groups "psychopy-users" group.

> To view this discussion on the web visit

> https://groups.google.com/d/msg/psychopy-users/-/m9KZq-q-PEQJ.


> To post to this group, send email to psychop...@googlegroups.com.
> To unsubscribe from this group, send email to
> psychopy-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/psychopy-users?hl=en.

--

Jonathan Peirce

unread,
Sep 21, 2011, 11:51:56 AM9/21/11
to psychop...@googlegroups.com
Then solution 2 is the one you need, which is slightly more involved

> could just present all 80 of them in a random order! --


> You received this message because you are subscribed to the Google
> Groups "psychopy-users" group.

> To view this discussion on the web visit

> https://groups.google.com/d/msg/psychopy-users/-/QQxgJBre6vQJ.


> To post to this group, send email to psychop...@googlegroups.com.
> To unsubscribe from this group, send email to
> psychopy-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/psychopy-users?hl=en.

--

newbie

unread,
Sep 21, 2011, 11:53:45 AM9/21/11
to psychop...@googlegroups.com
i'll give it a go!

Victoria Simms

unread,
Sep 22, 2011, 5:27:48 AM9/22/11
to psychop...@googlegroups.com
I tried to use that script- first of all what do you mean by the 'Each frame section'?
 
Also when I have put any new script in I get this message:
 
 if trials.thisTrialN not in [20,40]:
NameError: name 'trials' is not defined
 
Sorry for being a pain.

On Wed, Sep 21, 2011 at 4:53 PM, newbie <victori...@gmail.com> wrote:
i'll give it a go!

--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/Vss2k0J-o8gJ.

Jonathan Peirce

unread,
Sep 23, 2011, 3:20:18 AM9/23/11
to psychop...@googlegroups.com

I've attached a demo experiment to show you the idea.

When I actually created it I noticed a slight wrinkle which is that
nothing at the moment directly stores the trial number in the way I
thought. There's
trials.thisTrialN which stores the trial number within this rep
trials.thisRepN which stores the number of the repeat
For the demo I've sent you there is only one condition repeating many
times (so I used thisRepN) but more likely you need many conditions
repeating once (so you need to switch to using thisTrialN).

I wish I had set thisTrialN to keep track of the total number of trials
run so far. But I guess we'll add something new to do that in the next
release (trials.N ?).

On 22/09/2011 10:27, Victoria Simms wrote:
> I tried to use that script- first of all what do you mean by the 'Each
> frame section'?

In the Code Component (look in the Break Routine of the attached exp)


> Also when I have put any new script in I get this message:
> if trials.thisTrialN not in [20,40]:
> NameError: name 'trials' is not defined

You need a loop called trials and you'd need the break routine to be
within that loop.
If your loop is called runs then you need runs.thisTrialN etc.

> Sorry for being a pain.

Don't worry - user issues highlight the things that we need to
add/adjust. You've got me thinking about new ways to make things run
only under certain conditions, but I'll probably start a new thread
about that...

Jon

demoInsertBreaks.psyexp

newbie

unread,
Sep 26, 2011, 5:02:26 AM9/26/11
to psychopy-users
Jon,

Thanks so much for all your help- it's really appreciated!

I'm going to give this all a go now.

cheers,

vic
>  demoInsertBreaks.psyexp
> 6KViewDownload

newbie

unread,
Sep 26, 2011, 5:13:49 AM9/26/11
to psychopy-users
It works!

Thanks!

On Sep 23, 8:20 am, Jonathan Peirce <jon.pei...@gmail.com> wrote:
>  demoInsertBreaks.psyexp
> 6KViewDownload

Erik

unread,
Nov 21, 2011, 12:19:11 PM11/21/11
to psychopy-users
As a quick extra note to this thread: if you have more than one
condition in your trials, you should also check the trial number in
the break code - otherwise you'll be asked to break on each trial of
the rep instead of just the one that at the start. For me, that looked
like:

if not (trials.thisRepN in [20,40] and trials.thisTrialN == 0):
continueRoutine = False

For example, if you had two conditions [rows] in your .csv (i.e.
distractor: 'present' or 'absent'), this would break after 40 and 80
trials, respectively. Otherwise you'd have two breaks right after each
other in rep 20 and rep 40.

Hope this helps someone. Thanks for making this excellent software,
Erik

On Sep 26, 4:13 am, newbie <victoriasimm...@gmail.com> wrote:
> It works!
>
> Thanks!
>
> On Sep 23, 8:20 am, Jonathan Peirce <jon.pei...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I've attached a demo experiment to show you the idea.
>
> > When I actually created it I noticed a slight wrinkle which is that
> > nothing at the moment directly stores the trial number in the way I
> > thought. There's
> >      trials.thisTrialN which stores the trial number within this rep
> >      trials.thisRepN which stores the number of the repeat
> > For the demo I've sent you there is only one condition repeating many
> > times (so I used thisRepN) but more likely you need many conditions
> > repeating once (so you need to switch to using thisTrialN).
>
> > I wish I had set thisTrialN to keep track of the total number oftrials
> > run so far. But I guess we'll add something new to do that in the next
> > release (trials.N ?).
>
> > On 22/09/2011 10:27, Victoria Simms wrote:> I tried to use that script- first of all what do you mean by the 'Each
> > > frame section'?
>

> > In the Code Component (look in theBreakRoutine of the attached exp)> Also when I have put any new script in I get this message:
> > >  iftrials.thisTrialN not in [20,40]:


> > > NameError: name 'trials' is not defined
>

> > You need a loop calledtrialsand you'd need thebreakroutine to be

k.k.cl...@gmail.com

unread,
Jun 22, 2015, 2:11:45 PM6/22/15
to psychop...@googlegroups.com
Hello,

This post has proven very useful for me as well.  

Is there some symbol/code snippet that I can place inside the Text dialog box in Builder that would allow me to tell the participant what trial they had just completed before the break, e.g. "You've just completed 20 trials! Take a short break." where the '20' would draw form something like $trials.thisTrialN.

I tried that but I get a syntax error when I try to compile.  I'm not very familiar with how to do this sort of dynamic text in Python, so some basics would be helpful.

Thanks!

Jeremy Gray

unread,
Jun 22, 2015, 2:17:32 PM6/22/15
to psychop...@googlegroups.com
Is there some symbol/code snippet that I can place inside the Text dialog box in Builder that would allow me to tell the participant what trial they had just completed before the break, e.g. "You've just completed 20 trials! Take a short break." where the '20' would draw form something like $trials.thisTrialN.
I tried that but I get a syntax error when I try to compile.  I'm not very familiar with how to do this sort of dynamic text in Python, so some basics would be helpful.

The text you enter has to be legal python syntax, except for a $ symbol appearing in the line, ideally the first character for ease of reading it.

So you'd need something like this, including all single and double quotation marks

$"You've just completed " + trials.thisTrialN + " trials! Take a short break."
 
This will also work if you prefer to think of it in this form:

"You've just completed " + $trials.thisTrialN + " trials! Take a short break."

--Jeremy



Thanks!

On Wednesday, 21 September 2011 11:34:57 UTC-4, Jon wrote:
Could you use 3 loops of 20 trials and insert a 'Break' routine in between them? (you'll have to call it 'Break', because 'break' is a reserved word in the programming language):

In that case your Break Routine would just be something like a keyboard that lasted the length of your break and ended early on a press(?)

If that isn't possible with your trial structure then you could have a Flow like this:

And the Break Routine would then be as above, but also with something that terminates the routine if it isn't rep number
20 or 40.So Break occurs on every pass but terminates immediately nearly every time. The way to do that is to have a Code Component with the following code in the 'Each Frame' section:

if trials.thisTrialN not in [20,40]:
    continueRoutine=False

Jon

PS anyone know what the EPrime way would be? ie Is there something more intuitive we cold allow?

On 21/09/2011 15:44, newbie wrote:
unfortunately I'm using the builder- I'm not proficient with coding! --


-- 
Dr. Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk/

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.

To post to this group, send email to psychop...@googlegroups.com.

Michael MacAskill

unread,
Jun 22, 2015, 3:29:55 PM6/22/15
to psychop...@googlegroups.com

> On 23/06/2015, at 06:17, Jeremy Gray <jrg...@gmail.com> wrote:
>
> $"You've just completed " + trials.thisTrialN + " trials! Take a short break."

Hi,

It might also need the str() function to turn the integer trial number value into a string of characters:

$"You've just completed " + str(trials.thisTrialN) + " trials! Take a short break."

Cheers,

M

k.k.cl...@gmail.com

unread,
Jun 22, 2015, 5:24:29 PM6/22/15
to psychop...@googlegroups.com
That works great.  Thanks to both of you!
Message has been deleted

Paula

unread,
Nov 23, 2015, 1:36:07 PM11/23/15
to psychopy-users
Hi,

I was also trying to had a break after a x number of stimuli using Builder. I was able to do it, but if I want to break after 4 stimuli within a list of 8, I have to write:
if trials.thisTrialN not in [3]:
    continueRoutine=False

I would expect to define 4 as the number after which a break should be presented. 

Moreover, I have to write:
if trials.thisTrialN not in [1,3,5]:
    continueRoutine=False

If I want a break after each pair of sentences.

I am not getting the logic, sorry.

I am able to put i to work, but I would like to understand the logic, if possible.

Is it possible to define: make a break after every 20 stimuli?

Thanks a lot for your help and, specially, for this wonderful software.

Best regards,

Paula

Michael MacAskill

unread,
Nov 23, 2015, 3:19:12 PM11/23/15
to <psychopy-users@googlegroups.com>
Hi Paula,

> I was also trying to had a break after a x number of stimuli using Builder. I was able to do it, but if I want to break after 4 stimuli within a list of 8, I have to write:
> if trials.thisTrialN not in [3]:
> continueRoutine=False

You've hit on the correct solution.

> I would expect to define 4 as the number after which a break should be presented.
PsychoPy is written in the Python language, which (like most computer languages), counts elements in lists, arrays, and so on as starting from 0. So the first trial is actually the 'zeroth' entry in the list of trials (if you have n trials, the list will run from 0 to n-1). PsychoPy has to stick to the underlying zero-base, or else all sorts of unintentional errors would arise. So this is a situation where we have to think like computer programmers rather than human beings. So be aware that in the data output from PsychoPy, the first trial will be numbered as 0, through to n-1.

Confusion arises for scientists in particular because the rare exceptions to this standard are languages like R and Matlab that are commonly used in science. Rather than being general purpose languages like Python, these are based on solving mathematical/statistical problems, where the notation convention is for lists and arrays to be numbered from one…

> Moreover, I have to write:
> if trials.thisTrialN not in [1,3,5]:
> continueRoutine=False
>
> If I want a break after each pair of sentences.
Sure, you can use a mathematical expression rather than listing all of the possible values. One of the key useful things here is the modulus expression (%), which gives the remainder after a division. Effectively above, you are just checking to see if .thisTrialN is an odd number, which is equivalent to checking if the remainder after dividing by 2 is equal to 1:

if trials.thisTrialN % 2 == 1: # Yay, we don't need a list of all odd numbers!
continueRoutine=False

> I am not getting the logic, sorry.
> I am able to put i to work, but I would like to understand the logic, if possible.
That is a great attitude: there is a real danger in just pasting in code from other people and using it without understanding what it is actually doing.

> Is it possible to define: make a break after every 20 stimuli?
Certainly, just modify the above expression to check for a remainder of 19 after dividing by 20:

if trials.thisTrialN % 20 == 19: # Will be true every 20 trials (trials numbered 19, 39, 59, etc)
continueRoutine=False

Best wishes,

Michael


--
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill

Richard Höchenberger

unread,
Nov 23, 2015, 3:46:33 PM11/23/15
to psychop...@googlegroups.com
On Mon, Nov 23, 2015 at 9:19 PM, Michael MacAskill
<michael....@nzbri.org> wrote:
> So this is a situation where we have to think like computer programmers rather than human beings.

Hey there, this wasn't very nice, programmers have feelings too!! ;)

Paula Luegi

unread,
Nov 24, 2015, 11:17:47 AM11/24/15
to psychop...@googlegroups.com
Thank you very much, Michael. Again!!!

I tried to not bother you again, but it seems that you are always there.

The zero thing is one of the two/three things I now about Python, but I did not combine that information with this question. Now it makes a lot of sense! 

Sometimes, when I realize that I will not understand the point, I just copy, otherwise I make a little effort to understand it.

I will try to implement your solution but I have not completely understand it yet. I will ask for help at home before bothering you again.

Best wishes,

Paula

--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/gvSkCZa2ceE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.

To post to this group, send email to psychop...@googlegroups.com.

Michael MacAskill

unread,
Nov 24, 2015, 3:28:27 PM11/24/15
to <psychopy-users@googlegroups.com>

> I will try to implement your solution but I have not completely understand it yet.

A good thing to do here is just play with Python to see how it works. e.g. switch to the Coder view and click on the "Shell" tab.

e.g. to understand how the % (modulus) operator works, just type expressions like this:

4 % 2

or:

4 % 3

And see what answers you get.

Regards,

Michael


Paula Luegi

unread,
Nov 24, 2015, 4:46:47 PM11/24/15
to psychop...@googlegroups.com
Thanks Michael, I will try to play with coder someday (I really want to learn Python!), but now I new to finish my experiment. Moreover, I am planning to go to the Python for Neuroscience Workshop, next April.

For now I believe that I will be able to create a pause after every 20 sentences with the code you suggested.

I have searched in the forum and I realized that it is a bit difficult to activate a pseudorandomized order. I would like to have one filler sentence (lets say, sentences of type A) at least in between each experimental item (type B sentence). Is it to difficult to implement that in the builder?

Best wishes,

Paula

--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/gvSkCZa2ceE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.

Michael MacAskill

unread,
Nov 24, 2015, 4:59:33 PM11/24/15
to <psychopy-users@googlegroups.com>

> On 25/11/2015, at 10:46, Paula Luegi <paula...@gmail.com> wrote:
>
> I have searched in the forum and I realized that it is a bit difficult to activate a pseudorandomized order. I would like to have one filler sentence (lets say, sentences of type A) at least in between each experimental item (type B sentence). Is it to difficult to implement that in the builder?

This does get tricky. One option would be to have two columns of sentences in your conditions file (one for type A and one for type B).

The easiest way to implement this in Builder would be to have a second routine which runs after the first. The First shows a sentence from type A and the second, from type B. Otherwise, you can keep just one routine, but you will need to use a little bit of code to decide which list it will show a sentence from on a given trial.

Beware that the two columns will be sorted together when randomising (i.e. rows stick together). f this is a problem, then the rows need to be sorted independently in the two columns. There have been a number of previous questions & answers about how to shuffle columns independently, which google should help with.

Regards,
Reply all
Reply to author
Forward
0 new messages