Skip to content

Commit

Permalink
Changed to local paths (Windows) and fixed the issue with interactive…
Browse files Browse the repository at this point in the history
… plots
  • Loading branch information
young-x-skyee committed Dec 21, 2023
1 parent cad0c57 commit 0208a31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion invokers/invoker_preproc_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
_display_welcome_message_to_terminal()

# Load parameters
config = load_config('/imaging/projects/cbu/kymata/analyses/tianyi/kymata-toolbox/kymata/config/dataset4.yaml')
config = load_config(r'\\cbsu\data\Imaging\projects\cbu\kymata\analyses\tianyi\kymata-toolbox\kymata\config\dataset4.yaml')

# Ensure we have all the data we need
data_integrety_checks(config=config)
Expand Down
21 changes: 11 additions & 10 deletions kymata/preproc/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from kymata.io.yaml import load_config
from kymata.preproc.emeg import apply_automatic_bad_channel_detection

import matplotlib
matplotlib.use('TkAgg')

def run_preprocessing(list_of_participants: list[str],
dataset_directory_name: str,
Expand All @@ -28,20 +30,19 @@ def run_preprocessing(list_of_participants: list[str],
print_with_color(f" Loading Raw data...", Fore.GREEN)

# set filename. (Use .fif.gz extension to use gzip to compress)
saved_maxfiltered_filename = '/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/intrim_preprocessing_files/1_maxfiltered/' + participant + "_run" + str(
run) + '_raw_sss.fif'
saved_maxfiltered_filename = r'//cbsu/data/Imaging/projects/cbu/kymata/data/' + dataset_directory_name + "/intrim_preprocessing_files/1_maxfiltered/" + participant + "_run" + str(run) + '_raw_sss.fif'

if skip_maxfilter_if_previous_runs_exist and os.path.isfile(saved_maxfiltered_filename):
raw_fif_data_sss_movecomp_tr = mne.io.Raw(saved_maxfiltered_filename, preload=True)

else:
raw_fif_data = mne.io.Raw(
'/imaging/projects/cbu/kymata/data/' + dataset_directory_name + "/raw_emeg/" + participant + "/" + participant + "_run" + str(
r'//cbsu/data/imaging/projects/cbu/kymata/data/' + dataset_directory_name + "/raw_emeg/" + participant + "/" + participant + "_run" + str(
run) + "_raw.fif", preload=True)

# Rename any channels that require it, and their type
recording_config = load_config(
'/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/raw_emeg/' + participant + "/" + participant + '_recording_config.yaml')
r'//cbsu/data/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/raw_emeg/' + participant + "/" + participant + '_recording_config.yaml')
ecg_and_eog_channel_name_and_type_overwrites = recording_config[
'ECG_and_EOG_channel_name_and_type_overwrites']

Expand Down Expand Up @@ -105,8 +106,8 @@ def run_preprocessing(list_of_participants: list[str],
# Apply SSS and movement compensation
print_with_color(f" Applying SSS and movement compensation...", Fore.GREEN)

fine_cal_file = '/imaging/projects/cbu/kymata/data/cbu_specific_files/SSS/sss_cal_' + emeg_machine_used_to_record_data + '.dat'
crosstalk_file = '/imaging/projects/cbu/kymata/data/cbu_specific_files/SSS/ct_sparse_' + emeg_machine_used_to_record_data + '.fif'
fine_cal_file = r'//cbsu/data/imaging/projects/cbu/kymata/data/cbu_specific_files/SSS/sss_cal_' + emeg_machine_used_to_record_data + '.dat'
crosstalk_file = r'//cbsu/data/imaging/projects/cbu/kymata/data/cbu_specific_files/SSS/ct_sparse_' + emeg_machine_used_to_record_data + '.fif'

mne.viz.plot_head_positions(
head_pos_data, mode='field', destination=raw_fif_data.info['dev_head_t'], info=raw_fif_data.info)
Expand Down Expand Up @@ -182,7 +183,7 @@ def run_preprocessing(list_of_participants: list[str],
mne.viz.plot_raw(raw_fif_data_sss_movecomp_tr)

raw_fif_data_sss_movecomp_tr.save(
'/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/intrim_preprocessing_files/2_cleaned/' + participant + "_run" + str(
r'//cbsu/data/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/intrim_preprocessing_files/2_cleaned/' + participant + "_run" + str(
run) + '_cleaned_raw.fif.gz',
overwrite=True)

Expand Down Expand Up @@ -261,7 +262,7 @@ def create_trials(dataset_directory_name: str,
cleaned_raws = []

for run in range(1, number_of_runs + 1):
raw_fname = '/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/intrim_preprocessing_files/2_cleaned/' + p + '_run' + str(run) + '_cleaned_raw.fif.gz'
raw_fname = r'//cbsu/data/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/intrim_preprocessing_files/2_cleaned/' + p + '_run' + str(run) + '_cleaned_raw.fif.gz'
raw = mne.io.Raw(raw_fname, preload=True)
cleaned_raws.append(raw)

Expand Down Expand Up @@ -328,7 +329,7 @@ def create_trials(dataset_directory_name: str,
# Log which channels are worst
dropfig = epochs.plot_drop_log(subject=p)
dropfig.savefig(
'/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/intrim_preprocessing_files/3_evoked_sensor_data/logs/' + input_stream + '_drop-log_' + p + '.jpg')
r'//cbsu/data/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/intrim_preprocessing_files/3_evoked_sensor_data/logs/' + input_stream + '_drop-log_' + p + '.jpg')

global_droplog.append('[' + input_stream + ']' + p + ':' + str(epochs.drop_log_stats(epochs.drop_log)))

Expand All @@ -354,7 +355,7 @@ def create_trials(dataset_directory_name: str,
print_with_color(f"... save grand covariance matrix", Fore.GREEN)

cov = mne.compute_raw_covariance(raw, tmin=0, tmax=10, return_estimators=True)
mne.write_cov('/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/intrim_preprocessing_files/3_evoked_sensor_data/covariance_grand_average/' + p + '-auto-cov.fif', cov)
mne.write_cov(r'//cbsu/data/imaging/projects/cbu/kymata/data/' + dataset_directory_name + '/intrim_preprocessing_files/3_evoked_sensor_data/covariance_grand_average/' + p + '-auto-cov.fif', cov)


# Save global droplog
Expand Down

0 comments on commit 0208a31

Please sign in to comment.