Problem with showing first stimulus in for loop whilst all other stimuli are fine

Hi,

My first stimulus shows up on a grey screen for 1 second whilst all my other stimuli are fine… I’m struggling to understand why this is as it’s all in a for loop. Code below and the stimuli file attached, I would masssively appreciate any help, thank you!

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 30 14:04:49 2022

@author: emilia

Piloting script for motor task with a pre-defined duration.
"""

from psychopy import visual, core, sound, data, gui, logging
from psychopy.visual import TextStim, ImageStim
from psychopy.hardware import keyboard
import psychopy.event

import pandas as pd
import random as rd
from datetime import datetime
import os
import serial

# %%%%%%%%%% Path directories %%%%%%%%%%

_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)

# %%%%%%%%%% Setting up the experiment %%%%%%%%%%

ask_port = False

experimentName = 'motor_task_pilot'
if ask_port == True:
    experimentInfo = {'Participant': '', 'Port name': ''}
else:
    experimentInfo = {'Participant': ''}
dlg = gui.DlgFromDict(dictionary=experimentInfo, sortKeys=False, title=experimentName)
if not dlg.OK:
    print("User pressed 'Cancel'!")
    core.quit()

experimentInfo['date'] = data.getDateStr()
experimentInfo['expName'] = experimentName
experimentInfo['psychopyVersion'] = '2021.2.3'
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (experimentInfo['Participant'],
                                                   experimentName, experimentInfo['date'])

thisExp = data.ExperimentHandler(name=experimentName, extraInfo=experimentInfo,
                                 originPath='C:/Users/emilia/Documents/Dementia task piloting/Lumo/resting_state/resting_state.py',
                                 savePickle=True, saveWideText=True,
                                 dataFileName=filename)
# Setting up a log file
logFile = logging.LogFile(filename + '.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING)

endExpNow = False
frameTolerance = 0.001

# Event triggers

if ask_port == True:
    port_name = '/dev/tty.usbserial-' + experimentInfo['Port name']
else:
    port_name = '/dev/tty.usbserial-FTBXN67J'

#port = serial.Serial(port_name, baudrate=9600)

# Key inputs
kb = keyboard.Keyboard()
trial_timer = core.CountdownTimer()

# Set up window
win = visual.Window([1440, 900], color=[-1, -1, -1], fullscr=True)

# Monitor frame rate
experimentInfo['frameRate'] = win.getActualFrameRate()
if experimentInfo['frameRate'] != None:
    frameDur = 1.0 / round(experimentInfo['frameRate'])
else:
    frameDur = 1.0 / 60.0

# Hide mouse
win.mouseVisible = False


# %%%%%%%%%% FUNCTIONS %%%%%%%%%%
def closing(duration):
    closing_text = TextStim(win, text='')
    closing_text.draw()
    win.flip()
    core.wait(duration)
    win.flip()


# %%%%%%%%%% LOADING DATA %%%%%%%%%%
motor_task_stimuli = pd.read_csv(
    '/Users/emilia/Documents/Dementia task piloting/Lumo/motor_task/naturalistic_motor_stimuli.csv')

ready = TextStim(win, text='ready?')
ready.draw()
win.flip()
psychopy.event.waitKeys()

# %%%%%%%%%% SETTING UP TRIAL COMPONENTS %%%%%%%%%%

motor_clock = core.Clock()
pre_baseline_duration = 2 + (rd.random()/10)
block_duration = 5

# %%%%%%%%%% TESTING TRIALS %%%%%%%%%%
for j in range(len(motor_task_stimuli)):

    # Baseline
    win.color = [0.0039, 0.0039, 0.0039]
    motor_clock.reset()
    while motor_clock.getTime() < pre_baseline_duration:
        fixation_cross = TextStim(win, text='+')
        fixation_cross.draw()
        win.flip()
        
    win.color = [-1, -1, -1]
    
    # Selecting the correct image & instruction
    task_text = motor_task_stimuli['stimulus'][j]
    task = TextStim(win, text=task_text)
        
    # Trials
    trigger_sent = False
    key_pressed = False
    motor_clock.reset()
    while not key_pressed and motor_clock.getTime() < block_duration:
        task.draw()
        if trigger_sent == False:
            #win.callOnFlip(port.write, motor_task_stimuli['trigger'][j].encode())
            trigger_sent = True
        win.flip()
        keys = kb.getKeys(keyList=None, waitRelease=True)
        if len(keys) > 0:
            #port.write((motor_task_stimuli['trigger'][j] + '2').encode())
            key_pressed = True
    
# %%%%%%%%%% EXPERIMENT END %%%%%%%%%%

core.wait(2)
win.mouseVisible = True
win.flip()

closing(4)

thisExp.abort()
#port.close()
win.close()
core.quit()

naturalistic_motor_stimuli.csv (385 Bytes)