From 245309713d505d17d00a20cbc2733747cff3b16f Mon Sep 17 00:00:00 2001 From: Jeff Stout Date: Fri, 25 Oct 2024 17:13:13 -0400 Subject: [PATCH] Minor adds + cleanup --- nih2mne/GUI/qa_bids_gui.py | 2 + nih2mne/GUI/qt_gui.py | 25 ++++++- nih2mne/dataQA/qa_config_reader.py | 17 ----- nih2mne/make_mri_json.py | 110 ----------------------------- 4 files changed, 26 insertions(+), 128 deletions(-) delete mode 100755 nih2mne/make_mri_json.py diff --git a/nih2mne/GUI/qa_bids_gui.py b/nih2mne/GUI/qa_bids_gui.py index 71ea4c1..6014f4f 100644 --- a/nih2mne/GUI/qa_bids_gui.py +++ b/nih2mne/GUI/qa_bids_gui.py @@ -678,6 +678,8 @@ def subject_qa_POPUP(bids_info, text_item='Select'): [sg.Text(f'{bids_info}')], # [sg.Listbox(data, size=(20,5), key='SELECTED')], [sg.Button('Plot MEG',key='-PLOT_MEG-'), sg.Combo(bids_info.meg_list, key='-MEG_SELECTION-')], + + [sg.Button('Process Freesurfer', key='-PROC_FS-')] ] window = sg.Window('POPUP', layout).Finalize() meg_selection = None diff --git a/nih2mne/GUI/qt_gui.py b/nih2mne/GUI/qt_gui.py index b71411d..33f8c9d 100755 --- a/nih2mne/GUI/qt_gui.py +++ b/nih2mne/GUI/qt_gui.py @@ -7,7 +7,18 @@ TODO -- check the MEG datasets and assess bad subjs data (bad chans etc) -launch single subject check from push button + +Layout: + BIDS_project_window: + Freesurfer - Run all outstanding freesurfer processing + MRIprep - Run all mri preprocessing on outstanding subjects + MEGNET - not implemented currently + Next/Prev - Page Numbers + Subject_Tile: + BIDS_root lookup + QA file - QA-s the MEG tasks per subject + Subject_GUI: + Subject specific parameters. Summary+Triax+3Dcoreg+MEG plotting """ @@ -21,6 +32,7 @@ import numpy as np from nih2mne.utilities.montages import montages from nih2mne.dataQA.qa_config_reader import qa_dataset, read_yml +import glob @@ -271,6 +283,17 @@ def setup_full_layout(self): self.b_task_chooser.addItems(self.task_set) self.b_task_chooser.currentIndexChanged.connect(self.filter_task_qa_vis) top_buttons_layout.addWidget(self.b_task_chooser) + self.b_out_project_chooser = QComboBox() + #Add Project output directory + # tmp_ = glob.glob('*', root_dir=op.join(self.bids_project.bids_root, 'derivatives')) + # derivatives_dirs = [i for i in tmp_ if op.isdir(op.join(self.bids_project.bids_root, 'derivatives', i))] + # for i in ['freesurfer', 'megQA']: + # if i in derivatives_dirs: derivatives_dirs.remove(i) + # self.b_out_project_chooser.addItems(derivatives_dirs) + # top_buttons_layout.addWidget(self.b_out_project_chooser) + + + main_layout.addLayout(top_buttons_layout) # Add Subject Chooser Grid Layer diff --git a/nih2mne/dataQA/qa_config_reader.py b/nih2mne/dataQA/qa_config_reader.py index 2f7ae87..9367892 100644 --- a/nih2mne/dataQA/qa_config_reader.py +++ b/nih2mne/dataQA/qa_config_reader.py @@ -51,20 +51,3 @@ def qa_dataset(raw, task_type=None, qa_dict=None): - - - - - - - -#%% Testing -def test_yaml_read(): - from nih2mne.dataQA.qa_config_reader import read_yml - import nih2mne - fname = op.join(nih2mne.__path__[0], 'dataQA', 'config_template.yml') - dat = read_yml(fname) - assert dat['airpuff']['stim']==425 - assert dat['airpuff']['missingstim'] ==75 - assert 'haririhammer' in dat.keys() - diff --git a/nih2mne/make_mri_json.py b/nih2mne/make_mri_json.py deleted file mode 100755 index 0e17cc4..0000000 --- a/nih2mne/make_mri_json.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Thu Oct 24 10:37:34 2024 - -@author: jstout -""" - -import os, os.path as op -import pandas as pd -import numpy as np -import nibabel as nib -import json - - - - -import argparse -if __name__=='__main__': - parser = argparse.ArgumentParser() - parser.add_argument('-mri', - help='Nifti format MRI used with brainsight', - required=True - ) - parser.add_argument('-elec', - help = 'Electrodes.txt file name', - required=True - ) - parser.add_argument('-plot', - default=False, - help='Plot the results in a triaxial image', - action='store_true') - args = parser.parse_args() - - -elec_fname = args.elec -mri_fname = args.mri -do_plot = args.plot - -#%% -mri = nib.load(mri_fname) -dframe = pd.read_csv(elec_fname, skiprows=6, sep='\t') - -locs_ras = {} -for val in ['Nasion', 'Left Ear', 'Right Ear']: - row = dframe[dframe['# Electrode Name']==val] - tmp = row['Loc. X'], row['Loc. Y'], row['Loc. Z'] - output = [i.values[0] for i in tmp] - locs_ras[val] = np.array(output) - - -# set the fids as voxel coords -inv_rot = np.linalg.inv(mri.affine[0:3,0:3]) -translation = mri.affine[0:3,3] -nas_vox = np.matmul(inv_rot, locs_ras['Nasion']) - translation -lpa_vox = np.matmul(inv_rot, locs_ras['Left Ear']) - translation -rpa_vox = np.matmul(inv_rot, locs_ras['Right Ear']) - translation - - -# if json exists read it - -# else create it - -fids_json_out = {"AnatomicalLandmarkCoordinates": { - "NAS":list(nas_vox), - "LPA":list(lpa_vox), - "RPA":list(rpa_vox) - }} - -if mri_fname.endswith('.gz'): - json_fname = mri_fname.replace('.nii.gz', '.json') -else: - json_fname = mri_fname.replace('.nii','.json') - -# Write the json -with open(json_fname, 'w') as f: - json.dump(fids_json_out, f) - - -if do_plot: - from matplotlib import pyplot as plt - from nilearn.plotting import plot_anat - - # Do a full read of the json - with open(json_fname, 'r') as f: - json_out = json.load(f) - nas_vox = json_out['AnatomicalLandmarkCoordinates']['NAS'] - lpa_vox = json_out['AnatomicalLandmarkCoordinates']['LPA'] - rpa_vox = json_out['AnatomicalLandmarkCoordinates']['RPA'] - - nas = np.matmul(mri.affine[0:3,0:3] , nas_vox) + mri.affine[0:3,3] - lpa = np.matmul(mri.affine[0:3,0:3] , lpa_vox) + mri.affine[0:3,3] - rpa = np.matmul(mri.affine[0:3,0:3] , rpa_vox) + mri.affine[0:3,3] - - mri_pos = {'LPA':lpa, 'NAS': nas , 'RPA': rpa} - - # Plot it - fig, axs = plt.subplots(3, 1, figsize=(7, 7), facecolor="k") - for point_idx, label in enumerate(("LPA", "NAS", "RPA")): - plot_anat( - mri_fname, - axes=axs[point_idx], - cut_coords=mri_pos[label],#, :], - title=label, - vmax=160, - ) - plt.show(block=True) - - - \ No newline at end of file