Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 13, 2025
1 parent d9112fc commit b39f494
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 150 deletions.
8 changes: 4 additions & 4 deletions doc/git_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
legend = "".join(legend.split("\n"))

nodes = dict(
upstream="LABSN/expyfun\n" "master\n" " ",
maint="Eric89GXL/expyfun\n" "master\n" "other_branch",
dev="rkmaddox/expyfun\n" "master\n" "fix_branch",
upstream="LABSN/expyfun\nmaster\n ",
maint="Eric89GXL/expyfun\nmaster\nother_branch",
dev="rkmaddox/expyfun\nmaster\nfix_branch",
maint_clone="/home/larsoner/expyfun\n"
"master (origin/master)\n"
"other_branch (origin/other_branch)\n"
Expand All @@ -31,7 +31,7 @@
"master (origin/master)\n"
"fix_branch (origin/fix_branch)\n"
" ",
user_clone="/home/akclee/expyfun\n" "master (origin/master)\n" " \n" " ",
user_clone="/home/akclee/expyfun\nmaster (origin/master)\n \n ",
legend=legend,
)

Expand Down
28 changes: 11 additions & 17 deletions examples/experiments/keypress.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
###############
# screen_prompt
pressed = ec.screen_prompt(
"press any key\n\nscreen_prompt(" f"max_wait={wait_dur})",
f"press any key\n\nscreen_prompt(max_wait={wait_dur})",
max_wait=wait_dur,
timestamp=True,
)
Expand All @@ -51,7 +51,7 @@

##################
# wait_for_presses
ec.screen_text(f"press some keys\n\nwait_for_presses(max_wait={wait_dur})" "")
ec.screen_text(f"press some keys\n\nwait_for_presses(max_wait={wait_dur})")
screenshot = ec.screenshot()
ec.flip()
pressed = ec.wait_for_presses(wait_dur)
Expand All @@ -60,7 +60,7 @@
message = "no keys pressed"
else:
message = [
f"{key} pressed after {round(time, 4)} secs\n" "" for key, time in pressed
f"{key} pressed after {round(time, 4)} secs\n" for key, time in pressed
]
message = "".join(message)
ec.screen_prompt(message, msg_dur)
Expand All @@ -69,25 +69,23 @@
############################################
# wait_for_presses, relative to master clock
ec.screen_text(
f"press some keys\n\nwait_for_presses(max_wait={wait_dur}, " "relative_to=0.0)"
f"press some keys\n\nwait_for_presses(max_wait={wait_dur}, relative_to=0.0)"
)
ec.flip()
pressed = ec.wait_for_presses(wait_dur, relative_to=0.0)
ec.write_data_line("wait_for_presses relative_to 0.0", pressed)
if not len(pressed):
message = "no keys pressed"
else:
message = [
f"{key} pressed at {round(time, 4)} secs\n" "" for key, time in pressed
]
message = [f"{key} pressed at {round(time, 4)} secs\n" for key, time in pressed]
message = "".join(message)
ec.screen_prompt(message, msg_dur)
ec.wait_secs(isi)

##########################################
# listen_presses / wait_secs / get_presses
ec.screen_text(
f"press some keys\n\nlisten_presses()\nwait_secs({wait_dur})" "\nget_presses()"
f"press some keys\n\nlisten_presses()\nwait_secs({wait_dur})\nget_presses()"
)
ec.flip()
ec.listen_presses()
Expand All @@ -98,7 +96,7 @@
message = "no keys pressed"
else:
message = [
f"{key} pressed after {round(time, 4)} secs\n" "" for key, time in pressed
f"{key} pressed after {round(time, 4)} secs\n" for key, time in pressed
]
message = "".join(message)
ec.screen_prompt(message, msg_dur)
Expand All @@ -119,9 +117,7 @@
if not len(pressed):
message = "no keys pressed"
else:
message = [
f"{key} pressed at {round(time, 4)} secs\n" "" for key, time in pressed
]
message = [f"{key} pressed at {round(time, 4)} secs\n" for key, time in pressed]
message = "".join(message)
ec.screen_prompt(message, msg_dur)
ec.wait_secs(isi)
Expand All @@ -132,7 +128,7 @@
countdown = ec.current_time + disp_time
ec.call_on_next_flip(ec.listen_presses)
ec.screen_text(
"press some keys\n\nlisten_presses()" f"\nwhile loop {disp_time}\nget_presses()"
f"press some keys\n\nlisten_presses()\nwhile loop {disp_time}\nget_presses()"
)
ec.flip()
while ec.current_time < countdown:
Expand All @@ -151,7 +147,7 @@
message = "no keys pressed"
else:
message = [
f"{key} pressed after {round(time, 4)} secs\n" "" for key, time in pressed
f"{key} pressed after {round(time, 4)} secs\n" for key, time in pressed
]
message = "".join(message)
ec.screen_prompt(message, msg_dur)
Expand Down Expand Up @@ -183,9 +179,7 @@
if not len(pressed):
message = "no keys pressed"
else:
message = [
f"{key} pressed at {round(time, 4)} secs\n" "" for key, time in pressed
]
message = [f"{key} pressed at {round(time, 4)} secs\n" for key, time in pressed]
message = "".join(message)
ec.screen_prompt(message, msg_dur)

Expand Down
2 changes: 1 addition & 1 deletion examples/experiments/keyrelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
if not len(events):
message = "no keys pressed"
else:
message = [f"{k} {r} after {round(t, 4)} secs\n" "" for k, t, r in events]
message = [f"{k} {r} after {round(t, 4)} secs\n" for k, t, r in events]
message = "".join(message)
ec.screen_prompt(message, msg_dur)
ec.wait_secs(isi)
Expand Down
4 changes: 2 additions & 2 deletions examples/experiments/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
pb = ProgressBar(ec, [0, -0.1, 1.5, 0.1], units="norm")

ec.screen_prompt(
"Press the number shown on the screen. Start by pressing" " 1.",
"Press the number shown on the screen. Start by pressing 1.",
font_size=16,
live_keys=[1],
max_wait=max_wait,
Expand All @@ -51,7 +51,7 @@
pb.update_bar(percent)
# display the progress bar with some text
ec.screen_text(
f"You've completed {percent} %. Press any key to proceed." "",
f"You've completed {percent} %. Press any key to proceed.",
[0, 0.1],
wrap=False,
font_size=16,
Expand Down
8 changes: 3 additions & 5 deletions examples/simple_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,9 @@
message = "Too slow!"
elif int(pressed) == stim_num + 1:
running_total += 1
message = "Correct! Your reaction time was " f"{round(timestamp, 3)}"
message = f"Correct! Your reaction time was {round(timestamp, 3)}"
else:
message = (
f"You pressed {pressed}, the correct answer was " f"{stim_num + 1}."
)
message = f"You pressed {pressed}, the correct answer was {stim_num + 1}."
ec.screen_prompt(message, max_wait=feedback_dur)
ec.wait_secs(isi)

Expand Down Expand Up @@ -184,7 +182,7 @@
running_total += sum(correct)
ec.call_on_next_flip(ec.stop_noise())
ec.screen_prompt(
f"You got {sum(correct)} out of {len(answers)} correct." "",
f"You got {sum(correct)} out of {len(answers)} correct.",
max_wait=feedback_dur,
)
ec.trial_ok()
Expand Down
4 changes: 2 additions & 2 deletions examples/stimuli/crm_stimuli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
)

# print the valid callsigns
print(f'Valid callsigns are {crm_info()["callsign"]}')
print(f"Valid callsigns are {crm_info()['callsign']}")

# read a sentence in from the hard drive
x1 = 0.5 * crm_sentence(fs, "m", "0", "c", "r", "5", path=crm_path)
Expand All @@ -79,7 +79,7 @@
stim_fs=40000,
) as ec:
ec.screen_text(
"Report the color and number spoken by the female " "talker.", wrap=True
"Report the color and number spoken by the female talker.", wrap=True
)
screenshot = ec.screenshot()
ec.flip()
Expand Down
44 changes: 20 additions & 24 deletions expyfun/_experiment_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def __init__(
and value is not None
and not isinstance(value, str)
):
raise TypeError(f"{value} must be string or None" "")
raise TypeError(f"{value} must be string or None")
if key in edit_list and value is None:
self._exp_info[key] = get_keyboard_input(f"{key}: ")
else:
Expand All @@ -272,7 +272,7 @@ def __init__(
os.mkdir(output_dir)
basename = op.join(
output_dir,
"{}_{}" "".format(
"{}_{}".format(
self._exp_info["participant"], self._exp_info["date"]
),
)
Expand All @@ -298,8 +298,7 @@ def __init__(
safe_flipping = not (get_config("SAFE_FLIPPING", "").lower() == "false")
if not safe_flipping:
logger.warning(
"Expyfun: Unsafe flipping mode enabled, flip "
"timing not guaranteed"
"Expyfun: Unsafe flipping mode enabled, flip timing not guaranteed"
)
self.safe_flipping = safe_flipping

Expand All @@ -323,7 +322,7 @@ def __init__(
req_mon_keys = ["SCREEN_WIDTH", "SCREEN_DISTANCE", "SCREEN_SIZE_PIX"]
missing_keys = [key for key in req_mon_keys if key not in monitor]
if missing_keys:
raise KeyError(f"monitor is missing required keys {missing_keys}" "")
raise KeyError(f"monitor is missing required keys {missing_keys}")
mon_size = monitor["SCREEN_SIZE_PIX"]
monitor["SCREEN_DPI"] = monitor["SCREEN_SIZE_PIX"][0] / (
monitor["SCREEN_WIDTH"] * 0.393701
Expand Down Expand Up @@ -365,7 +364,7 @@ def __init__(
response_device = get_config("RESPONSE_DEVICE", "keyboard")
if response_device not in ["keyboard", "tdt", "cedrus"]:
raise ValueError(
'response_device must be "keyboard", "tdt", ' '"cedrus", or None'
'response_device must be "keyboard", "tdt", "cedrus", or None'
)
self._response_device = response_device

Expand Down Expand Up @@ -447,7 +446,7 @@ def __init__(
window_size = [int(w) for w in window_size]
window_size = np.array(window_size)
if window_size.ndim != 1 or window_size.size != 2:
raise ValueError("window_size must be 2-element array-like or " "None")
raise ValueError("window_size must be 2-element array-like or None")

# open window and setup GL config
self._setup_window(window_size, exp_name, full_screen, screen)
Expand All @@ -458,7 +457,7 @@ def __init__(
elif response_device == "tdt":
if not isinstance(self._ac, TDTController):
raise ValueError(
'response_device can only be "tdt" if ' "tdt is used for audio"
'response_device can only be "tdt" if tdt is used for audio'
)
self._response_handler = self._ac
self._ac._add_keyboard_init(self, force_quit)
Expand Down Expand Up @@ -489,13 +488,12 @@ def __init__(
f"{known_keys}, got {set(trigger_controller)}"
)
logger.info(
f'Expyfun: Initializing {trigger_controller["TYPE"]} ' 'triggering mode'
f"Expyfun: Initializing {trigger_controller['TYPE']} triggering mode"
)
if trigger_controller["TYPE"] == "tdt":
if not isinstance(self._ac, TDTController):
raise ValueError(
'trigger_controller can only be "tdt" if '
"tdt is used for audio"
'trigger_controller can only be "tdt" if tdt is used for audio'
)
self._tc = self._ac
elif trigger_controller["TYPE"] == "sound_card":
Expand Down Expand Up @@ -543,9 +541,9 @@ def __init__(
# finish initialization
logger.info("Expyfun: Initialization complete")
logger.exp(
"Expyfun: Participant: {0}" "".format(self._exp_info["participant"])
"Expyfun: Participant: {0}".format(self._exp_info["participant"])
)
logger.exp("Expyfun: Session: {0}" "".format(self._exp_info["session"]))
logger.exp("Expyfun: Session: {0}".format(self._exp_info["session"]))
ok_log = partial(self.write_data_line, "trial_ok", None)
self._on_trial_ok.append(ok_log)
self._on_trial_ok.append(self.flush)
Expand All @@ -558,7 +556,7 @@ def __init__(

def __repr__(self):
"""Return a useful string representation of the experiment"""
string = '<ExperimentController ({3}): "{0}" {1} ({2})>' "".format(
string = '<ExperimentController ({3}): "{0}" {1} ({2})>'.format(
self._exp_info["exp_name"],
self._exp_info["participant"],
self._exp_info["session"],
Expand Down Expand Up @@ -792,9 +790,7 @@ def start_stimulus(self, start_of_trial=True, flip=True, when=None):
"""
if start_of_trial:
if self._trial_progress != "identified":
raise RuntimeError(
"Trial ID must be stamped before starting " "the trial"
)
raise RuntimeError("Trial ID must be stamped before starting the trial")
self._trial_progress = "started"
extra = "flipping screen and " if flip else ""
logger.exp(f"Expyfun: Starting stimuli: {extra}playing audio")
Expand Down Expand Up @@ -1392,7 +1388,7 @@ def check_force_quit(self):
def text_input(
self,
stop_key="return",
instruction_string="Type" " response below",
instruction_string="Type response below",
pos=(0, 0),
color="white",
font_name="Arial",
Expand Down Expand Up @@ -1863,12 +1859,12 @@ def load_buffer(self, samples):
"""
if self._playing:
raise RuntimeError(
"Previous audio must be stopped before loading " "the buffer"
"Previous audio must be stopped before loading the buffer"
)
samples = self._validate_audio(samples)
if not np.isclose(self._stim_scaler, 1.0):
samples = samples * self._stim_scaler
logger.exp(f"Expyfun: Loading {samples.size} samples to buffer" "")
logger.exp(f"Expyfun: Loading {samples.size} samples to buffer")
self._ac.load_buffer(samples)

def play(self):
Expand Down Expand Up @@ -1997,7 +1993,7 @@ def _validate_audio(self, samples):
max_samples = 4000000 - 1
if samples.shape[0] > max_samples:
raise RuntimeError(
f"Sample too long {samples.shape[0]} > {max_samples}" ""
f"Sample too long {samples.shape[0]} > {max_samples}"
)

# resample if needed
Expand Down Expand Up @@ -2066,7 +2062,7 @@ def set_rms_checking(self, check_rms):
"""
if check_rms not in [None, "wholefile", "windowed"]:
raise ValueError(
'check_rms must be one of "wholefile", "windowed"' ", or None."
'check_rms must be one of "wholefile", "windowed", or None.'
)
self._slow_rms_warned = False
self._check_rms = check_rms
Expand Down Expand Up @@ -2235,7 +2231,7 @@ def identify_trial(self, **ids):
)
ll = max([len(key) for key in ids.keys()])
for key, id_ in ids.items():
logger.exp(f"Expyfun: Stamp trial ID to {key.ljust(ll)} : {str(id_)}" "")
logger.exp(f"Expyfun: Stamp trial ID to {key.ljust(ll)} : {str(id_)}")
if isinstance(id_, dict):
self._id_call_dict[key](**id_)
else:
Expand Down Expand Up @@ -2318,7 +2314,7 @@ def stamp_triggers(self, ids, check="binary", wait_for_last=True):
_vals = [1, 2, 4, 8]
if not all(id_ in _vals for id_ in ids):
raise ValueError(
'with check="binary", ids must all be ' f"1, 2, 4, or 8: {ids}"
f'with check="binary", ids must all be 1, 2, 4, or 8: {ids}'
)
self._stamp_ttl_triggers(ids, wait_for_last, False)

Expand Down
Loading

0 comments on commit b39f494

Please sign in to comment.