Skip to content
Open
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
19 changes: 19 additions & 0 deletions .direnv/bin/nix-direnv-reload
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
if [[ ! -d "/home/zak/work/hbc/boost/beh" ]]; then
echo "Cannot find source directory; Did you move it?"
echo "(Looking for "/home/zak/work/hbc/boost/beh")"
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
exit 1
fi

# rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/home/zak/work/hbc/boost/beh" true

# Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building.
touch "/home/zak/work/hbc/boost/beh/.envrc"

# Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date.
touch -r "/home/zak/work/hbc/boost/beh/.envrc" "/home/zak/work/hbc/boost/beh/.direnv"/*.rc
2,045 changes: 2,045 additions & 0 deletions .direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.venv
.direnv
1 change: 1 addition & 0 deletions code/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# code package
Binary file modified code/data_processing/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file modified code/data_processing/__pycache__/cc_qc.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified code/data_processing/__pycache__/pull_handler.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file modified code/data_processing/__pycache__/utils.cpython-313.pyc
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions code/data_processing/cc_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def cc_qc(self, df, threshold, TS=False):
CATEGORY = 3
print("Found unreported condition, category set to 3 ")

return CATEGORY

# Return both the QC category and the accuracy-by-condition dictionary
return CATEGORY, accuracy


2 changes: 1 addition & 1 deletion code/data_processing/mem_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def fn_sm_qc(self, df, threshold):
CATEGORY = 3
print("Found unreported condition, category set to 3 ")

return CATEGORY
return CATEGORY, accuracy



Expand Down
26 changes: 1 addition & 25 deletions code/data_processing/ps_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,6 @@ def ps_qc(self, submission, threshold, DSST=False):
CATEGORY = 3
print("Found unreported condition, category set to 3 ")

return CATEGORY
























return CATEGORY, accuracy


171 changes: 143 additions & 28 deletions code/main_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from data_processing.plot_utils import CC_PLOTS, MEM_PLOTS, PS_PLOTS
from data_processing.save_utils import SAVE_EVERYTHING
import pandas as pd
from pathlib import Path


class Handler:
Expand All @@ -28,6 +29,7 @@ def __init__(self):
"WL": [958, 972, 995, 910, 927, 944]
}

self.master_acc = pd.DataFrame(columns=['task', 'subject_id', 'session', 'condition', 'accuracy'])

def pull(self, task):
pull_instance = Pull(
Expand Down Expand Up @@ -85,27 +87,76 @@ def qc_cc_dfs(self, dfs, task):
categories.append([subject, category, df])
plots.append([subject, plot])

else:
qc_instance = CCqC(task,
MAXRT=1800,
RT_COLUMN_NAME='response_time',
ACC_COLUMN_NAME='correct',
CORRECT_SYMBOL=1,
INCORRECT_SYMBOL=0,
COND_COLUMN_NAME='block_cond')
for df in dfs:
subject = df['subject_id'][1]
print(f"qcing {subject}")
categories, plots, master_rows = [], [], []
plot_instance = CC_PLOTS()

# pick the grouping column for accuracy
cond_col = "condition" if task in ["AF", "NF", "NNB", "VNB"] else "block_cond"

qc_instance = CCqC(
task,
MAXRT=1800,
RT_COLUMN_NAME="response_time",
ACC_COLUMN_NAME="correct",
CORRECT_SYMBOL=1,
INCORRECT_SYMBOL=0,
COND_COLUMN_NAME=cond_col,
)

for df in dfs:
subject = df["subject_id"].iloc[0]
# preserve session information from available column
if "session" in df.columns:
session = df["session"].iloc[0]
elif "session_number" in df.columns:
session = df["session_number"].iloc[0]
else:
session = None

# run QC + choose plot
if task in ["AF", "NF"]:
category, _ = qc_instance.cc_qc(df, threshold=0.5)
plot = plot_instance.af_nf_plot(df)
elif task in ["NNB", "VNB"]:
category, _ = qc_instance.cc_qc(df, threshold=0.5)
plot = plot_instance.nnb_vnb_plot(df)
else:
category = qc_instance.cc_qc(df, threshold=0.5, TS=True)
plot = plot_instance.ats_nts_plot(df)
print(f"Category = {category}")
categories.append([subject, category, df])
plots.append([subject, plot])

categories.append([subject, category, df])
plots.append([subject, plot])

# compute accuracies per block/condition for THIS df
from data_processing.utils import QC_UTILS
qc_util = QC_UTILS()
acc_by = qc_util.get_acc_by_block_cond(
df, block_cond_column_name=cond_col,
acc_column_name="correct",
correct_symbol=1,
incorrect_symbol=0,
)
for cond, acc in acc_by.items():
master_rows.append([task, subject, session, cond, float(acc)])

# save artifacts
save_instance = SAVE_EVERYTHING()
save_instance.save_dfs(categories=categories,
task=task)
save_instance.save_plots(plots=plots,
task=task)
save_instance.save_dfs(categories=categories, task=task)
save_instance.save_plots(plots=plots, task=task)

# append to master table
if master_rows:
self.master_acc = pd.concat(
[self.master_acc,
pd.DataFrame(master_rows,
columns=["task", "subject_id", "session", "condition", "accuracy"])],
ignore_index=True,
)

# save aggregated master accuracy to meta_file.csv at project base directory
base_dir = Path(__file__).parents[1]
self.master_acc.to_csv(base_dir / "meta_file.csv", index=False)

return categories, plots


Expand Down Expand Up @@ -139,10 +190,42 @@ def qc_ps_dfs(self, dfs, task):
plots.append([subject, plot])

save_instance = SAVE_EVERYTHING()
save_instance.save_dfs(categories=categories,
task=task)
save_instance.save_plots(plots=plots,
task=task)
save_instance.save_dfs(categories=categories, task=task)
save_instance.save_plots(plots=plots, task=task)

# append accuracies by block/condition to master_acc
master_rows = []
from data_processing.utils import QC_UTILS
qc_util = QC_UTILS()
cond_col = 'block_c'
for subject, _, df in categories:
# preserve session information from available column
if 'session' in df.columns:
session = df['session'].iloc[0]
elif 'session_number' in df.columns:
session = df['session_number'].iloc[0]
else:
session = None
acc_by = qc_util.get_acc_by_block_cond(
df,
block_cond_column_name=cond_col,
acc_column_name='correct',
correct_symbol=1,
incorrect_symbol=0,
)
for cond, acc in acc_by.items():
master_rows.append([task, subject, session, cond, float(acc)])
if master_rows:
self.master_acc = pd.concat(
[self.master_acc,
pd.DataFrame(master_rows,
columns=['task','subject_id','session','condition','accuracy'])],
ignore_index=True,
)

# save aggregated master accuracy to meta_file.csv at project base directory
base_dir = Path(__file__).parents[1]
self.master_acc.to_csv(base_dir / "meta_file.csv", index=False)

return categories, plots

Expand Down Expand Up @@ -172,10 +255,43 @@ def qc_mem_dfs(self, dfs, task):
categories.append([subject, category, df])
plots.append([subject, plot])
save_instance = SAVE_EVERYTHING()
save_instance.save_dfs(categories=categories,
task=task)
save_instance.save_plots(plots=plots,
task=task)
save_instance.save_dfs(categories=categories, task=task)
save_instance.save_plots(plots=plots, task=task)

# append accuracies by block/condition to master_acc
master_rows = []
from data_processing.utils import QC_UTILS
qc_util = QC_UTILS()
cond_col = 'block_c'
for subject, _, df in categories:
# preserve session information from available column
if 'session' in df.columns:
session = df['session'].iloc[0]
elif 'session_number' in df.columns:
session = df['session_number'].iloc[0]
else:
session = None
acc_by = qc_util.get_acc_by_block_cond(
df,
block_cond_column_name=cond_col,
acc_column_name='correct',
correct_symbol=1,
incorrect_symbol=0,
)
for cond, acc in acc_by.items():
master_rows.append([task, subject, session, cond, float(acc)])
if master_rows:
self.master_acc = pd.concat(
[self.master_acc,
pd.DataFrame(master_rows,
columns=['task','subject_id','session','condition','accuracy'])],
ignore_index=True,
)

# save aggregated master accuracy to meta_file.csv at project base directory
base_dir = Path(__file__).parents[1]
self.master_acc.to_csv(base_dir / "meta_file.csv", index=False)

return categories, plots

def qc_wl_dfs(self, dfs, task):
Expand Down Expand Up @@ -211,6 +327,7 @@ def qc_wl_dfs(self, dfs, task):
task=task)
return categories, plots

# mysql 10.6.22

if __name__ == '__main__':
import os
Expand All @@ -224,5 +341,3 @@ def qc_wl_dfs(self, dfs, task):
elif sys.argv[1] in task_list:
instance = Handler()
csv_dfs = instance.pull(task=sys.argv[1])


Loading