a4_ica_labeling.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. %% a4_ica_labeling
  2. % required functions:
  3. % - cm_label_ica_gui_20180116
  4. currentFile = mfilename('fullpath');
  5. [pathstr,~,~] = fileparts(currentFile);
  6. cd(fullfile(pathstr,'..'))
  7. rootpath = pwd;
  8. % inputs
  9. pn.eeg_BIDS = fullfile(rootpath, 'data', 'inputs', 'rawdata', 'eeg_BIDS');
  10. pn.channel_locations = fullfile(rootpath, 'data', 'inputs', 'rawdata', 'channel_locations');
  11. pn.events = fullfile(rootpath, 'data', 'inputs', 'rawdata', 'events');
  12. pn.tools = fullfile(rootpath, 'tools');
  13. % outputs
  14. pn.eeg_ft = fullfile(rootpath, 'data', 'outputs', 'eeg');
  15. pn.history = fullfile(rootpath, 'data', 'outputs', 'history');
  16. addpath(fullfile(pn.tools, 'fieldtrip')); ft_defaults;
  17. addpath(fullfile(pn.tools, 'helpers'));
  18. %% define IDs for visual screening
  19. ID = 'sub-001';
  20. %% load data & start GUI
  21. % load data (full data)
  22. load(fullfile(pn.eeg_ft, [ID, '_task-xxxx_eeg_ica.mat']),'data');
  23. if ~isfield(data.iclabels,'emg')
  24. data.iclabels.emg = [];
  25. end
  26. % load config (ICA version)
  27. load(fullfile(pn.history, [ID, '_task-xxxx_config.mat']),'config');
  28. % settings for ICA
  29. % ica config
  30. cfg.method = config.ica1.cfg.method; %'runica';
  31. cfg.trials = 'all';
  32. cfg.numcomponent = 'all';
  33. cfg.demean = 'no';
  34. cfg.runica.extended = 1;
  35. % ICA solution for segments
  36. cfg.unmixing = data.unmixing;
  37. cfg.topolabel = data.topolabel;
  38. % ICA (from weights)
  39. % components
  40. comp = ft_componentanalysis(cfg,data);
  41. % include electrode information
  42. comp.elec = data.elec;
  43. % include ICA labeling
  44. comp.iclabels = data.iclabels;
  45. % clear cfg
  46. clear cfg
  47. % label ICs
  48. % settings
  49. cfg.topoall = 'yes';
  50. cfg.chanlocs = data.chanlocs;
  51. % label electrodes
  52. data.iclabels = cm_label_ica_gui_20180116(cfg,comp);
  53. % keep labels in config
  54. config.ica1.iclabels.manual = data.iclabels;
  55. % clear variables
  56. clear cfg
  57. % save data (full data)
  58. save(fullfile(pn.eeg_ft, [ID, '_task-xxxx_eeg_ica.mat']),'data');
  59. % save config (ICA version)
  60. save(fullfile(pn.history, [ID, '_task-xxxx_config.mat']),'config');
  61. % clear variables
  62. clear BLOCK ID comp config data