예제 #1
0
def registration(gui=gui):
    gui = gui.Dlg()
    gui.addField("Subject ID:")
    gui.addField("Condition Num:")
    gui.show()
    gui.close()
    #save data
    subj_id = gui.data[0]
    cond_num = int(gui.data[1])  # Control =0, retreat = 1
    return (subj_id, cond_num)  #save this data as the excell name?


# cross object

# registration()
def init_and_show_gui():
    gui = psychopy.gui.Dlg()
    gui.addField("Participant Number:", "001")
    gui.addField("Condition Number:", 1)
    gui.addField("Age:", 26)
    gui.addField("Gender(m/f/o):", "f")
    gui.show()
    print(gui.data)
    return gui
예제 #3
0
def show_dialog_and_get_info():
    print("show_dialog...")
    gui = psychopy.gui.Dlg()
    gui.addField("Participant Name:", "Ilaria")
    gui.addField("Condition Number:", 1)
    gui.addField("Age:", 26)
    gui.addField("Gender(m/f/o):", "f")
    # this is a blocking function. as long as the participant has not clicked ok the code progression
    # will be blocked here
    gui.show()
    participant_number = gui.data[0]
    cond_num = int(gui.data[1])
    age = int(gui.data[2])
    gender = (gui.data[3])
    return participant_number, cond_num, age, gender
예제 #4
0
# and moves towards the left side of the screen. A red dot sits in the left side of the screen (random offset from the center)
# Aim of the task is to make the moving-dot stop on top of the red square (by pressing any key).
# Extra thing: when the dot is closer than 10 pixel to the red square, it is not presented on the screen anymore
# =============================================================================
from psychopy import visual, core, event
from psychopy.hardware import keyboard
from random import randint
import pandas as pd
import numpy as np
from pandas import DataFrame
import psychopy.gui
from psychtoolbox import *

gui = psychopy.gui.Dlg()

gui.addField("Subject ID:")
gui.addField("Condition Num:")

gui.show()

sub_id = gui.data[0]
cond_num = int(gui.data[1])

screenXpix = 800
screenYpix = 600

# create a new window in fullscreen
win = visual.Window(size=[screenXpix, screenYpix],
                    color='black',
                    units="pix",
                    screen=1,
#shutdown key

event.globalKeys.add(key='q', func=core.quit, name='shutdown')

# upload excel reward structure

#datafile = xlrd.open_workbook(r "C:\Users\ic18563\OneDrive - University of Bristol\python different\python start\sensitivity_reward_condition.xlsx")
#workbook = xlrd.open_workbook(datafile)

#datafile= xlrd.open_workbook (r "C:\Users\ic18563\OneDrive - University of Bristol\python different\python start\sensitivity_punishment_condition.xlsx")
#workbook = xlrd.open_workbook(datafile)

# Participant info for everybody

gui = psychopy.gui.Dlg()
gui.addField("Participant Number:", "Ilaria")
gui.addField("Condition Number:", 1)
gui.addField("Age:", 22)
gui.addField("Gender(m/f/o):", "f")
gui.show()

participant_num = (gui.data[0])
cond_num = int(gui.data[1])
age = int(gui.data[2])
gender = (gui.data[3])

print(gui.data[3])

# creating and checking file location

data_path = participant_num + "_cond_" + str(cond_num) + "Age" + str(
예제 #6
0
import psychopy.event
import psychopy.core
import psychopy.visual
import psychopy.gui
import psychopy.sound
import os
import BDM
import sort_by_BDM

# subject info window
gui = psychopy.gui.Dlg()
gui.addField("Subject ID:")
gui.addField("Age:")
gui.addField("Gender:")
gui.show()

# saving subject info
subj_id = gui.data[0]
subj_age = gui.data[1]
subj_gender = gui.data[2]
#save as a metadata to the Results DataFrame

cur_folder = r"C:\Users\wolfi\Documents\PythonCourse\Final_project\Python-Hackathon"

tx_file = BDM.main(subj_id)

# tx_file = r"C:\Users\wolfi\Documents\PythonCourse\Final_project\Python-Hackathon\Output\11_BDM1.txt"
keys = r"C:\Users\wolfi\Documents\PythonCourse\Final_project\Python-Hackathon\Only_6_snacks_ladder_key.xlsx"

A = sort_by_BDM.Sort_By_BDM(tx_file, keys)
df = A.create_full_df()
fixation_time = 3
fixation_end_time = 3

#inter-stimulus-interval length in seconds
isi = 1

#import stuff
from psychopy import visual, event, sound, core, gui
import random
import numpy
import os
import time

#input participant data w/ graphic interface
gui = gui.Dlg()
gui.addField("Subject ID:")
gui.addField("Session nr:")
gui.show()

#===========================================================

### SET DISP AND STIMULI

win = visual.Window(
    size=(size_monitor),
    fullscr=False,  #change this for the experiment to True
    monitor="testMonitor",
    color=[0, 0, 0],
    units="deg",
    screen=0,  # 0 is participant monitor, 1 is experimenter monitor
    allowGUI=True)
예제 #8
0
import os, sys, numpy
from psychopy import core, event, visual, sound, gui

gui = gui.Dlg()
gui.addField("Participant Number:")
gui.addField("Name:")
gui.show()

subject_id = gui.data[0]
subject_name = gui.data[1]

n_blocks = 10

# win = visual.Window([1200,800], fullscr=True,  color=[-1,-1,-1])
win = visual.Window([1200, 800], color=[-1, -1, -1])

stars = visual.DotStim(win, dir=1, nDots=100, fieldSize=(2, 2))

ship = visual.ImageStim(win, image='resources/images/ship.png', size=0.4)
asteroid = visual.ImageStim(win,
                            'resources/images/asteroid.png',
                            pos=(0, 1),
                            size=0.2)
laser = visual.ImageStim(win,
                         image='resources/images/beams.png',
                         size=0.3,
                         pos=(-0.15, 0.1))
splash_title = visual.ImageStim(win,
                                image="resources/images/splash.png",
                                opacity=0)
예제 #9
0
import os
import sys
import numpy as np
import psychopy.visual
import psychopy.event
import psychopy.gui
import psychopy.core

gui = psychopy.gui.Dlg()

gui.addField("Sujeto ID:")
gui.addField("Condición. num.:")
gui.addField("Sesión num_rep:")

gui.show()

subj_id = gui.data[0]
cond_num = gui.data[1]
rep_num = gui.data[2]

data_path = subj_id + "_cond_" + cond_num + "_rep_" + rep_num + ".tsv"

if os.path.exists(data_path):
    sys.exit("Data path " + data_path + " already exists!")

responses = []

sfm_size_pix = 200
sfm_dot_size_pix = 5
sfm_n_dots = 1000
sfm_dot_shape = "gauss"
예제 #10
0
fixation_size = 0.7  # 0.7         | units in cm
fullscreen = True  # True

# shuffler
shuffle(seq)
oc_seq = [1, 2] * openclose_per_block
gaze_seq = ['l', 'r', 'u', 'd'] * gaze_per_block
shuffle(gaze_seq)

##########################################
#         Initialize Components          #
##########################################
# GUI to enter subj & experiment details
gui = gui.Dlg(title="eog_blinks")
gui.addFixedField("exp:", 'eog_blinks')
gui.addField("SubjID:", '001')
gui.show()
if not gui.OK:
    print('Cancelled')
    core.quit()
exp_name = gui.data[0]
subj_id = gui.data[1]
exp_summary = exp_name + '_' + subj_id
print('exp summary: ' + str(exp_summary))  # NetStation setup

if netstation:
    import egi.simple as egi
    ms_localtime = egi.ms_localtime
    ns = egi.Netstation()
    print("Imported PyNetstation")
def RunMathTask():
    #declare global variables
    global task_start_time
    global window
    global kb
    global log_file
    global procs
    global rules
    global pracs
    global rulenames
    global pracnames
    global instnames
    global insts
    global postnames
    global posts
    global gui

    #Get Subject ID using gui

    gui = gui.Dlg()
    gui.addField("Subject ID:")
    gui.show()
    SubjectID = gui.data[0]
    print(SubjectID)

    #onset of first instruction via image

    proc1 = visual.ImageStim(window, image='Proc01.jpeg')

    proc1.draw()
    window.flip()

    proc1response = event.waitKeys(keyList=[
        'space',
    ], timeStamped=True)

    #Rule videos and practice problem sequence

    #play each of the 6 rule videos
    for i in range(3):
        rulemov = visual.MovieStim3(window,
                                    name=rulenames[i],
                                    noAudio=False,
                                    filename=rules[i])

        rulemov.play()

        #play full video for each
        for j in range(int(rulemov.duration * 60)):
            rulemov.draw()
            window.flip()

    #show each of the 6 practice problems, participants have to answer each one using '1', '2', or '3'
    responserec = ""

    for i in range(6):
        ruleprac = visual.ImageStim(window, name=pracnames[i], image=pracs[i])

        ruleprac.draw()
        window.flip()

        pracresponse = event.waitKeys(keyList=[
            '1',
            '2',
            '3',
        ],
                                      timeStamped=True)

        #log Subject ID, name of the problem, and response to each problem
        log_file.write(SubjectID + "," + pracnames[i] + "," +
                       pracresponse[0][0] + "\n")

    #onset of second instruction via image (we skip Proc02 in the lab and go right to Proc03)
    proc3 = visual.ImageStim(window, image='Proc03.jpeg')

    proc3.draw()
    window.flip()

    proc3response = event.waitKeys(keyList=[
        'space',
    ], timeStamped=True)

    #instructional problem sequence

    #show each of the 8 instructional problems, participants have to answer each one using '1', '2', or '3'
    responserec = ""

    for i in range(8):
        instprobs = visual.ImageStim(window, name=instnames[i], image=insts[i])

        instprobs.draw()
        window.flip()

        instresponse = event.waitKeys(keyList=[
            '1',
            '2',
            '3',
        ],
                                      timeStamped=True)

        #log Subject ID, name of the problem, and response to each problem
        log_file.write(SubjectID + "," + instnames[i] + "," +
                       instresponse[0][0] + "\n")

    #onset of next instruction screen via image (this image prompts the post test)
    proc4 = visual.ImageStim(window, image='Proc04.jpeg')

    proc4.draw()
    window.flip()

    proc4response = event.waitKeys(keyList=[
        'space',
    ], timeStamped=True)

    #beginning of post test

    #show each of the 8 instructional problems, participants have to answer each one using '1', '2', or '3'
    responserec = ""

    for i in range(35):
        postprobs = visual.ImageStim(window, name=postnames[i], image=posts[i])

        postprobs.draw()
        window.flip()

        postresponse = event.waitKeys(keyList=[
            '1',
            '2',
            '3',
        ],
                                      timeStamped=True)

        #log Subject ID, name of the problem, and response to each problem
        log_file.write(SubjectID + "," + postnames[i] + "," +
                       postresponse[0][0] + "\n")

    #onset of final instruction  screen thanking participant for participation
    proc5 = visual.ImageStim(window, image='Proc05.jpeg')

    proc5.draw()
    window.flip()

    proc5response = event.waitKeys(keyList=[
        'space',
    ], timeStamped=True)
예제 #12
0
dt = datetime.datetime.now()
date = dt.strftime("%x")
time = dt.strftime("%X")

############################################################################################
# Generate User ID
############################################################################################
gui = psychopy.gui.Dlg(title="User ID", pos=(400, 800))
gui.addText('Format of User ID is', color='Black')
gui.addText('      1. AGE -> NN', color='Black')
gui.addText('      2. SEX -> M/F', color='Black')
gui.addText('      3. First 2 letters of your first name and last name',
            color='Black')
gui.addText('Example : For a guy named Sven Milz aged 32', color='Blue')
gui.addText('      User ID -> 32MSVMI', color='Blue')
gui.addField("User ID:")
gui.show()
if gui.OK:
    print(gui.data[0])
else:
    sys.exit("user cancelled")

pattern = re.compile(r'^([1-9]{2})' r'([m|M|f|F])' r'([a-zA-Z]{4})')

valid_in = pattern.findall(gui.data[0])
if valid_in:
    usr_id = gui.data[0]
    os.chdir(exp_id + "/")
    file = usr_id + ".csv"
    file = file.lower()
예제 #13
0
            i = i[:-1]
        inp = [int(j) - 1 for j in i.split(',')]
        r, t = one_trail(inp[:4], inp[4:8])
        res_ans = -1
        if r == 'm':
            res_ans = 1
        elif r == 'c':
            res_ans = 0

        f.write(i + ',{},{},{}\n'.format(r, t, int(res_ans == inp[-1] + 1)))


if __name__ == '__main__':  # The code start from here
    # Subject's information
    gui = gui.Dlg()
    gui.addField("Subject ID:")
    gui.addField("condition")
    gui.show()

    subj_id = gui.data[0]
    condition = gui.data[1]

    # Initialize the environment
    starting_information()
    mon = monitors.Monitor(name='mypc', width=37, distance=60)
    mon.setSizePix((800, 600))
    win = visual.Window(size=[800, 600], units='pix')
    if int(condition) == 1:
        trial_file_session1 = 'set2.csv'
        trial_file_session2 = 'set4.csv'
    elif int(condition) == 2:
예제 #14
0
# -*- coding: utf-8 -*-
# Import packages
import pyllusion as ill
import numpy as np
from psychopy import visual, event, gui
import os
import sys
import wx

# Set up GUI
gui = gui.Dlg()
gui.addField("Subject ID:")
gui.addField("Experiment Title:")

gui.show()

# subj_id = gui.data[0]
# rep_num = gui.data[1]

# data_path = subj_id + "_rep_" + rep_num + ".tsv"

# if os.path.exists(data_path):
#     sys.exit("Data path " + data_path + " already exists!")
# exp_data = []

# Initiate window
app = wx.App(False)
width = wx.GetDisplaySize()[0]
height = wx.GetDisplaySize()[1]

window = visual.Window(size=[width - 100, height - 100],
예제 #15
0
# which can be used to enter in experiment/subject info
# Whenever you ran our experiments before, you probably noticed how you entered subject ID and so on
# It is the gui function that lets you do it.

# GUI to enter subj & experiment details
gui = gui.Dlg(title="Sample Code Parameter"
              )  # this line creates a box frame named the given title
# now we can add however many fields we want using .addField, .addFixedField
# .addFixedField adds a text field that cannot be modified in the box
# then why add a fixed field? It's useful to specify details of experiment/subject
# ie. if you know that the experiment is purely behavioral, you could add something like 'beh' tag
gui.addFixedField("exp:", 'sample')
# Q1. Add two fields named 'SubjID' and 'type' being behavioral

# ---YOUR CODE START---
gui.addField("SubjID:", '001')
gui.addField("type:", 'beh')
# ---YOUR CODE END---

gui.show()
if not gui.OK:
    print('Cancelled')
    core.quit()

# Now whatever input is entered in the gui can be accessed by gui.data[index]
exp_name = gui.data[0]  # this will return sample

# Q1-2. Now create variables named 'subj_id' and 'exp_type' to retrieve the SubjID and type information from the gui you created above:

# ---YOUR CODE START---
subj_id = gui.data[1]
예제 #16
0
import os
import sys
import numpy as np
from random import randint
from random import shuffle
import psychopy.core

# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__)).decode(
    sys.getfilesystemencoding())
os.chdir(_thisDir)

#input subject and partner ID
#store values for later
gui = psychopy.gui.Dlg()
gui.addField("Subject ID: ")
gui.addField("Partner ID: ")
gui.show()
subID = gui.data[0]
partnerID = gui.data[1]

dir = "data" + str(subID) + "_" + str(partnerID) + ".csv"
while os.path.exists(
        dir):  #if path exists, remame it to avoid overwriting data
    print "CHECK SUBJECT NUMBER"
    subID = subID + "000"
    dir = "data" + str(subID) + "_" + str(partnerID) + ".csv"

#load video ########
#figure out a good naming convention to call them
예제 #17
0
monitor_dpi = 96  # crucial for size!

# Stimulus parameters
habituation_total_duration = 10  # in seconds
habituation_image_duration = 0.5  # in seconds
habituation_isi = 0.2  # in seconds
test_total_duration = 10  # in seconds
test_image_duration = 1  # in seconds
test_isi = 1  # in seconds
background_color = 'grey'
path_to_images = 'G:\My Drive\Lara\SNARC'
#path_to_logfile = 'G:\My Drive\Lara\SNARC\test\test.txt'

# This creates the message box to get measure ID
gui = gui.Dlg()
gui.addField("Subject ID:")
gui.show()

# This creates the windows where you draw your stimuli
window_1 = visual.Window(size=(monitor_width, monitor_height),
                         fullscr=True,
                         screen=0,
                         allowGUI=False,
                         units='pix',
                         monitor='testMonitor',
                         colorSpace='rgb255',
                         color=background_color)

# Create images
squares_12_1 = visual.ImageStim(window_1,
                                image=path_to_images + '\squares_12_1.png',
예제 #18
0
import os
import sys
import random
import numpy as np
import psychopy.visual
import psychopy.event
import psychopy.gui
import psychopy.core

gui = psychopy.gui.Dlg()

gui.addField("Subject ID:")
gui.addField("Repeat num:")

gui.show()

subj_id = gui.data[0]
rep_num = gui.data[1]

data_path = subj_id + "_rep_" + rep_num + ".tsv"

if os.path.exists(data_path):
    sys.exit("Data path " + data_path + " already exists!")

exp_data = []

bg_colour = [-1, -1, -0.25]

oval_radius_pix = [10, 18]
oval_fill_colour = [-1, 0.25, -1]
n_ovals_per_dim = 40