From ba549e65a18334e04faa0cf923f84f4eb0bb58d9 Mon Sep 17 00:00:00 2001 From: dyld-w Date: Thu, 31 Oct 2024 15:48:36 -0400 Subject: [PATCH] Refactors visual updates to work when running from outermost main.py --- tasks/RDM/config.py | 10 +- tasks/RDM/instruct.py | 6 +- tasks/RDM/main.py | 8 +- tasks/RDM/trial.py | 17 +- tasks/flanker/config.py | 45 ++-- tasks/flanker/flanker.py | 42 ++-- tasks/flanker/instruct.py | 165 ++++++++------ tasks/flanker/instruct_copy.py | 322 ---------------------------- tasks/flanker/list_gen.py | 4 - tasks/flanker/main.py | 8 +- tasks/flanker/stim/create_folder.py | 1 - tasks/flanker/trial.py | 22 +- tasks/flanker/trial_copy.py | 98 --------- 13 files changed, 172 insertions(+), 576 deletions(-) delete mode 100644 tasks/flanker/instruct_copy.py delete mode 100644 tasks/flanker/stim/create_folder.py delete mode 100644 tasks/flanker/trial_copy.py diff --git a/tasks/RDM/config.py b/tasks/RDM/config.py index f7de15e..ffd9c03 100644 --- a/tasks/RDM/config.py +++ b/tasks/RDM/config.py @@ -1,4 +1,12 @@ -# config + +from pathlib import Path + +# Define the base directory as the directory containing the current file +BASE_DIR = Path(__file__).resolve().parent + +# Background image path +BACKGROUND_IMAGE = str(BASE_DIR / "NIGHT_SKY.png") + NUM_BLOCKS = 1 NUM_DOTS = 100 diff --git a/tasks/RDM/instruct.py b/tasks/RDM/instruct.py index 7d939ee..cab6e2c 100644 --- a/tasks/RDM/instruct.py +++ b/tasks/RDM/instruct.py @@ -3,8 +3,8 @@ from smile.common import * from smile.scale import scale as s -from trial import Trial, GetResponse -from list_gen import gen_practice_trials +from .trial import Trial, GetResponse +from .list_gen import gen_practice_trials # Text for instructions @@ -168,7 +168,7 @@ def Instruct(self, config, lang="E", practice=False): with Loop(self.md_blocks) as block: with Parallel(): # put up the fixation cross - Background = Image(source = "./NIGHT_SKY.png", size = (self.exp.screen.size[0]*1.1, self.exp.screen.size[1]*1.1), allow_stretch = True, keep_ratio = False, blocking=False) + Background = Image(source = config.BACKGROUND_IMAGE, size = (self.exp.screen.size[0]*1.1, self.exp.screen.size[1]*1.1), allow_stretch = True, keep_ratio = False, blocking=False) Border= Ellipse(size = (s((config.RADIUS)*1.2*2),(s((config.RADIUS)*1.2*2))), color = (.55,.55,.55,1)) Telescope = Ellipse(size = (s((config.RADIUS)*1.1*2),(s((config.RADIUS)*1.1*2))), color = (.35, .35, .35, 1.0)) cross = Label(text='+', color=config.CROSS_COLOR, diff --git a/tasks/RDM/main.py b/tasks/RDM/main.py index ef650c0..a741c8c 100644 --- a/tasks/RDM/main.py +++ b/tasks/RDM/main.py @@ -9,10 +9,10 @@ from ..happy import HappyQuest -from list_gen import gen_moving_dot_trials +from .list_gen import gen_moving_dot_trials from math import log -from trial import Trial, GetResponse -from instruct import Instruct +from .trial import Trial, GetResponse +from .instruct import Instruct # from . import version @@ -88,7 +88,7 @@ def RDMExp(self, config, run_num=0, lang="E", pulse_server=None, practice=False, with Loop(self.md_blocks) as block: with Parallel(): # put up the fixation cross - Background = Image(source = "./NIGHT_SKY.png", size = (self.exp.screen.size[0]*1.1, self.exp.screen.size[1]*1.1), allow_stretch = True, keep_ratio = False, blocking=False) + Background = Image(source = config.BACKGROUND_IMAGE, size = (self.exp.screen.size[0]*1.1, self.exp.screen.size[1]*1.1), allow_stretch = True, keep_ratio = False, blocking=False) Border= Ellipse(size = (s((config.RADIUS)*1.2*2),(s((config.RADIUS)*1.2*2))), color = (.55,.55,.55,1)) Telescope = Ellipse(size = (s((config.RADIUS)*1.1*2),(s((config.RADIUS)*1.1*2))), color = (.35, .35, .35, 1.0)) cross = Label(text='+', color=config.CROSS_COLOR, diff --git a/tasks/RDM/trial.py b/tasks/RDM/trial.py index 416c63d..c1eaca8 100644 --- a/tasks/RDM/trial.py +++ b/tasks/RDM/trial.py @@ -55,22 +55,15 @@ def Trial(self, self.eeg_pulse_time = None with Parallel(): - Background = Image(source = "./NIGHT_SKY.png", size = (self.exp.screen.size[0]*1.1, self.exp.screen.size[1]*1.1), allow_stretch = True, keep_ratio = False, blocking=False) - Border = Ellipse(color = (1,1,1,0)) - Telescope = Ellipse(color = (1,1,1,0)) + background = Image(source = config.BACKGROUND_IMAGE, size = (self.exp.screen.size[0]*1.1, self.exp.screen.size[1]*1.1), allow_stretch = True, keep_ratio = False, blocking=False) + border = Ellipse(color = (1,1,1,0)) + telescope = Ellipse(color = (1,1,1,0)) with UntilDone(): with Serial(): - # with Parallel(): - # Background = Image(source = "./NIGHT_SKY.png", size = (self.exp.screen.size[0]*1.1, self.exp.screen.size[1]*1.1), allow_stretch = True, keep_ratio = False, blocking=False) - # Border = Ellipse(color = (1,1,1,0)) - # Telescope = Ellipse(color = (1,1,1,0)) # present the dots with Parallel(): cross.update(color=(.35, .35, .35, 1.0)) - # Background = Image(source = "./NIGHT_SKY.png", size = (self.exp.screen.size[0]*1.1, self.exp.screen.size[1]*1.1), allow_stretch = True, keep_ratio = False, blocking=False) - # Border = Ellipse(color = (1,1,1,0)) - # Telescope = Ellipse(color = (1,1,1,0)) md = MovingDots(color=color, scale=s(config.SCALE), num_dots=num_dots, radius=s(config.RADIUS), motion_props=[{"coherence": right_coherence, @@ -82,8 +75,8 @@ def Trial(self, lifespan=config.LIFESPAN, lifespan_variance=config.LIFESPAN_VAR, speed=s(config.SPEED)) - Border.update(center = md.center, size = (md.width*1.2, md.height*1.2), color = (.55,.55,.55,1)) - Telescope.update(center = md.center, size = (md.width*1.1, md.height*1.1), color = (.35, .35, .35, 1.0)) + border.update(center = md.center, size = (md.width*1.2, md.height*1.2), color = (.55,.55,.55,1)) + telescope.update(center = md.center, size = (md.width*1.1, md.height*1.1), color = (.35, .35, .35, 1.0)) with UntilDone(): # Collect key response Wait(until=md.appear_time) diff --git a/tasks/flanker/config.py b/tasks/flanker/config.py index 5447f57..4f418d6 100644 --- a/tasks/flanker/config.py +++ b/tasks/flanker/config.py @@ -1,4 +1,14 @@ -#from numpy import linspace +from pathlib import Path + +# Define the base directory as the directory containing the current file +BASE_DIR = Path(__file__).resolve().parent + +# Use BASE_DIR / "stim" / "fish_" to define the STIM_DIRECTORY path +STIM_DIRECTORY = str(BASE_DIR / "stim" / "fish_") + +# Background image path +BACKGROUND_IMAGE = str(BASE_DIR / "ocean_background.png") + # FLANKER VARIABLES NUM_TRIALS = 1 # (len(evidence_conditions)-1) * 4 + 2 * num_trials NUM_BLOCKS = 1 @@ -33,38 +43,7 @@ "dir": "left"}, ] -# uNCOMMENT THIS LINE FOR EXTRA CONDITIONS -# CONDITIONS = [{"stim": "__>__\n" + -# "_<><_\n" + -# "<<><<\n" + -# "_<><_\n" + -# "__>__\n", -# "condition": "|", -# "dir": "R"}, -# {"stim": "__<__\n" + -# "_<<<_\n" + -# ">>>>>\n" + -# "_<<<_\n" + -# "__<__\n", -# "condition": "--", -# "dir": "R"}, -# {"stim": "__<__\n" + -# "_><>_\n" + -# ">><>>\n" + -# "_><>_\n" + -# "__<__\n", -# "condition": "|", -# "dir": "L"}, -# {"stim": "__>__\n" + -# "_>>>_\n" + -# "<<<<<\n" + -# "_>>>_\n" + -# "__>__\n", -# "condition": "--", -# "dir": "L"}, -# ] - -STIM_DIRECTORY = "./stim/fish_" + #EVIDENCE_CONDITIONS = [0., 45.] NUM_LOCS = 8 DEF_SAT = [255.,255.,255.] diff --git a/tasks/flanker/flanker.py b/tasks/flanker/flanker.py index 38530b4..6e22024 100644 --- a/tasks/flanker/flanker.py +++ b/tasks/flanker/flanker.py @@ -1,12 +1,6 @@ from smile.common import * from smile.scale import scale as s -import config as config -from list_gen import gen_fblocks -from smile.common import * -from smile.scale import scale as s -import config as config -from list_gen import gen_fblocks @Subroutine def Flanker(self, config, center_x, center_y, direction, condition, layers, num_layers = 2, background = True): @@ -27,7 +21,7 @@ def Flanker(self, config, center_x, center_y, direction, condition, layers, num_ with Parallel(): with Parallel(): - Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, + background_image = Image(source = config.BACKGROUND_IMAGE, size = (self.exp.screen.size[0] * 1.1, self.exp.screen.size[1] * 1.1), allow_stretch = True, keep_ratio = False) center_image = Image(source = self.center_image, center = (self.center_x, self.center_y), size = (s(50),s(50)), allow_stretch = True, keep_ratio = False) @@ -69,25 +63,27 @@ def Flanker(self, config, center_x, center_y, direction, condition, layers, num_ center = (add_left.center_x, add_left.center_y - s(50*(mult+1)))) self.layer = self.layer + 1 with If(background == False): - Background.update(color = (1,1,1,0)) + background_image.update(color = (1,1,1,0)) with Serial(): Wait(until=center_image.appear_time) self.stim_appear_time = center_image.appear_time # self.stim_disappear_time = center_image.disappear_time -# blocks = gen_fblocks(config) -# exp = Experiment() -# with Loop(blocks) as block: -# with Loop(block.current) as trial: -# fl = Flanker(config, -# center_x = exp.screen.center_x + trial.current['loc_x']*s(config.FROM_CENTER), -# center_y = exp.screen.center_y + trial.current['loc_y']*s(config.FROM_CENTER), -# direction = trial.current["dir"], -# condition = trial.current['condition'], -# layers = config.LAYERS) -# with UntilDone(): -# Wait(until=fl.stim_appear_time) -# Wait(3) -# exp.run() - +if __name__ == "__main__": + import config as config + from list_gen import gen_fblocks + blocks = gen_fblocks(config) + exp = Experiment() + with Loop(blocks) as block: + with Loop(block.current) as trial: + fl = Flanker(config, + center_x = exp.screen.center_x + trial.current['loc_x']*s(config.FROM_CENTER), + center_y = exp.screen.center_y + trial.current['loc_y']*s(config.FROM_CENTER), + direction = trial.current["dir"], + condition = trial.current['condition'], + layers = config.LAYERS) + with UntilDone(): + Wait(until=fl.stim_appear_time) + Wait(3) + exp.run() diff --git a/tasks/flanker/instruct.py b/tasks/flanker/instruct.py index bfc7a3c..d9bd929 100644 --- a/tasks/flanker/instruct.py +++ b/tasks/flanker/instruct.py @@ -2,9 +2,11 @@ from smile.common import * from smile.scale import scale as s -from widget import Flanker +import config + +from .flanker import Flanker from kivy.utils import platform -from trial import Trial, GetResponse +from tasks.flanker.trial import Trial, GetResponse from math import cos, sin, sqrt, pi, radians @@ -18,7 +20,7 @@ def get_instructions(config): inst = {} inst['top_text'] = 'You will be presented with a group of symbols. \n' + \ 'You will be asked to indicate the direction that the \n' + \ - '[b]middle arrow is pointing[/b], while ignoring any other symbols. \n\n' + '[b]middle symbol is pointing[/b], while ignoring any other symbols. \n\n' inst['inst_1'] = '[b]Practice 1:[/b] \n \n' + \ 'Respond to the arrow in the red circle while ignoring the other symbols. \n' @@ -82,42 +84,59 @@ def Instruct(self, config, lang="E"): font_size=s(config.INST_FONT_SIZE)) # upper left - Flanker(center_x=self.exp.screen.center_x - s(400), + Flanker(config, center_x=self.exp.screen.center_x - s(400), center_y=toplbl.top + s(125), - box=s(config.CONFIG_BOX), around=s(config.CONFIG_AROUND), - line_width=s(config.LW), - stim="__<__\n_<<<_\n<<<<<\n_<<<_\n__<__\n") + direction = "left", + condition = "+", + layers = config.LAYERS, + background = False) + + #stim="__<__\n_<<<_\n<<<<<\n_<<<_\n__<__\n") # upper middle - Flanker(center_x=self.exp.screen.center_x, + Flanker(config, center_x=self.exp.screen.center_x, center_y=toplbl.top + s(125), - box=s(config.CONFIG_BOX), around=s(config.CONFIG_AROUND), - line_width=s(config.LW), - stim="__>__\n_><>_\n><<<>\n_><>_\n__>__\n") + direction = "left", + condition = "=", + layers = config.LAYERS, + background = False) + + #stim="__>__\n_><>_\n><<<>\n_><>_\n__>__\n") # upper right - Flanker(center_x=self.exp.screen.center_x + s(400), + Flanker(config, center_x=self.exp.screen.center_x + s(400), center_y=toplbl.top + s(125), - box=s(config.CONFIG_BOX), around=s(config.CONFIG_AROUND), - line_width=s(config.LW), - stim="__<__\n_<><_\n<><><\n_<><_\n__<__\n") + direction = "left", + condition = "~", + layers = config.LAYERS, + background = False) - # lower left - Flanker(center_x=self.exp.screen.center_x - s(400), + + #stim="__<__\n_<><_\n<><><\n_<><_\n__<__\n") + + # # lower left + Flanker(config, center_x=self.exp.screen.center_x - s(400), center_y=toplbl.bottom - s(125), - box=s(config.CONFIG_BOX), around=s(config.CONFIG_AROUND), - line_width=s(config.LW), - stim="__<__\n_<><_\n<><><\n_<><_\n__<__\n") - # lower middle - Flanker(center_x=self.exp.screen.center_x, + direction = "left", + condition = "~", + layers = config.LAYERS, + background = False) + # stim="__<__\n_<><_\n<><><\n_<><_\n__<__\n") + #WONDERING IF THIS IS AN ERROR BECAUSE IT SHOWS THE SAME ONE TWICE, I DIDN'T WRITE THIS PART + # # lower middle + Flanker(config, center_x=self.exp.screen.center_x, center_y=toplbl.bottom - s(125), - box=s(config.CONFIG_BOX), around=s(config.CONFIG_AROUND), - line_width=s(config.LW), - stim="__>__\n_><>_\n><><>\n_><>_\n__>__\n") - # lower right - Flanker(center_x=self.exp.screen.center_x + s(400), + direction = "right", + condition = "~", + layers = config.LAYERS, + background = False) + # stim="__>__\n_><>_\n><><>\n_><>_\n__>__\n") + # # lower right + Flanker(config, center_x=self.exp.screen.center_x + s(400), center_y=toplbl.bottom - s(125), - box=s(config.CONFIG_BOX), around=s(config.CONFIG_AROUND), - line_width=s(config.LW), - stim="__<__\n_<><_\n<>>><\n_<><_\n__<__\n") + direction = "right", + condition = "=", + layers = config.LAYERS, + background = False) + # stim="__<__\n_<><_\n<>>><\n_<><_\n__<__\n") with UntilDone(): Wait(until=toplbl.appear_time) @@ -125,18 +144,18 @@ def Instruct(self, config, lang="E"): Wait(1.0) - with Loop([["__<__\n_<<<_\n<<<<<\n_<<<_\n__<__\n", config.RESP_KEYS[0]], - ["__>__\n_><>_\n><<<>\n_><>_\n__>__\n", config.RESP_KEYS[0]], - ["__<__\n_<><_\n<>>><\n_<><_\n__<__\n", config.RESP_KEYS[-1]], - ["__>__\n_><>_\n><><>\n_><>_\n__>__\n", config.RESP_KEYS[-1]]]) as prac_ev: - Wait(1.0) + with Loop([["left", config.RESP_KEYS[0]], + ["left", config.RESP_KEYS[0]], + ["right", config.RESP_KEYS[-1]], + ["right", config.RESP_KEYS[-1]]]) as prac_ev: p2 = Trial(config, - stim=prac_ev.current[0], + direct=prac_ev.current[0], center_x=self.exp.screen.center_x, center_y=self.exp.screen.center_y, - correct_resp=prac_ev.current[1], condition='+') + correct_resp=prac_ev.current[1], condition='+', + background = False) with If(p2.correct): - # They got it right + # # # They got it right Label(text=u"\u2713", color='green', duration=config.FEEDBACK_TIME, font_size=s(config.FEEDBACK_FONT_SIZE), font_name='DejaVuSans.ttf') @@ -168,21 +187,24 @@ def Instruct(self, config, lang="E"): GetResponse(keys=config.CONT_KEY) - with Loop([["__<__\n_<><_\n<>>><\n_<><_\n__<__\n", config.RESP_KEYS[1], + with Loop([["right", config.RESP_KEYS[1], cos(radians((360./config.NUM_LOCS)*5)), sin(radians((360./config.NUM_LOCS)*5))], - ["__<__\n_<><_\n<><><\n_<><_\n__<__\n", config.RESP_KEYS[0], + ["left", config.RESP_KEYS[0], cos(radians((360./config.NUM_LOCS)*1)), sin(radians((360./config.NUM_LOCS)*1))], - ["__>__\n_><>_\n><><>\n_><>_\n__>__\n", config.RESP_KEYS[1], + ["right", config.RESP_KEYS[1], cos(radians((360./config.NUM_LOCS)*3.)), sin(radians((360./config.NUM_LOCS)*3.))], - ["__>__\n_><>_\n><><>\n_><>_\n__>__\n", config.RESP_KEYS[1], + ["right", config.RESP_KEYS[1], cos(radians((360./config.NUM_LOCS)*4.)), sin(radians((360./config.NUM_LOCS)*4.))], - ["__>__\n_>>>_\n>>>>>\n_>>>_\n__>__\n", config.RESP_KEYS[1], + ["right", config.RESP_KEYS[1], cos(radians((360./config.NUM_LOCS)*0)), sin(radians((360./config.NUM_LOCS)*0))], - ["__>__\n_><>_\n><<<>\n_><>_\n__>__\n", config.RESP_KEYS[0], + ["left", config.RESP_KEYS[0], cos(radians((360./config.NUM_LOCS)*2)), sin(radians((360./config.NUM_LOCS)*2))] ]) as prac_ev: - Wait(1.0) + # Wait(1.0) with Parallel(): + Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, + self.exp.screen.size[1] * 1.1), + allow_stretch = True, keep_ratio = False, blocking = False) Ellipse(color='red', size=(s(55),s(55)), center_x=self.exp.screen.center_x + prac_ev.current[2]*s(config.FROM_CENTER), center_y=self.exp.screen.center_y + prac_ev.current[3]*s(config.FROM_CENTER), @@ -191,18 +213,28 @@ def Instruct(self, config, lang="E"): center_x=self.exp.screen.center_x + prac_ev.current[2]*s(config.FROM_CENTER), center_y=self.exp.screen.center_y + prac_ev.current[3]*s(config.FROM_CENTER), blocking=False) - p4 = Trial(config,stim=prac_ev.current[0], + p4 = Trial(config,direct=prac_ev.current[0], center_x=self.exp.screen.center_x + prac_ev.current[2]*s(config.FROM_CENTER), center_y=self.exp.screen.center_y + prac_ev.current[3]*s(config.FROM_CENTER), - correct_resp=prac_ev.current[1], condition='+') + correct_resp=prac_ev.current[1], condition='+', + background = False) with If(p4.correct): + with Parallel(): # They got it right - Label(text=u"\u2713", color='green', duration=config.FEEDBACK_TIME, + Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, + self.exp.screen.size[1] * 1.1), + allow_stretch = True, keep_ratio = False, blocking = False) + Label(text=u"\u2713", color='green', duration=config.FEEDBACK_TIME, font_size=s(config.FEEDBACK_FONT_SIZE), font_name='DejaVuSans.ttf') + with Else(): + with Parallel(): + Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, + self.exp.screen.size[1] * 1.1), + allow_stretch = True, keep_ratio = False, blocking = False) # they got it wrong - Label(text=u"\u2717", color='red', + Label(text=u"\u2717", color='red', font_size=s(config.FEEDBACK_FONT_SIZE), duration=config.FEEDBACK_TIME, font_name='DejaVuSans.ttf') @@ -227,32 +259,45 @@ def Instruct(self, config, lang="E"): GetResponse(keys=config.CONT_KEY) - with Loop([["__<__\n_<><_\n<>>><\n_<><_\n__<__\n", config.RESP_KEYS[1], + with Loop([["right", config.RESP_KEYS[1], cos(radians((360./config.NUM_LOCS)*5)), sin(radians((360./config.NUM_LOCS)*5))], - ["__<__\n_<><_\n<><><\n_<><_\n__<__\n", config.RESP_KEYS[0], + ["left", config.RESP_KEYS[0], cos(radians((360./config.NUM_LOCS)*1)), sin(radians((360./config.NUM_LOCS)*1))], - ["__>__\n_><>_\n><><>\n_><>_\n__>__", config.RESP_KEYS[1], + ["right", config.RESP_KEYS[1], cos(radians((360./config.NUM_LOCS)*3)), sin(radians((360./config.NUM_LOCS)*3))], - ["__>__\n_>>>_\n>>>>>\n_>>>_\n__>__\n", config.RESP_KEYS[1], + ["right", config.RESP_KEYS[1], cos(radians((360./config.NUM_LOCS)*6)), sin(radians((360./config.NUM_LOCS)*6))], - ["__>__\n_><>_\n><<<>\n_><>_\n__>__\n", config.RESP_KEYS[0], + ["left", config.RESP_KEYS[0], cos(radians((360./config.NUM_LOCS)*2)), sin(radians((360./config.NUM_LOCS)*2))] ]) as prac_ev: - Wait(1.0) - p5 = Trial(config, stim=prac_ev.current[0], + # Wait(1.0) + with Parallel(): + Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, + self.exp.screen.size[1] * 1.1), + allow_stretch = True, keep_ratio = False, blocking = False) + p5 = Trial(config, direct=prac_ev.current[0], center_x=self.exp.screen.center_x + prac_ev.current[2]*s(config.FROM_CENTER), center_y=self.exp.screen.center_y + prac_ev.current[3]*s(config.FROM_CENTER), - correct_resp=prac_ev.current[1], condition='+') + correct_resp=prac_ev.current[1], condition='+', + background = False) with If(p5.correct): # They got it right - Label(text=u"\u2713", color='green', duration=config.FEEDBACK_TIME, + with Parallel(): + Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, + self.exp.screen.size[1] * 1.1), + allow_stretch = True, keep_ratio = False, blocking = False) + Label(text=u"\u2713", color='green', duration=config.FEEDBACK_TIME, font_size=s(config.FEEDBACK_FONT_SIZE), center_y=self.exp.screen.center_y + s(50), font_name='DejaVuSans.ttf') with Else(): # they got it wrong - Label(text=u"\u2717", color='red', + with Parallel(): + Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, + self.exp.screen.size[1] * 1.1), + allow_stretch = True, keep_ratio = False, blocking = False) + Label(text=u"\u2717", color='red', font_size=s(config.FEEDBACK_FONT_SIZE), center_y=self.exp.screen.center_y + s(50), duration=config.FEEDBACK_TIME, font_name='DejaVuSans.ttf') @@ -274,4 +319,4 @@ def Instruct(self, config, lang="E"): center_y=self.exp.screen.center_y, font_size=s(config.INST_FONT_SIZE)) with UntilDone(): - GetResponse(keys=config.CONT_KEY) + GetResponse(keys=config.CONT_KEY) \ No newline at end of file diff --git a/tasks/flanker/instruct_copy.py b/tasks/flanker/instruct_copy.py deleted file mode 100644 index ddb35f3..0000000 --- a/tasks/flanker/instruct_copy.py +++ /dev/null @@ -1,322 +0,0 @@ -# -*- coding: utf-8 -*- -from smile.common import * -from smile.scale import scale as s - -import config - -from flanker import Flanker -from kivy.utils import platform -from trial_copy import Trial, GetResponse -from math import cos, sin, sqrt, pi, radians - - -def get_instructions(config): - if len(config.CONT_KEY) > 1: - cont_key = str(config.CONT_KEY[0]) + " or " + str(config.CONT_KEY[-1]) - else: - cont_key = str(config.CONT_KEY[0]) - - - inst = {} - inst['top_text'] = 'You will be presented with a group of symbols. \n' + \ - 'You will be asked to indicate the direction that the \n' + \ - '[b]middle symbol is pointing[/b], while ignoring any other symbols. \n\n' - - inst['inst_1'] = '[b]Practice 1:[/b] \n \n' + \ - 'Respond to the arrow in the red circle while ignoring the other symbols. \n' - - inst['inst_2'] = '[b]Practice 2:[/b] \n \n' + \ - 'Now, the group of symbols will appear in different locations around the screen. \n' + \ - 'Look at the arrow inside the red circle and indicate its direction. \n' - inst['inst_3'] = '[b]Practice 3:[/b] \n \n' + \ - 'The final practice set will look like the actual task. \n' + \ - 'The group of symbols will appear at different locations around the screen. \n' + \ - 'Find the arrow at the center of the group, and indicate its direction. \n' + \ - 'In between responses, please direct your gaze to the cross at the center of the screen. \n' - if config.TOUCH: - inst_temp = 'Press the [b]left side of the screen[/b] ' + \ - 'if the arrow is pointing [b]left[/b]. \n' + \ - 'Press the [b]right side of the screen[/b] ' + \ - 'if the arrow is pointing [b]right[/b].\n' - inst['top_text'] += inst_temp + 'Press the screen to begin.' - inst['inst_1'] += inst_temp - inst['inst_2'] += inst_temp + 'Press the screen to begin.' - inst['inst_3'] += inst_temp + 'Press the screen to begin.' - inst['to_cont'] = "Press the screen to continue!" - inst['done'] = 'You have finished the Practice!\nPress the screen to continue!' - else: - inst_temp = 'Press the [b]%s[/b] '%(config.RESP_KEYS[0]) + \ - 'key if the arrow is pointing [b]left[/b]. \n' + \ - 'Press the [b]%s[/b] '%(config.RESP_KEYS[-1]) + \ - 'key if the arrow is pointing [b]right[/b].\n' - - inst['top_text'] += inst_temp + 'Press ' + cont_key + ' to begin.' - inst['inst_1'] += inst_temp - inst['inst_2'] += inst_temp + 'Press ' + cont_key + ' to begin.' - inst['inst_3'] += inst_temp + 'Press ' + cont_key + ' to begin.' - inst['to_cont'] = 'Press ' + cont_key + ' to continue!' - inst['done'] = 'You have finished the Practice!\nPress ' + cont_key + ' to continue!' - - - inst['skip_text'] = "Skip Practice" - inst['p_fdbk'] = "CORRECT!" - inst['n_fdbk'] = "INCORRECT!" - - return inst - - -@Subroutine -def Instruct(self, config, lang="E"): - - inst = Func(get_instructions, config).result - - # with If(practice==True): - with Parallel(): - if not config.TOUCH: - MouseCursor(blocking=False) - with Serial(blocking=False): - with Parallel(): - toplbl = Label(text=inst['top_text'], - markup=True, - halign='center', - center_x=self.exp.screen.center_x, - center_y=self.exp.screen.center_y, - font_size=s(config.INST_FONT_SIZE)) - - # upper left - Flanker(config, center_x=self.exp.screen.center_x - s(400), - center_y=toplbl.top + s(125), - direction = "left", - condition = "+", - layers = config.LAYERS, - background = False) - - #stim="__<__\n_<<<_\n<<<<<\n_<<<_\n__<__\n") - # upper middle - Flanker(config, center_x=self.exp.screen.center_x, - center_y=toplbl.top + s(125), - direction = "left", - condition = "=", - layers = config.LAYERS, - background = False) - - #stim="__>__\n_><>_\n><<<>\n_><>_\n__>__\n") - # upper right - Flanker(config, center_x=self.exp.screen.center_x + s(400), - center_y=toplbl.top + s(125), - direction = "left", - condition = "~", - layers = config.LAYERS, - background = False) - - - #stim="__<__\n_<><_\n<><><\n_<><_\n__<__\n") - - # # lower left - Flanker(config, center_x=self.exp.screen.center_x - s(400), - center_y=toplbl.bottom - s(125), - direction = "left", - condition = "~", - layers = config.LAYERS, - background = False) - # stim="__<__\n_<><_\n<><><\n_<><_\n__<__\n") - #WONDERING IF THIS IS AN ERROR BECAUSE IT SHOWS THE SAME ONE TWICE, I DIDN'T WRITE THIS PART - # # lower middle - Flanker(config, center_x=self.exp.screen.center_x, - center_y=toplbl.bottom - s(125), - direction = "right", - condition = "~", - layers = config.LAYERS, - background = False) - # stim="__>__\n_><>_\n><><>\n_><>_\n__>__\n") - # # lower right - Flanker(config, center_x=self.exp.screen.center_x + s(400), - center_y=toplbl.bottom - s(125), - direction = "right", - condition = "=", - layers = config.LAYERS, - background = False) - # stim="__<__\n_<><_\n<>>><\n_<><_\n__<__\n") - - with UntilDone(): - Wait(until=toplbl.appear_time) - GetResponse(keys=config.CONT_KEY) - - Wait(1.0) - - with Loop([["left", config.RESP_KEYS[0]], - ["left", config.RESP_KEYS[0]], - ["right", config.RESP_KEYS[-1]], - ["right", config.RESP_KEYS[-1]]]) as prac_ev: - p2 = Trial(config, - direct=prac_ev.current[0], - center_x=self.exp.screen.center_x, - center_y=self.exp.screen.center_y, - correct_resp=prac_ev.current[1], condition='+', - background = False) - with If(p2.correct): - # # # They got it right - Label(text=u"\u2713", color='green', duration=config.FEEDBACK_TIME, - font_size=s(config.FEEDBACK_FONT_SIZE), - font_name='DejaVuSans.ttf') - with Else(): - # they got it wrong - Label(text=u"\u2717", color='red', - font_size=s(config.FEEDBACK_FONT_SIZE), - duration=config.FEEDBACK_TIME, font_name='DejaVuSans.ttf') - - with Meanwhile(): - with Parallel(): - Ellipse(color='red', size=(s(55),s(55))) - Ellipse(color=config.INNER_CIRCLE_COLOR, size=(s(45),s(45))) - Label(text=inst['inst_1'], - markup=True, - halign='center', - center_x=self.exp.screen.center_x, - center_y=self.exp.screen.center_y + s(300), - font_size=s(config.INST_FONT_SIZE)) - - Wait(1.0) - Label(text=inst['inst_2'], - markup=True, - halign='center', - center_x=self.exp.screen.center_x, - center_y=self.exp.screen.center_y + s(300), - font_size=s(config.INST_FONT_SIZE)) - with UntilDone(): - GetResponse(keys=config.CONT_KEY) - - - with Loop([["right", config.RESP_KEYS[1], - cos(radians((360./config.NUM_LOCS)*5)), sin(radians((360./config.NUM_LOCS)*5))], - ["left", config.RESP_KEYS[0], - cos(radians((360./config.NUM_LOCS)*1)), sin(radians((360./config.NUM_LOCS)*1))], - ["right", config.RESP_KEYS[1], - cos(radians((360./config.NUM_LOCS)*3.)), sin(radians((360./config.NUM_LOCS)*3.))], - ["right", config.RESP_KEYS[1], - cos(radians((360./config.NUM_LOCS)*4.)), sin(radians((360./config.NUM_LOCS)*4.))], - ["right", config.RESP_KEYS[1], - cos(radians((360./config.NUM_LOCS)*0)), sin(radians((360./config.NUM_LOCS)*0))], - ["left", config.RESP_KEYS[0], - cos(radians((360./config.NUM_LOCS)*2)), sin(radians((360./config.NUM_LOCS)*2))] - ]) as prac_ev: - # Wait(1.0) - with Parallel(): - Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, - self.exp.screen.size[1] * 1.1), - allow_stretch = True, keep_ratio = False, blocking = False) - Ellipse(color='red', size=(s(55),s(55)), - center_x=self.exp.screen.center_x + prac_ev.current[2]*s(config.FROM_CENTER), - center_y=self.exp.screen.center_y + prac_ev.current[3]*s(config.FROM_CENTER), - blocking=False) - Ellipse(color=config.INNER_CIRCLE_COLOR, size=(s(45),s(45)), - center_x=self.exp.screen.center_x + prac_ev.current[2]*s(config.FROM_CENTER), - center_y=self.exp.screen.center_y + prac_ev.current[3]*s(config.FROM_CENTER), - blocking=False) - p4 = Trial(config,direct=prac_ev.current[0], - center_x=self.exp.screen.center_x + prac_ev.current[2]*s(config.FROM_CENTER), - center_y=self.exp.screen.center_y + prac_ev.current[3]*s(config.FROM_CENTER), - correct_resp=prac_ev.current[1], condition='+', - background = False) - with If(p4.correct): - with Parallel(): - # They got it right - Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, - self.exp.screen.size[1] * 1.1), - allow_stretch = True, keep_ratio = False, blocking = False) - Label(text=u"\u2713", color='green', duration=config.FEEDBACK_TIME, - font_size=s(config.FEEDBACK_FONT_SIZE), - font_name='DejaVuSans.ttf') - - with Else(): - with Parallel(): - Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, - self.exp.screen.size[1] * 1.1), - allow_stretch = True, keep_ratio = False, blocking = False) - # they got it wrong - Label(text=u"\u2717", color='red', - font_size=s(config.FEEDBACK_FONT_SIZE), - duration=config.FEEDBACK_TIME, font_name='DejaVuSans.ttf') - - - Label(text=inst['to_cont'], - halign='center', - center_x=self.exp.screen.center_x, - center_y=self.exp.screen.center_y, - font_size=s(config.INST_FONT_SIZE)) - with UntilDone(): - GetResponse(keys=config.CONT_KEY) - - - Wait(1.0) - Label(text=inst['inst_3'], - markup=True, - halign='center', - center_x=self.exp.screen.center_x, - center_y=self.exp.screen.center_y + s(200), - font_size=s(config.INST_FONT_SIZE)) - with UntilDone(): - GetResponse(keys=config.CONT_KEY) - - - with Loop([["right", config.RESP_KEYS[1], - cos(radians((360./config.NUM_LOCS)*5)), sin(radians((360./config.NUM_LOCS)*5))], - ["left", config.RESP_KEYS[0], - cos(radians((360./config.NUM_LOCS)*1)), sin(radians((360./config.NUM_LOCS)*1))], - ["right", config.RESP_KEYS[1], - cos(radians((360./config.NUM_LOCS)*3)), sin(radians((360./config.NUM_LOCS)*3))], - ["right", config.RESP_KEYS[1], - cos(radians((360./config.NUM_LOCS)*6)), sin(radians((360./config.NUM_LOCS)*6))], - ["left", config.RESP_KEYS[0], - cos(radians((360./config.NUM_LOCS)*2)), sin(radians((360./config.NUM_LOCS)*2))] - ]) as prac_ev: - # Wait(1.0) - with Parallel(): - Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, - self.exp.screen.size[1] * 1.1), - allow_stretch = True, keep_ratio = False, blocking = False) - p5 = Trial(config, direct=prac_ev.current[0], - center_x=self.exp.screen.center_x + prac_ev.current[2]*s(config.FROM_CENTER), - center_y=self.exp.screen.center_y + prac_ev.current[3]*s(config.FROM_CENTER), - correct_resp=prac_ev.current[1], condition='+', - background = False) - - with If(p5.correct): - # They got it right - with Parallel(): - Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, - self.exp.screen.size[1] * 1.1), - allow_stretch = True, keep_ratio = False, blocking = False) - Label(text=u"\u2713", color='green', duration=config.FEEDBACK_TIME, - font_size=s(config.FEEDBACK_FONT_SIZE), - center_y=self.exp.screen.center_y + s(50), - font_name='DejaVuSans.ttf') - with Else(): - # they got it wrong - with Parallel(): - Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, - self.exp.screen.size[1] * 1.1), - allow_stretch = True, keep_ratio = False, blocking = False) - Label(text=u"\u2717", color='red', - font_size=s(config.FEEDBACK_FONT_SIZE), - center_y=self.exp.screen.center_y + s(50), - duration=config.FEEDBACK_TIME, font_name='DejaVuSans.ttf') - with Meanwhile(): - Label(text="+", font_size=s(config.ORIENT_FONT_SIZE)) - - with Serial(blocking=False): - with ButtonPress(): - Button(text=inst['skip_text'], right=self.exp.screen.width, - bottom=0, width=s(config.SKIP_SIZE[0]), - height=s(config.SKIP_SIZE[1]), blocking=False, - font_size=s(config.SKIP_FONT_SIZE)) - - Wait(1.0) - - Label(text=inst['done'], - halign='center', - center_x=self.exp.screen.center_x, - center_y=self.exp.screen.center_y, - font_size=s(config.INST_FONT_SIZE)) - with UntilDone(): - GetResponse(keys=config.CONT_KEY) \ No newline at end of file diff --git a/tasks/flanker/list_gen.py b/tasks/flanker/list_gen.py index a33683a..fe6855b 100644 --- a/tasks/flanker/list_gen.py +++ b/tasks/flanker/list_gen.py @@ -1,6 +1,5 @@ import random from math import cos, sin, sqrt, pi, radians -import config # list generation @@ -29,6 +28,3 @@ def gen_fblocks(config): random.shuffle(temp_block) flanker_blocks.append(temp_block) return flanker_blocks - -res = gen_fblocks(config) -print(res) diff --git a/tasks/flanker/main.py b/tasks/flanker/main.py index b38a15b..53e3f85 100644 --- a/tasks/flanker/main.py +++ b/tasks/flanker/main.py @@ -9,10 +9,10 @@ from smile.lsl import LSLPush from ..happy import HappyQuest import smile.ref as ref -from list_gen import gen_fblocks +from .list_gen import gen_fblocks from math import log -from trial_copy import Trial, GetResponse -from instruct_copy import Instruct +from .trial import Trial, GetResponse +from .instruct import Instruct #from . import version @@ -74,7 +74,7 @@ def FlankerExp(self, config, run_num=0, lang="E", pulse_server=None, # put up the fixation cross with Parallel(): - Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1, + Background = Image(source = config.BACKGROUND_IMAGE, size = (self.exp.screen.size[0] * 1.1, self.exp.screen.size[1] * 1.1), allow_stretch = True, keep_ratio = False) fix = Label(text='+', color=config.CROSS_COLOR, diff --git a/tasks/flanker/stim/create_folder.py b/tasks/flanker/stim/create_folder.py deleted file mode 100644 index 215df60..0000000 --- a/tasks/flanker/stim/create_folder.py +++ /dev/null @@ -1 +0,0 @@ -Initialize folder diff --git a/tasks/flanker/trial.py b/tasks/flanker/trial.py index 4246873..a4e014c 100644 --- a/tasks/flanker/trial.py +++ b/tasks/flanker/trial.py @@ -1,7 +1,7 @@ from smile.common import * from smile.scale import scale as s from smile.lsl import LSLPush -from widget import Flanker +from .flanker import Flanker @Subroutine @@ -42,23 +42,23 @@ def GetResponse(self, @Subroutine def Trial(self, config, - stim, + direct, center_x, center_y, condition, correct_resp=None, color='white', - pulse_server=None): + pulse_server=None, + background = True): self.eeg_pulse_time = None # present the dots - fl = Flanker(center_x=center_x, center_y=center_y, - box=s(config.CONFIG_BOX), around=s(config.CONFIG_AROUND), - line_width=s(config.LW), - stim=stim) + fl = Flanker(config, center_x= center_x, center_y = center_y, direction = direct, condition = condition, layers = config.LAYERS, + background = background) + with UntilDone(): # Collect key response - Wait(until=fl.appear_time) + Wait(until=fl.stim_appear_time) if config.EEG: pulse_fn = LSLPush(server=pulse_server, val=Ref.getitem(config.EEG_CODES, condition)) @@ -66,7 +66,7 @@ def Trial(self, start_time=pulse_fn.push_time) self.eeg_pulse_time = pulse_fn.push_time gr = GetResponse(correct_resp=correct_resp, - base_time=fl.appear_time['time'], + base_time=fl.stim_appear_time["time"], duration=config.RESPONSE_DURATION, keys=config.RESP_KEYS) @@ -76,5 +76,5 @@ def Trial(self, self.correct = gr.correct # save vars - self.appear_time = fl.appear_time - self.disappear_time = fl.disappear_time + self.appear_time = fl.stim_appear_time + self.disappear_time = fl.stim_disappear_time diff --git a/tasks/flanker/trial_copy.py b/tasks/flanker/trial_copy.py deleted file mode 100644 index 6e3a791..0000000 --- a/tasks/flanker/trial_copy.py +++ /dev/null @@ -1,98 +0,0 @@ -from smile.common import * -from smile.scale import scale as s -from smile.lsl import LSLPush -from flanker import Flanker -from list_gen import gen_fblocks -import config - - -@Subroutine -def GetResponse(self, - keys, - base_time=None, - correct_resp=None, - duration=None): - self.pressed = None - self.rt = None - self.correct = None - self.press_time = None - with Parallel(): - kp = KeyPress(base_time=base_time, - keys=keys, - correct_resp=correct_resp, - duration=duration, - blocking=False) - with Serial(blocking=False): - with ButtonPress(correct_resp=correct_resp, - base_time=base_time, - duration=duration, - ) as bp: - Button(width=self.exp.screen.width*.45, - height=self.exp.screen.height, - name=keys[0], text="", - left=0, bottom=0, background_color=(0, 0, 0, 0)) - Button(width=self.exp.screen.width*.45, height=self.exp.screen.height, - name=keys[-1], text="", right=self.exp.screen.width, - bottom=0, background_color=(0, 0, 0, 0)) - - self.pressed = Ref.cond((bp.pressed == ''), kp.pressed, bp.pressed) - self.rt = Ref.cond((bp.pressed == ''), kp.rt, bp.rt) - self.correct = Ref.cond((bp.pressed == ''), kp.correct, bp.correct) - self.press_time = Ref.cond((bp.pressed == ''), kp.press_time, bp.press_time) - - -@Subroutine -def Trial(self, - config, - direct, - center_x, - center_y, - condition, - correct_resp=None, - color='white', - pulse_server=None, - background = True): - - self.eeg_pulse_time = None - # present the dots - fl = Flanker(config, center_x= center_x, center_y = center_y, direction = direct, condition = condition, layers = config.LAYERS, - background = background) - - with UntilDone(): - # Collect key response - Wait(until=fl.stim_appear_time) - if config.EEG: - pulse_fn = LSLPush(server=pulse_server, - val=Ref.getitem(config.EEG_CODES, condition)) - Log(name="FLKR_PULSES", - start_time=pulse_fn.push_time) - self.eeg_pulse_time = pulse_fn.push_time - gr = GetResponse(correct_resp=correct_resp, - base_time=fl.stim_appear_time["time"], - duration=config.RESPONSE_DURATION, - keys=config.RESP_KEYS) - - self.pressed = gr.pressed - self.press_time = gr.press_time - self.rt = gr.rt - self.correct = gr.correct - - # save vars - self.appear_time = fl.stim_appear_time - self.disappear_time = fl.stim_disappear_time - -# blocks = gen_fblocks(config) -# print(blocks) - - -# exp = Experiment() -# blocks = Func(gen_fblocks,config) -# res = blocks.result -# with Loop(res) as block: -# with Loop(block.current) as trial: -# Trial(config, direct = trial.current["dir"], -# center_x=exp.screen.center_x + trial.current['loc_x']*s(config.FROM_CENTER), -# center_y=exp.screen.center_y + trial.current['loc_y']*s(config.FROM_CENTER), -# correct_resp=trial.current['corr_resp'], -# condition=trial.current['condition']) -# exp.run() \ No newline at end of file