Created
January 14, 2021 20:06
-
-
Save christian-oreilly/ac4772561891724cb727dde0801b405e to your computer and use it in GitHub Desktop.
Tabulating_eegip_events_washington.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import mne | |
import pandas as pd | |
from pathlib import Path | |
root = Path("/home/oreillyc/projects/def-emayada/eegip/washington/derivatives/lossless/") | |
results = {"subjects": [], | |
"ages": []} | |
for age in ["06", "12", "18"]: | |
for path in root.glob(f"sub-s*/ses-m{age}/eeg/sub-s*_ses-m{age}_*_eeg_qcr.set"): | |
print(path) | |
results["subjects"].append(str(path)[-35:-32]) | |
results["ages"].append(age) | |
raw = mne.io.read_raw_eeglab(path) | |
event_names, counts = np.unique([annot["description"] for annot in raw.annotations], return_counts=True) | |
event_counts = dict(list(zip(event_names, counts))) | |
for event_name in event_names: | |
if event_name not in results: | |
if len(results["ages"]) == 1: | |
results[event_name] = [] | |
else: | |
results[event_name] = [0]*(len(results["ages"])-1) | |
for event_name in results: | |
if event_name in ["ages", "subjects"]: | |
continue | |
if event_name in event_counts: | |
results[event_name].append(event_counts[event_name]) | |
else: | |
results[event_name].append(0) | |
pd.DataFrame(results).sort_values(["ages", "subjects"]).to_csv("event_counts_washington.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment