Re: [psychopy-users] Import conditions from Excel File

929 views
Skip to first unread message

Michael MacAskill

unread,
May 1, 2013, 6:25:21 PM5/1/13
to psychop...@googlegroups.com
Hi Danielle,

This is the way the trialHandler works: you don't need to specify how many trials to run, as it assumes that you will want one trial for each row (so it assumes 24 iterations in this case).

nReps says how many times the file should be repeated. In this case, you should end up with 48 trials (not sure why you aren't, but that isn't a problem as it isn't what you want anyway).

In essence, you can get it to do what you want, but you need a second loop, and a way of terminating the trial handler early.

As I understand it, you have 24 possible pairs, but for any given run, you only want three of them to randomly sampled from those 24? But those three should themselves be shown four times.

So what you want is a trialHandler with nReps = 1, pointing to your xlsx file, and specified to be random. Nested within that, you want a *second* simple loop, which just repeats each trial four times. You also want a check so that your trial handler will end early (after just 3 trials rather than 24:

for trials in myTrialHandler:
# repeat each pair 4 times:
for repeatTrial in range(4):
# draw the stimuli
# get a response, etc

# but only do 3 of the possible 24 pairs:
if myTrialHandler.thisN() == 3:
myTrialHandler.finished=True # terminate early

The above is all pseudo code but hopefully shows you the structure you need.

All this assumes you are using Coder. I think you are but if not there is a page here on terminating loops in Builder:
<http://www.psychopy.org/recipes/builderTerminateLoops.html>


PS do you really have a line saying "OOO_trialList=data.importConditions('OOO.xlsx')"?
Python doesn't accept variables beginning with numbers.


On 2 May, 2013, at 07:58, Danielle Penny <dpen...@gmail.com> wrote:

> Hello all,
>
> I'm designing an experiment where 3 pairs of images are selected from a list of 24 total pairs. These 3 image pairs are shown in a loop which repeats 4 times. The list of image pairs is stored in an xlsv file; to retrieve them, I defined the trialList as <"OOO_trialList=data.importConditions('OOO.xlsx')"> then in the loop coded <imageA.setImage(StimA)>, where StimA is the title of a column in the spreadsheet. Right now the loop works, and successfully choses 3 image pairs. However, the loop repeats 25 times rather than 4. I believe this is because there are 25 rows in the Excel sheet (no where in my code do I specify the number 25). nReps is currently defined as 2, but seems to have no effect. Any ideas on how to change this? Thank you.
> Best, Danielle

--
Michael R. MacAskill, PhD michael....@nzbri.org
Research Director,
New Zealand Brain Research Institute

66 Stewart St http://www.nzbri.org/macaskill
Christchurch 8011 Ph: +64 3 3786 072
NEW ZEALAND Fax: +64 3 3786 080










Colby Tibbets

unread,
Jun 13, 2015, 12:59:33 PM6/13/15
to psychop...@googlegroups.com
I am also having an issue importing variables from Excel:

data.importConditions(fileName,'matrix.xlsx', returnFieldNames=False, selection='posL','sqrL', 'posR', 'sqrR')
When I run this code, I get 

SyntaxError: non-keyword arg after keyword arg

it seems to be in the same format as the example on the psychopy site. 
What am I doing wrong?
Michael R. MacAskill, PhD                michael.maca...@nzbri.org

Jonathan Peirce

unread,
Jun 15, 2015, 7:08:09 AM6/15/15
to psychop...@googlegroups.com


On 13/06/15 17:59, Colby Tibbets wrote:
> selection='posL','sqrL', 'posR', 'sqrR'
You need these in brackets to indicate that they are a single entity (a
list). Otherwise Python assumes that 'sqrL' is another argument in the
function.

jon

--
Jonathan Peirce
University of Nottingham

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.

Reply all
Reply to author
Forward
0 new messages