Export position data of image objects

Hello,

I’m relatively new to using the coder component in PsychoPy builder, so I would really appreciate some advice on how to tackle this. This experiment will be run locally and not online (so no need for JS).

The experiment asks participants to watch a video stimulus, then replicate the position of objects on a blank canvas. I have set up the stimulus routine, and the response routine (following advice from Drag & Drop Stimuli). But I’m not sure how to export the response - i.e., the pixel position of the objects. I don’t necessarily want to export ‘correct’ responses, but the accuracy of position (which I will calculate as error, retrospectively). So all I want to do is export the positions of objects at the end of each routine. I assume this will be added to the data CSV file produced at the end of each trial, but if it’s easier to create a new file then this is fine too.

I hope that makes sense :slight_smile: Let me know if you can help!

Aimee

Please could you show your Each Frame code?

Hello,

Yes it’s pretty simple so far:

Where the ‘pieces’ are image stimuli.

Thanks,
Aimee

Sorry screenshotted the wrong one somehow…

Try in End Routine

for Idx in range(len(pieces)):
     thisExp.addData('Pos'+str(Idx),pieces[Idx].pos)

Thank you!

This didn’t add any data to the output CSV file. But it did add some data lines to the stdout code. See DATA positions below. I didn’t have these lines before.

Participants will be moving 8 image objects, in an order they want, so I will need to know which object was in which position.

Thanks,
Aimee

It certainly should have added 8 columns.

Try

thisExp.addData('Pieces',len(pieces))

which should save 8 in the pieces column

Do you want the data to be the order of the x coordinates rather than the x coordinates themselves?

Those lines in the data don’t look like they came from my code. I note you pressed escape. Did you do that before the routine had ended?

Ah sorry, as I’m still building the experiment I hadn’t added a function to ‘end’ the routine yet, so I was using escape to quit the routine not realising that the data wouldn’t be saved if I left before the end of the routine. My bad…

I have now added a keyboard press to end the routine. Using the first code you sent:
for Idx in range(len(pieces)):
thisExp.addData(‘Pos’+str(Idx),pieces[Idx].pos)

I now have the new columns in the data file called Pos0, Pos1 (etc.) as coordinates, e.g, [-0.56 -0.31]. Thanks so much for your help! I’m not entirely clear on which object each PosX value relates to, can I assume it’s the order of the objects in the routine? Or is there a way I can label them according to the names of the image files?

Thanks,
Aimee

How did you create the pieces list?

Try this code?

for piece in pieces:
     thisExp.addData(piece.name,piece.pos)

(I haven’t tested this and I don’t know if you’ve named the pieces.)

Amazing, this code gave me the correct pieces names in the data export. Thanks so much :slight_smile:

1 Like