Skip to content

Commit ba549e6

Browse files
committed
Refactors visual updates to work when running from outermost main.py
1 parent a853c2f commit ba549e6

File tree

13 files changed

+172
-576
lines changed

13 files changed

+172
-576
lines changed

tasks/RDM/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
# config
1+
2+
from pathlib import Path
3+
4+
# Define the base directory as the directory containing the current file
5+
BASE_DIR = Path(__file__).resolve().parent
6+
7+
# Background image path
8+
BACKGROUND_IMAGE = str(BASE_DIR / "NIGHT_SKY.png")
9+
210
NUM_BLOCKS = 1
311
NUM_DOTS = 100
412

tasks/RDM/instruct.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from smile.common import *
44
from smile.scale import scale as s
55

6-
from trial import Trial, GetResponse
7-
from list_gen import gen_practice_trials
6+
from .trial import Trial, GetResponse
7+
from .list_gen import gen_practice_trials
88

99

1010
# Text for instructions
@@ -168,7 +168,7 @@ def Instruct(self, config, lang="E", practice=False):
168168
with Loop(self.md_blocks) as block:
169169
with Parallel():
170170
# put up the fixation cross
171-
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)
171+
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)
172172
Border= Ellipse(size = (s((config.RADIUS)*1.2*2),(s((config.RADIUS)*1.2*2))), color = (.55,.55,.55,1))
173173
Telescope = Ellipse(size = (s((config.RADIUS)*1.1*2),(s((config.RADIUS)*1.1*2))), color = (.35, .35, .35, 1.0))
174174
cross = Label(text='+', color=config.CROSS_COLOR,

tasks/RDM/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from ..happy import HappyQuest
1010

1111

12-
from list_gen import gen_moving_dot_trials
12+
from .list_gen import gen_moving_dot_trials
1313
from math import log
14-
from trial import Trial, GetResponse
15-
from instruct import Instruct
14+
from .trial import Trial, GetResponse
15+
from .instruct import Instruct
1616
# from . import version
1717

1818

@@ -88,7 +88,7 @@ def RDMExp(self, config, run_num=0, lang="E", pulse_server=None, practice=False,
8888
with Loop(self.md_blocks) as block:
8989
with Parallel():
9090
# put up the fixation cross
91-
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)
91+
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)
9292
Border= Ellipse(size = (s((config.RADIUS)*1.2*2),(s((config.RADIUS)*1.2*2))), color = (.55,.55,.55,1))
9393
Telescope = Ellipse(size = (s((config.RADIUS)*1.1*2),(s((config.RADIUS)*1.1*2))), color = (.35, .35, .35, 1.0))
9494
cross = Label(text='+', color=config.CROSS_COLOR,

tasks/RDM/trial.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,15 @@ def Trial(self,
5555
self.eeg_pulse_time = None
5656

5757
with Parallel():
58-
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)
59-
Border = Ellipse(color = (1,1,1,0))
60-
Telescope = Ellipse(color = (1,1,1,0))
58+
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)
59+
border = Ellipse(color = (1,1,1,0))
60+
telescope = Ellipse(color = (1,1,1,0))
6161
with UntilDone():
6262

6363
with Serial():
64-
# with Parallel():
65-
# 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)
66-
# Border = Ellipse(color = (1,1,1,0))
67-
# Telescope = Ellipse(color = (1,1,1,0))
6864
# present the dots
6965
with Parallel():
7066
cross.update(color=(.35, .35, .35, 1.0))
71-
# 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)
72-
# Border = Ellipse(color = (1,1,1,0))
73-
# Telescope = Ellipse(color = (1,1,1,0))
7467
md = MovingDots(color=color, scale=s(config.SCALE),
7568
num_dots=num_dots, radius=s(config.RADIUS),
7669
motion_props=[{"coherence": right_coherence,
@@ -82,8 +75,8 @@ def Trial(self,
8275
lifespan=config.LIFESPAN,
8376
lifespan_variance=config.LIFESPAN_VAR,
8477
speed=s(config.SPEED))
85-
Border.update(center = md.center, size = (md.width*1.2, md.height*1.2), color = (.55,.55,.55,1))
86-
Telescope.update(center = md.center, size = (md.width*1.1, md.height*1.1), color = (.35, .35, .35, 1.0))
78+
border.update(center = md.center, size = (md.width*1.2, md.height*1.2), color = (.55,.55,.55,1))
79+
telescope.update(center = md.center, size = (md.width*1.1, md.height*1.1), color = (.35, .35, .35, 1.0))
8780
with UntilDone():
8881
# Collect key response
8982
Wait(until=md.appear_time)

tasks/flanker/config.py

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
#from numpy import linspace
1+
from pathlib import Path
2+
3+
# Define the base directory as the directory containing the current file
4+
BASE_DIR = Path(__file__).resolve().parent
5+
6+
# Use BASE_DIR / "stim" / "fish_" to define the STIM_DIRECTORY path
7+
STIM_DIRECTORY = str(BASE_DIR / "stim" / "fish_")
8+
9+
# Background image path
10+
BACKGROUND_IMAGE = str(BASE_DIR / "ocean_background.png")
11+
212
# FLANKER VARIABLES
313
NUM_TRIALS = 1 # (len(evidence_conditions)-1) * 4 + 2 * num_trials
414
NUM_BLOCKS = 1
@@ -33,38 +43,7 @@
3343
"dir": "left"},
3444

3545
]
36-
# uNCOMMENT THIS LINE FOR EXTRA CONDITIONS
37-
# CONDITIONS = [{"stim": "__>__\n" +
38-
# "_<><_\n" +
39-
# "<<><<\n" +
40-
# "_<><_\n" +
41-
# "__>__\n",
42-
# "condition": "|",
43-
# "dir": "R"},
44-
# {"stim": "__<__\n" +
45-
# "_<<<_\n" +
46-
# ">>>>>\n" +
47-
# "_<<<_\n" +
48-
# "__<__\n",
49-
# "condition": "--",
50-
# "dir": "R"},
51-
# {"stim": "__<__\n" +
52-
# "_><>_\n" +
53-
# ">><>>\n" +
54-
# "_><>_\n" +
55-
# "__<__\n",
56-
# "condition": "|",
57-
# "dir": "L"},
58-
# {"stim": "__>__\n" +
59-
# "_>>>_\n" +
60-
# "<<<<<\n" +
61-
# "_>>>_\n" +
62-
# "__>__\n",
63-
# "condition": "--",
64-
# "dir": "L"},
65-
# ]
66-
67-
STIM_DIRECTORY = "./stim/fish_"
46+
6847
#EVIDENCE_CONDITIONS = [0., 45.]
6948
NUM_LOCS = 8
7049
DEF_SAT = [255.,255.,255.]

tasks/flanker/flanker.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
from smile.common import *
22
from smile.scale import scale as s
3-
import config as config
4-
from list_gen import gen_fblocks
53

6-
from smile.common import *
7-
from smile.scale import scale as s
8-
import config as config
9-
from list_gen import gen_fblocks
104

115
@Subroutine
126
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_
2721

2822
with Parallel():
2923
with Parallel():
30-
Background = Image(source = "ocean_background.png", size = (self.exp.screen.size[0] * 1.1,
24+
background_image = Image(source = config.BACKGROUND_IMAGE, size = (self.exp.screen.size[0] * 1.1,
3125
self.exp.screen.size[1] * 1.1),
3226
allow_stretch = True, keep_ratio = False)
3327
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_
6963
center = (add_left.center_x, add_left.center_y - s(50*(mult+1))))
7064
self.layer = self.layer + 1
7165
with If(background == False):
72-
Background.update(color = (1,1,1,0))
66+
background_image.update(color = (1,1,1,0))
7367
with Serial():
7468
Wait(until=center_image.appear_time)
7569
self.stim_appear_time = center_image.appear_time
7670
# self.stim_disappear_time = center_image.disappear_time
7771

7872

79-
# blocks = gen_fblocks(config)
80-
# exp = Experiment()
81-
# with Loop(blocks) as block:
82-
# with Loop(block.current) as trial:
83-
# fl = Flanker(config,
84-
# center_x = exp.screen.center_x + trial.current['loc_x']*s(config.FROM_CENTER),
85-
# center_y = exp.screen.center_y + trial.current['loc_y']*s(config.FROM_CENTER),
86-
# direction = trial.current["dir"],
87-
# condition = trial.current['condition'],
88-
# layers = config.LAYERS)
89-
# with UntilDone():
90-
# Wait(until=fl.stim_appear_time)
91-
# Wait(3)
92-
# exp.run()
93-
73+
if __name__ == "__main__":
74+
import config as config
75+
from list_gen import gen_fblocks
76+
blocks = gen_fblocks(config)
77+
exp = Experiment()
78+
with Loop(blocks) as block:
79+
with Loop(block.current) as trial:
80+
fl = Flanker(config,
81+
center_x = exp.screen.center_x + trial.current['loc_x']*s(config.FROM_CENTER),
82+
center_y = exp.screen.center_y + trial.current['loc_y']*s(config.FROM_CENTER),
83+
direction = trial.current["dir"],
84+
condition = trial.current['condition'],
85+
layers = config.LAYERS)
86+
with UntilDone():
87+
Wait(until=fl.stim_appear_time)
88+
Wait(3)
89+
exp.run()

0 commit comments

Comments
 (0)