Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Referencing to image file pool in psychopy

edited October 2013 in OpenSesame

Hi!
I'm using the following script for randomizing pictures in the file pool.

import copy
import random

# Create a list of 100 pictures and shuffle them
nr_of_pictures = 100
self.experiment.pictures = []
for i in range(nr_of_pictures):
    self.experiment.pictures.append("MP%d.png" % i)
random.shuffle(self.experiment.pictures)

# Create some lists for bookkeeping, so we remember which pictures have been shown
self.experiment.unused_pictures = copy.deepcopy(self.experiment.pictures)
self.experiment.Memory_Target = copy.deepcopy(self.experiment.pictures)
self.experiment.Targets_Distractors = copy.deepcopy(self.experiment.pictures)
self.experiment.Memory = []
self.experiment.Target = [] 

During a trial I'm using the following script for selecting pictures

import random
from array import array
from psychopy import visual, core, event, sound

# Select 2 random pictures
pic1 = self.experiment.unused_pictures.pop()
pic2 = self.experiment.unused_pictures.pop()

# Save the pictures as experimental variables
self.experiment.set("pic1", pic1)
self.experiment.set("pic2", pic2)

# Remember that these pictures were targets
self.experiment.Memory_Target.append(pic1)
self.experiment.Memory_Target.append(pic2)

# Get pictures for Left and Right Polygon + Fixation dot
fixdot = visual.PatchStim(self.experiment.window, tex = None, size = 12, mask = "circle", color = "white")
ImRight = visual.ImageStim(win, image="pic1",pos=(250, 0.0), size=(350))
ImLeft = visual.ImageStim(win, image="pic2",pos=(-250, 0.0), size=(350))

As you can see in the last bit I'm using psychopy instead of the built-in canvas options. Psychopy requires a path for getting pictures and using the 'pic1'/ 'pic2' variables doesn't work

So, my question: Is there a way I can stil use the other script for randomizing and selecting pictures and make psychopy recognize the 'pic1' and 'pic2' variables?

at the moment I get the following error

Error: Inline script error
In: Congruent_Right (prepare phase)
File "dist\psychopy\visual.py", line 7419, in createTexture

Python traceback:
OSError: Couldn't find image file 'pic1'; check path? (tried: C:\Program Files\OpenSesame\pic1)

If anything is unclear or more information is needed please let me know. Thanks in advance!

Comments

  • edited 10:30AM

    Hi Michel,

    You could use the experiment function exp.get_file() to find the path corresponding to a given file name. Do the variables pic1 and pic2 refer to the exact file names of the .png files? And are the .png files saved in the file pool or in the same folder as your .opensesame.tar.gz script? In that case finding the paths simply works like this:

    path1 = exp.get_file(pic1)
    path2 = exp.get_file(pic2)
    

    For more information, see:

    Then, you use the paths instead of the filenames when calling the psychopy function visual.ImageStim().

    ImRight = visual.ImageStim(win, image=path1,pos=(250, 0.0), size=(350))
    

    Also, make sure you use the identifier name of the object (without quotes) for the keyword argument image. In your script, you wrote

    ImRight = visual.ImageStim(win, image="pic1",pos=(250, 0.0), size=(350))
    

    In this case you accidentally make the image argument a literal constant (i.e., "pic1"), instead of variable (e.g. "MP1.png", or "MP2.png", etc., depending on the current cycle).

    Does this help? Please let us know if you still encounter any problems!

    Cheers,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited October 2013

    Hi Lotje,

    Adding the, <exp.get_file()>, function worked like a charm!

    Also, I was aware of the quotes, I think it was a remnant of the trial and error testing I did to try and make the code work. My programming skills are not that advanced ;).

    Thank you very much! If anything else comes up I won't hesitate to ask.

    Greetings,
    Michel

  • edited 10:30AM

    That's great! :) And yes, feel free to post any further questions!

    Did you like my answer? Feel free to Buy Me A Coffee :)

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games