import mne
import os
from ieeg.viz.mri import plot_subj, subject_to_info, plot_on_average, get_sub_dir
from ieeg.io import raw_from_layout, get_data
from misc_functions import load_sig_chans, channel_names_to_indices
# grab all of the significant electrodes, and put them into one list, and then run plot_on_average
HOME = os.path.expanduser("~")
# get box directory depending on OS
if os.name == 'nt': # windows
LAB_root = os.path.join(HOME, "Box", "CoganLab")
else: # mac
LAB_root = os.path.join(HOME, "Library", "CloudStorage", "Box-Box", "CoganLab")
layout = get_data("GlobalLocal", root=LAB_root)
print(layout.derivatives)
print(layout.derivatives.keys())
base_path = os.path.join(LAB_root, "BIDS-1.1_GlobalLocal", "BIDS", "derivatives", "freqFilt", "figs")
subjects = layout.get(return_type="id", target="subject")
subjects_without_zeroes = ["D" + subj[1:].lstrip('0') for subj in subjects]
allSigElectrodes = {} # Initialize as an empty dictionary
allElectrodes = {}
for subj in subjects:
if subj == "D0077":
continue
resp_filename = f'{base_path}\\{subj}\\sig_chans_{subj}_Response.json'
stim_filename = f'{base_path}\\{subj}\\sig_chans_{subj}_Stimulus.json'
resp_sig_chans = load_sig_chans(resp_filename)
stim_sig_chans = load_sig_chans(stim_filename)
# Combine the significant electrodes for this subject
combined_chans = resp_sig_chans + stim_sig_chans
# Add them to the dictionary, tagged with the subject without zeroes
subj_without_zeroes = "D" + subj[1:].lstrip('0')
allSigElectrodes[subj_without_zeroes] = combined_chans
# Get all electrodes for this subject and add them to the allElectrodes dict
info = subject_to_info(subj_without_zeroes)
allSubjElectrodes = mne.pick_channels(info.ch_names, [])
allElectrodes[subj_without_zeroes] = allSubjElectrodes
picks = [f'D{k[1:].zfill(4)}-{v}' for k in allSigElectrodes.keys() for v in allSigElectrodes[k]]
sinfos = [subject_to_info(f'D{int(subj[1:])}') for subj in subjects]
sd = get_sub_dir()
plot_on_average(sinfos, picks=picks, hemi="both")
# plot_on_average(allElectrodes, hemi='both', color=(1,1,0))
OUTPUT:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[10], line 53
50 sinfos = [subject_to_info(f'D{int(subj[1:])}') for subj in subjects]
51 sd = get_sub_dir()
---> 53 plot_on_average(sinfos, picks=picks, hemi="both")
54 # plot_on_average(allElectrodes, hemi='both', color=(1,1,0))
File [c:\Users\jz421\Desktop\GlobalLocal\ieeg\viz\mri.py:293](file:///C:/Users/jz421/Desktop/GlobalLocal/ieeg/viz/mri.py:293), in plot_on_average(sigs, subj_dir, rm_wm, picks, surface, hemi, color, size, fig, background)
291 sigs = [sigs]
292 if isinstance(sigs, Iterable):
--> 293 sigs = {get_sub(v): v for v in sigs}
295 for subj, inst in sigs.items():
297 if isinstance(inst, mne.Info):
File [c:\Users\jz421\Desktop\GlobalLocal\ieeg\viz\mri.py:293](file:///C:/Users/jz421/Desktop/GlobalLocal/ieeg/viz/mri.py:293), in (.0)
291 sigs = [sigs]
292 if isinstance(sigs, Iterable):
--> 293 sigs = {get_sub(v): v for v in sigs}
295 for subj, inst in sigs.items():
297 if isinstance(inst, mne.Info):
File [c:\Users\jz421\Desktop\GlobalLocal\ieeg\viz\mri.py:385](file:///C:/Users/jz421/Desktop/GlobalLocal/ieeg/viz/mri.py:385), in get_sub(inst)
383 elif isinstance(inst, str):
384 return f"{inst[0]}{int(inst[1:])}"
--> 385 out_str = inst['subject_info']['his_id'][4:]
386 if len(out_str) == 1:
387 return out_str
TypeError: 'NoneType' object is not subscriptable