Skip to content

Commit

Permalink
Refactors visual updates to work when running from outermost main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dyld-w committed Oct 31, 2024
1 parent a853c2f commit ba549e6
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 576 deletions.
10 changes: 9 additions & 1 deletion tasks/RDM/config.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions tasks/RDM/instruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tasks/RDM/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down
17 changes: 5 additions & 12 deletions tasks/RDM/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
45 changes: 12 additions & 33 deletions tasks/flanker/config.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.]
Expand Down
42 changes: 19 additions & 23 deletions tasks/flanker/flanker.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Loading

0 comments on commit ba549e6

Please sign in to comment.