Howdy, Stranger!

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

Supported by

[solved] read a cvs file as variables

edited November 2015 in OpenSesame

he!

I found some similar problems on this forum but i just can’t get it work for me.
http://forum.cogsci.nl/index.php?p=/discussion/962/open-use-csv-in-lieu-of-loop-spreadsheet/p1
(I have not a lot of experience with python code)
I want to use an external txt or cvs file with two coulombs with the names of pictures in it as my variables.

for example:
„pic_left”,”pic_right"
"1l.jpg”,”1r.jpg"
"2l.jpg”,”2r.jpg"
"3l.jpg”,”3r.jpg"

I haven an experiment in which two pictures are shown in pairs.
the pairs are individual matched per participant and the file consist this individual matches in the right order.
I struggle with where i have to put the inline scripts, where i have to save the file, and which variables names I have to
right where.
image

I hope someone can help me with this.
thanks in advance!
Anouk

Comments

  • edited October 2015

    Hi Anouk,
    The resolution of the image is not high enough for me to be able to read the code. In any case, do you really need to use that .txt file, or could you just copy everything to python lists? You could put this in your inline script:

     left_pictures = ["1l.jpg", "2l.jpg", "3l.jpg"]
     right_pictures = ["1r.jpg","2r.jpg", "3r.jpg"]  # et cetera.
    

    It's possible to read something from a txt file in python, but it seems to me like an unnecessary additional step. If you have to, look up the python readlines() command on google. It'll be something like this; (make sure the txtfile is added to your filepool first!):

     path=exp.get_file('stimuli.txt')
     with open(path) as file:
           stimuli = file.readlines()
    

    Note that you can also counterbalance everything within OpenSesame, rather than through the use of manually organized txtfiles. (By using a loop item)

    Cheers,

    Josh

  • edited 10:57PM

    He Josh,
    Thanks for your help! I found a way that works for my experiment. But now i ame facing a new problem.
    So, I have this .txt-file. This is the for each participant individual playlist for the pictures in the experiment. Now I want to log the names of these pictures in a logger. But when I do this de logger do not display the names of the pictures from the txt file but what is written in the variable sheet. Also the order of the pairs and picture is different from my playlist which I can’t explain. I want the experiment to play the playlist in de same order.
    can you help me out?

    This is my inline code :Sorry! I don't know how to post code the right way.

    import csv
    2 subject_nr = self.get("subject_nr") # To get the subjectnr from OpenSesame# Read the txt file into a list, with one entry per row
    3

    4 with open('C:\Users\Lizz\Desktop\Exposure_duration_Anouk\Exposure_duration_Anouk\pool\pairs_' + str(subject_nr) + '_evaluation.txt', 'rb') as stimfile:
    5 reader = csv.reader(stimfile, delimiter='\t')
    6 contents = [row for row in reader]
    7

    8 # Make a list of dict items, with the column names from the
    9 # top of the txt file as keys, and the subsequent columns
    10 # as values.
    11 col_names = contents[0]
    12 stimuli = [dict(zip(col_names, row)) for row in contents[1:]]
    13

    14 # Transform these stimuli to OpenSesame variables.
    15 # To illustrate, imagine the first two variables are "probe" and "condition"
    16 for i in range(len(stimuli)):
    17 trial = stimuli[i]
    18 exp.set("pic_left_%i" % i, trial["pic_left"])
    19 exp.set("pic_right_%i" % i, trial["pic_right"])
    20 exp.set("rating_left_%i" % i, trial["rating_left"])
    21 exp.set("rating_right_%i" % i, trial["rating_right"])

  • edited 10:57PM

    Hi Anouk,

    In order to log a variable, it has to be 'set', by means of

       exp.set('picture', imagename)
    

    where imagename is the name of your image, be it either a string or a number. You have to make sure that imagename represents exactly what you want to have logged for the variable 'picture'.

    Further, I don't know in what way you translate these stimuli into a working display, so I can't tell yet what causes them to be displayed out of order. If you just pick a stimulus by 'popping' its name from a list (by means of stimulus = image_list.pop(0), the order of the list should be maintained.
    Also note that the loop item calls conditions in a random manner by default; this is a setting that can be turned off, in case you used the loop item.

    Cheers,

    Josh

  • edited 10:57PM

    Hi Josh,
    Thank you for your response. We do set the variables (i.e., pic_left_0 to pic_left_39) with the exp.set command. In the loop object we have a column named pic_left in which [pic_left_0], [pic_left_1], etc. are used (exactly the same as in: http://eointravers.github.io/blog/2014/04/opensesame-randomise/) However, what is logged in the logfile is the variablename pic_left_0 and not the actual imagename.
    Best, Nynke

  • edited 10:57PM

    Hi Nynke,

    Yes, all the variables you create in a loop item (so not an inline_script) are logged as is. Hence, you would log the exact value pic_left_0, rather than what pic_left_0 is supposed to refer to. Logged variables from the loop thus reflect conditions, rather than trial-specific items. You have to specifically set your item in an inline_script (within the loop), if you want to log the specific item for each trial.

    Cheers,

    Josh

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