Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

How looping pictures stimulus

I am programming my cognitive-emotion recognition experiment. But I had some difficulties concerned how to looping the image using "expyriment.stimuli.Picture()". I had 5 major emotion and i want to present in 2 blocks and 5 trials. Here some my code :
n_trials_block = 5
n_blocks = 2
emo_stimuli = ["G:/Py/Imej/Anger.jpg", "G:/Py/Imej/Contempt.jpg", "G:/Py/Imej/Disgust.jpg", "G:/Py/Imej/Happy.jpg"]
exp = expyriment.design.Experiment(name="Emotion_Recognition")
expyriment.control.initialize(exp)

for block in range(n_blocks):
my_block = expyriment.design.Block(name=str(block + 1))
for trial in range(n_trials_block):
now_stimuli = emo_stimuli[trial]
emot_stim = expyriment.stimuli.Picture(emo_stimuli)
emot_trial = expyriment.design.Trial()
emot_trial.add_stimulus(emot_stim)
my_block.add_trial(emot_trial)

my_block.Shuffle_trials()
exp.add_block(my_block)

Comments

  • fladdfladd Posts: 80

    Hi Tanto,

    I am not sure I understand what it exactly it is you want to achieve. Could you maybe be a bit more specific?

    Best,
    Florian

    Thanked by 1Tanto

    Florian Krause (Developer)
    http://www.expyriment.org

  • TantoTanto Posts: 3

    My apologies, I am new in Python and all the stuff scripting language. My research is to distinguish ERA (Emotional Response Ability) with Positive Emotion and Negative Emotion. In positive emotion I have happy and joy, in negative emotion there are sad and anger. To present this image I need some ability to looping the image, otherwise I just write it down in very tidy ways :

    block = 2
    n_trial_block = 5
    expyriment.io.defaults.outputfile_time_stamp = False
    exp = expyriment.design.Experiment(name="Visual_Emotion_Recognition")
    expyriment.control.initialize(exp)

    block_one = expyriment.design.Block(name="1")
    trial_one = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Anger.jpg")
    stim.preload()
    trial_one.add_stimulus(stim)
    trial_two = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Sad.jpg")
    trial_two.add_stimulus(stim)
    trial_three = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Sad.jpg")
    trial_three.add_stimulus(stim)
    trial_four = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Anger.jpg")
    trial_four.add_stimulus(stim)
    trial_five = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Sad.jpg")
    trial_five.add_stimulus(stim)
    block_one.add_trial(trial_one)
    block_one.add_trial(trial_two)
    block_one.add_trial(trial_three)
    block_one.add_trial(trial_four)
    block_one.add_trial(trial_five)
    block_one.shuffle_trials()
    exp.add_block(block_one)

    block_two = expyriment.design.Block(name="2")
    trial_one = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Fear.jpg")
    stim.preload()
    trial_one.add_stimulus(stim)
    trial_two = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Sad.jpg")
    trial_two.add_stimulus(stim)
    trial_three = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Sad.jpg")
    trial_three.add_stimulus(stim)
    trial_four = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Fear.jpg")
    trial_four.add_stimulus(stim)
    trial_five = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Fear.jpg")
    trial_five.add_stimulus(stim)
    block_two.add_trial(trial_one)
    block_two.add_trial(trial_two)
    block_two.add_trial(trial_three)
    block_two.add_trial(trial_four)
    block_two.add_trial(trial_five)
    block_two.shuffle_trials()
    exp.add_block(block_two)

    block_three = expyriment.design.Block(name="3")
    trial_one = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Happy.jpg")
    stim.preload()
    trial_one.add_stimulus(stim)
    trial_two = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Joy.jpg")
    trial_two.add_stimulus(stim)
    trial_three = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Happy.jpg")
    trial_three.add_stimulus(stim)
    trial_four = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Happy.jpg")
    trial_four.add_stimulus(stim)
    trial_five = expyriment.design.Trial()
    stim = expyriment.stimuli.Picture("G:/Py/Imej/Joy.jpg")
    trial_five.add_stimulus(stim)
    block_three.add_trial(trial_one)
    block_three.add_trial(trial_two)
    block_three.add_trial(trial_three)
    block_three.add_trial(trial_four)
    block_three.add_trial(trial_five)
    block_three.shuffle_trials()
    exp.add_block(block_three)

    and so on..I just want to looping this three blocks. Its easier if the stimuli like textline to be presented that i can use list but if i do, there is some error that said "list cannot decode". After all..thanksssss for your support!!!

  • fladdfladd Posts: 80

    Assuming your question is how to get two different block types (one negative, one positive emotion), where each has 5 trials that are randomly(?) drawn from two possible pictures, something along the lines of this should work:

    import expyriment as xpy
    
    
    pictures = {"anger": xpy.stimuli.Picture("G:/Py/Imej/Anger.jpg"),
                "sad": xpy.stimuli.Picture("G:/Py/Imej/Sad.jpg"),
                "happy": xpy.stimuli.Picture("G:/Py/Imej/Happy.jpg"),
                "joy": xpy.stimuli.Picture("G:/Py/Imej/Joy.jpg")}
    for picture in pictures:
        pictures[picture].preload()
    
    exp = xpy.design.Experiment("Emotion Regulation")
    
    for emotion_type, emotions in {"negative": ["anger", "sad"], "positive": ["happy", "joy"]}.items():   # use iteritems() in Python 2
        block = xpy.design.Block()
        block.set_factor("EmotionType", emotion_type)
        for trial_repetition in range(5):
            trial = xpy.design.Trial()
            emotion = xpy.design.randomize.rand_elem(emotions)
            trial.set_factor("Emotion", emotion)
            trial.add_stimulus(pictures[emotion])
        exp.add_block(block)
    

    Florian Krause (Developer)
    http://www.expyriment.org

  • TantoTanto Posts: 3

    Hi Florian
    Thank you very much! the basic is combine with tuple with every stimuli. I'll work for the rest (correct response in certain emotion).

Sign In or Register to comment.