Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v4
with:
version: "latest"

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --extra dev

- name: Lint
run: uv run ruff check src/ scripts/qa/

- name: Test
run: uv run pytest tests/ -q
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ private

# NFS hanging stuff
.nfs*

# Node
node_modules/
17 changes: 4 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ authors = [
]
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.9"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -34,26 +33,18 @@ dependencies = [
"nibabel>=3.0.0",
"nilearn>=0.6.0",
"scikit-learn>=0.22.0",
"jupyterlab>=3.0.0",
"ipywidgets>=7.5.0",
"h5py>=2.10.0",
"joblib>=1.0.0",
"pillow>=7.0.0",
"lxml>=4.5.0",
"ruff>=0.12.12",
"tqdm>=4.67.1",
"jinja2>=3.0.0",
"pyyaml>=6.0",
"pybids>=0.16.0",
"pycortex>=1.0.0",
"pytest>=8.4.2",
"pydeface>=2.0.2",
]

[project.optional-dependencies]
dev = [
"pytest>=6.0",
"ruff>=0.1.0",
"pytest>=8.4.2",
"ruff>=0.12.12",
]

[project.urls]
Expand All @@ -71,7 +62,7 @@ hyperface = ["assets/*.yaml", "templates/*.html"]

[tool.ruff]
line-length = 88
target-version = "py39"
target-version = "py310"
# Exclude archival code that should not be modified
exclude = [
"scripts/presentation/**", # Legacy Python 2 stimulus presentation code
Expand Down
10 changes: 7 additions & 3 deletions scripts/qa/print-tsnr-summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ def format_task_summary(task_stats: dict) -> str:
f" Number of subjects: {n_subjects}",
"",
" tSNR (temporal signal-to-noise ratio):",
f" Mean across subjects: {np.mean(mean_tsnrs):.1f} ± {np.std(mean_tsnrs):.1f}",
f" Mean across subjects: {np.mean(mean_tsnrs):.1f}"
f" ± {np.std(mean_tsnrs):.1f}",
f" Median across subjects: {np.median(mean_tsnrs):.1f}",
f" Min: {np.min(mean_tsnrs):.1f}",
f" Max: {np.max(mean_tsnrs):.1f}",
"",
" Paper-ready text:",
f" The mean tSNR across subjects was {np.mean(mean_tsnrs):.1f} ± {np.std(mean_tsnrs):.1f} "
f"(median {np.median(mean_tsnrs):.1f}, min {np.min(mean_tsnrs):.1f}, max {np.max(mean_tsnrs):.1f}).",
f" The mean tSNR across subjects was "
f"{np.mean(mean_tsnrs):.1f} ± {np.std(mean_tsnrs):.1f} "
f"(median {np.median(mean_tsnrs):.1f}, "
f"min {np.min(mean_tsnrs):.1f}, "
f"max {np.max(mean_tsnrs):.1f}).",
"",
]

Expand Down
9 changes: 5 additions & 4 deletions scripts/qa/qa-plot-accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def plot_accuracy_figure(

# Bar plot for mean accuracy
x_positions = np.arange(len(subjects))
bars = ax.bar(
ax.bar(
x_positions,
mean_accuracies,
color=PRIMARY_COLOR,
Expand All @@ -145,7 +145,7 @@ def plot_accuracy_figure(
)

# Scatter plot for individual run values
for i, (x_pos, values) in enumerate(zip(x_positions, all_run_values)):
for x_pos, values in zip(x_positions, all_run_values, strict=True):
jitter = np.random.uniform(-0.15, 0.15, len(values))
ax.scatter(
[x_pos + j for j in jitter],
Expand Down Expand Up @@ -205,7 +205,7 @@ def format_accuracy_summary(accuracy_data: dict[str, dict[str, int]]) -> str:
subject_means = []
perfect_subjects = 0

for subject, runs in accuracy_data.items():
for _subject, runs in accuracy_data.items():
values = list(runs.values())
all_values.extend(values)
subject_means.append(np.mean(values))
Expand Down Expand Up @@ -247,7 +247,8 @@ def format_accuracy_summary(accuracy_data: dict[str, dict[str, int]]) -> str:
"",
"Paper-ready text:",
f" Participants achieved a mean accuracy of {np.mean(subject_means):.1f}% "
f"(median {np.median(subject_means):.1f}%, min {np.min(subject_means):.1f}%, "
f"(median {np.median(subject_means):.1f}%, "
f"min {np.min(subject_means):.1f}%, "
f"max {np.max(subject_means):.1f}%) on the visual memory task. "
f"{perfect_subjects} out of {n_subjects} participants achieved "
f"100% accuracy across all runs.",
Expand Down
4 changes: 2 additions & 2 deletions scripts/qa/qa-plot-isc.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def print_summary_stats(isc_data: list[np.ndarray], subject_ids: list[str]) -> N
print(header)
print("-" * 60)

for subject_id, isc in zip(subject_ids, isc_data):
for subject_id, isc in zip(subject_ids, isc_data, strict=True):
valid = isc[np.isfinite(isc)]
vals = [valid.mean(), np.median(valid), valid.std(), valid.min(), valid.max()]
row = f"{subject_id:<15} " + " ".join(f"{v:>8.4f}" for v in vals)
Expand Down Expand Up @@ -173,7 +173,7 @@ def main():

# Create individual subject surface plots
print("\nCreating individual subject surface plots...")
for subject_id, isc in zip(subject_ids, isc_data):
for subject_id, isc in zip(subject_ids, isc_data, strict=True):
subject_path = figures_dir / f"{subject_id}_desc-isc_{plot_type}.png"
create_fsaverage6_plot(
isc,
Expand Down
2 changes: 1 addition & 1 deletion scripts/qa/qa-plot-motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def create_fd_violin_plots_by_session(
print(" Creating FD violin plots by session...")

session_data: dict[str | None, list[str]] = {}
for confounds_file, session in zip(confounds_files, sessions):
for confounds_file, session in zip(confounds_files, sessions, strict=True):
session_data.setdefault(session, []).append(confounds_file)

for session, session_files in session_data.items():
Expand Down
1 change: 0 additions & 1 deletion scripts/qa/qa-plot-participant-datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def main():

# Create binary matrix
n_participants = len(df)
datasets = ["hyperface", "budapest", "identity_decoding"]
matrix = np.zeros((n_participants, 3), dtype=int)

# All participants have hyperface
Expand Down
4 changes: 2 additions & 2 deletions scripts/qa/qa-save-isc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def load_and_process_subject(
events = load_events(subject, task="visualmemory", data_dir=data_dir)

processed_runs = []
for data, evt in zip(responses, events):
for data, evt in zip(responses, events, strict=True):
n_trs = data.shape[0]
clip_mask = get_clip_tr_mask(evt, n_trs, tr=tr)
data_clips = data[clip_mask]
Expand Down Expand Up @@ -111,7 +111,7 @@ def main():
n_trs_list = [d.shape[0] for d in subjects_data]
if len(set(n_trs_list)) > 1:
print(f"\nERROR: Inconsistent TR counts: {set(n_trs_list)}")
for subj_id, n_trs in zip(subject_ids, n_trs_list):
for subj_id, n_trs in zip(subject_ids, n_trs_list, strict=True):
print(f" {subj_id}: {n_trs}")
return 1

Expand Down
4 changes: 2 additions & 2 deletions scripts/qa/stimuli/plot-behavioral-ratings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def plot_factor_proportions(df, output_path):

total_n = len(df)

for ax, (factor, config) in zip(axes, FACTOR_CONFIG.items()):
for ax, (factor, config) in zip(axes, FACTOR_CONFIG.items(), strict=True):
# Get counts in specified order
counts = df[factor].value_counts()
order = [lvl for lvl in config["order"] if lvl in counts.index]
Expand All @@ -106,7 +106,7 @@ def plot_factor_proportions(df, output_path):
)

# Add percentage labels above bars
for i, (count, bar) in enumerate(zip(counts.values, bars)):
for count, bar in zip(counts.values, bars, strict=True):
pct = 100 * count / total_n
ax.text(
bar.get_x() + bar.get_width() / 2,
Expand Down
15 changes: 4 additions & 11 deletions src/hyperface/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,10 @@ def load_run_order_config() -> dict:
FileNotFoundError
If config file not found in package
"""
try:
# Python 3.9+
config_file = resources.files("hyperface.assets").joinpath(
"visualmemory_run_order.yaml"
)
config_text = config_file.read_text()
except AttributeError:
# Python 3.8 fallback
config_filename = "visualmemory_run_order.yaml"
with resources.open_text("hyperface.assets", config_filename) as f:
config_text = f.read()
config_file = resources.files("hyperface.assets").joinpath(
"visualmemory_run_order.yaml"
)
config_text = config_file.read_text()

return yaml.safe_load(config_text)

Expand Down
4 changes: 2 additions & 2 deletions src/hyperface/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def compute_tsnr(data: np.ndarray, confounds: pd.DataFrame) -> np.ndarray:
data : array of shape (dim1, dim2, dim3, n_volumes)
EPI data
confounds : pandas Dataframe
dataframe containing confounds generated by fmriprepp
dataframe containing confounds generated by fmriprep

Returns
------
Expand Down Expand Up @@ -90,7 +90,7 @@ def clean_data(data: np.ndarray, confounds: pd.DataFrame) -> np.ndarray:
data : array of shape (n_volumes, n_features)
flattened EPI data
confounds : pandas Dataframe
dataframe containing confounds generated by fmriprepp
dataframe containing confounds generated by fmriprep

Returns
-------
Expand Down
Loading
Loading