# Export position data of image objects

**URL:** <https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009>\
**Category:** Builder\
**Created:** [November 21, 2024, 11:41am UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009 "2024-11-21T11:41:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aimmcg](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/aimmcg/32/43412_2.png) [@aimmcg](https://discourse.psychopy.org/u/aimmcg)\
**Post date:** [November 21, 2024, 11:41am UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/1 "2024-11-21T11:41:59Z")

</div>

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](https://discourse.psychopy.org/t/drag-drop-stimuli/8503)). 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 🙂 Let me know if you can help!

Aimee

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 21, 2024, 1:23pm UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/2 "2024-11-21T13:23:21Z")

</div>

Please could you show your Each Frame code?

---

<div class="post-metadata">

**Author:** ![aimmcg](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/aimmcg/32/43412_2.png) [@aimmcg](https://discourse.psychopy.org/u/aimmcg)\
**Post date:** [November 21, 2024, 1:26pm UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/3 "2024-11-21T13:26:39Z")

</div>

Hello,

Yes it’s pretty simple so far:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/7/d74c861bf27e4b4ccea5c75b1eacb90d0f375532.png)

Where the ‘pieces’ are image stimuli.

Thanks,  
Aimee

---

<div class="post-metadata">

**Author:** ![aimmcg](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/aimmcg/32/43412_2.png) [@aimmcg](https://discourse.psychopy.org/u/aimmcg)\
**Post date:** [November 21, 2024, 1:27pm UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/4 "2024-11-21T13:27:16Z")

</div>

Sorry screenshotted the wrong one somehow…

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/d/1dfccaf58b6113aa5d281ae5e365cbdd5860c0c6.png)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 21, 2024, 1:32pm UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/5 "2024-11-21T13:32:16Z")

</div>

Try in End Routine

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

```

---

<div class="post-metadata">

**Author:** ![aimmcg](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/aimmcg/32/43412_2.png) [@aimmcg](https://discourse.psychopy.org/u/aimmcg)\
**Post date:** [November 21, 2024, 1:39pm UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/6 "2024-11-21T13:39:41Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/9/c9fe246af71e8e52aadc9c07ac4bccc3d2165e05.png)

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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 21, 2024, 2:08pm UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/7 "2024-11-21T14:08:28Z")

</div>

It certainly should have added 8 columns.

Try

```auto
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?

---

<div class="post-metadata">

**Author:** ![aimmcg](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/aimmcg/32/43412_2.png) [@aimmcg](https://discourse.psychopy.org/u/aimmcg)\
**Post date:** [November 21, 2024, 3:01pm UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/8 "2024-11-21T15:01:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 21, 2024, 3:11pm UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/9 "2024-11-21T15:11:29Z")

</div>

How did you create the pieces list?

Try this code?

```auto
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.)

---

<div class="post-metadata">

**Author:** ![aimmcg](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/aimmcg/32/43412_2.png) [@aimmcg](https://discourse.psychopy.org/u/aimmcg)\
**Post date:** [November 22, 2024, 1:28pm UTC](https://discourse.psychopy.org/t/export-position-data-of-image-objects/43009/10 "2024-11-22T13:28:36Z")

</div>

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