Load_Data_Example_Script.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. %% Add nix to path
  2. % Path for the folder 'nix-mx_Win64_1.4.1'
  3. addpath('nix-mx_Win64_1.4.1\')
  4. %% Open NIX file
  5. % Path of the selected file
  6. file_path = 'Data_Subject_01_Session_01.h5';
  7. f = nix.File(file_path,nix.FileMode.ReadOnly);
  8. %% Read metadata
  9. % Display names of all sections
  10. cellfun(@(x) disp(x.name),f.sections)
  11. %% General information
  12. sectionGeneral = f.openSection('General');
  13. % Properties
  14. cellfun(@(x) disp(x.name),sectionGeneral.properties)
  15. % Institution
  16. fprintf(['Institution: ',sectionGeneral.openProperty('Institution').values{1}.value,'\n'])
  17. % Recording location
  18. fprintf(['Recording location: ',sectionGeneral.openProperty('Recording location').values{1}.value,'\n'])
  19. % Sections
  20. cellfun(@(x) disp(x.name),sectionGeneral.sections)
  21. % Publications
  22. sectionPublications = sectionGeneral.openSection('Related publications');
  23. cellfun(@(x) disp(x.name),sectionPublications.properties)
  24. fprintf(['Publication name: ',sectionPublications.openProperty('Publication name').values{1}.value,'\n'])
  25. fprintf(['Publication DOI: ',sectionPublications.openProperty('Publication DOI').values{1}.value,'\n'])
  26. % Recording setup
  27. sectionRecordingSetup = sectionGeneral.openSection('Recording setup');
  28. cellfun(@(x) disp(x.name),sectionRecordingSetup.properties)
  29. fprintf(['Recording setup iEEG: ',sectionRecordingSetup.openProperty('Recording setup iEEG').values{1}.value,'\n'])
  30. fprintf(['Recording setup EEG: ',sectionRecordingSetup.openProperty('Recording setup EEG').values{1}.value,'\n'])
  31. %% Task information
  32. sectionTask = f.openSection('Task');
  33. % Properties
  34. cellfun(@(x) disp(x.name),sectionTask.properties)
  35. % Task characteristics
  36. fprintf(['Task name: ',sectionTask.openProperty('Task name').values{1}.value,'\n'])
  37. fprintf(['Task description: ',sectionTask.openProperty('Task description').values{1}.value,'\n'])
  38. fprintf(['Task URL: ',sectionTask.openProperty('Task URL').values{1}.value,'\n'])
  39. %% Subject information
  40. sectionSubject = f.openSection('Subject');
  41. % Properties
  42. cellfun(@(x) disp(x.name),sectionSubject.properties)
  43. % Subject characteristics
  44. fprintf(['Age: ',num2str(sectionSubject.openProperty('Age').values{1}.value),'\n'])
  45. fprintf(['Sex: ',sectionSubject.openProperty('Sex').values{1}.value,'\n'])
  46. fprintf(['Handedness: ',sectionSubject.openProperty('Handedness').values{1}.value,'\n'])
  47. fprintf(['Pathology: ',sectionSubject.openProperty('Pathology').values{1}.value,'\n'])
  48. fprintf(['Depth electrodes: ',sectionSubject.openProperty('Depth electrodes').values{1}.value,'\n'])
  49. fprintf(['Electrodes in seizure onset zone (SOZ): ',sectionSubject.openProperty('Electrodes in seizure onset zone (SOZ)').values{1}.value,'\n'])
  50. %% Session information
  51. sectionSession = f.openSection('Session');
  52. % Properties
  53. cellfun(@(x) disp(x.name),sectionSession.properties)
  54. % Session characteristics
  55. fprintf(['Number of trials: ',num2str(sectionSession.openProperty('Number of trials').values{1}.value),'\n'])
  56. fprintf(['Trial duration: ',num2str(sectionSession.openProperty('Trial duration').values{1}.value),' ',sectionSession.openProperty('Trial duration').unit,'\n'])
  57. % Sections
  58. cellfun(@(x) disp(x.name),sectionSession.sections)
  59. %% Trial information
  60. sectionTrialProperties = sectionSession.openSection('Trial properties');
  61. % Sections
  62. cellfun(@(x) disp(x.name),sectionTrialProperties.sections)
  63. % Each section is for a single trial
  64. % Select trial
  65. nTrial = 1;
  66. sectionSingleTrial = sectionTrialProperties.sections{nTrial};
  67. %% Single trial
  68. % Properties
  69. cellfun(@(x) disp(x.name),sectionSingleTrial.properties)
  70. for nProperty = 1:length(sectionSingleTrial.properties)
  71. switch sectionSingleTrial.properties{nProperty}.datatype
  72. case {'double','logical'}
  73. fprintf([sectionSingleTrial.properties{nProperty}.name,': ',num2str(sectionSingleTrial.properties{nProperty}.values{1}.value),'\n'])
  74. otherwise
  75. fprintf([sectionSingleTrial.properties{nProperty}.name,': ',sectionSingleTrial.properties{nProperty}.values{1}.value,'\n'])
  76. end
  77. end
  78. %% Blocks
  79. cellfun(@(x) disp(x.name),f.blocks)
  80. block = f.blocks{1};
  81. %% Groups of data arrays, tags, multitags
  82. groups = block.groups;
  83. cellfun(@(x) disp(x.name),block.groups)
  84. %% Select trial
  85. nTrial = 1;
  86. %% iEEG data
  87. group_iEEG = block.openGroup('iEEG data');
  88. % Data array
  89. dataArray_iEEG = group_iEEG.dataArrays{nTrial};
  90. % Electrode labels
  91. striEEGLabels = dataArray_iEEG.dimensions{1}.labels;
  92. % Time axis
  93. tiEEG = (0:(double(dataArray_iEEG.dataExtent(2))-1))*dataArray_iEEG.dimensions{2}.samplingInterval+dataArray_iEEG.dimensions{2}.offset;
  94. % Read data
  95. data_iEEG = dataArray_iEEG.readAllData;
  96. % Plot trial data
  97. figure
  98. plot(tiEEG,data_iEEG)
  99. title(['iEEG data - Trial ',num2str(nTrial)])
  100. xlabel(['Time (',dataArray_iEEG.dimensions{2}.unit,')'])
  101. ylabel(['Voltage (',dataArray_iEEG.unit,')'])
  102. legend(striEEGLabels)
  103. %% Scalp EEG data
  104. group_ScalpEEG = block.openGroup('Scalp EEG data');
  105. % Data array
  106. dataArray_ScalpEEG = group_ScalpEEG.dataArrays{nTrial};
  107. % Electrode labels
  108. strScalpEEGLabels = dataArray_ScalpEEG.dimensions{1}.labels;
  109. % Time axis
  110. tScalpEEG = (0:(double(dataArray_ScalpEEG.dataExtent(2))-1))*dataArray_ScalpEEG.dimensions{2}.samplingInterval+dataArray_ScalpEEG.dimensions{2}.offset;
  111. % Read data
  112. data_ScalpEEG = dataArray_ScalpEEG.readAllData;
  113. % Plot trial data
  114. figure
  115. plot(tScalpEEG,data_ScalpEEG)
  116. title(['Scalp data - Trial ',num2str(nTrial)])
  117. xlabel(['Time (',dataArray_ScalpEEG.dimensions{2}.unit,')'])
  118. ylabel(['Voltage (',dataArray_ScalpEEG.unit,')'])
  119. legend(strScalpEEGLabels)
  120. %% Trial events
  121. group_TrialEvents_iEEG = block.openGroup('Trial events single tags iEEG');
  122. group_TrialEvents_ScalpEEG = block.openGroup('Trial events single tags scalp EEG');
  123. %% Trial events for a single trial
  124. indTrialTags_iEEG = contains(cellfun(@(x) x.name,group_TrialEvents_iEEG.tags,'UniformOutput',0),['Trial_',num2str(nTrial,'%.2d')]);
  125. indTrialTags_ScalpEEG = contains(cellfun(@(x) x.name,group_TrialEvents_ScalpEEG.tags,'UniformOutput',0),['Trial_',num2str(nTrial,'%.2d')]);
  126. TrialEvents_iEEG = group_TrialEvents_iEEG.tags(indTrialTags_iEEG);
  127. TrialEvents_ScalpEEG = group_TrialEvents_iEEG.tags(indTrialTags_ScalpEEG);
  128. cellfun(@(x) disp(x.name),TrialEvents_iEEG)
  129. cellfun(@(x) disp(x.name),TrialEvents_ScalpEEG)
  130. %% Time of a single event
  131. nEvent = 3; % Maintenance
  132. fprintf(['Event name: ',TrialEvents_iEEG{nEvent}.name,'\n'])
  133. fprintf([sprintf('Time w.r.t. fixation: %.1f %s',TrialEvents_iEEG{nEvent}.position(2),TrialEvents_iEEG{nEvent}.units{1}),'\n'])
  134. fprintf([sprintf('Duration: %.1f %s',TrialEvents_iEEG{nEvent}.extent(2),TrialEvents_iEEG{nEvent}.units{1}),'\n'])
  135. % The values are the same for TrialEvents_ScalpEEG
  136. %% Units
  137. group_SpikeTimes = block.openGroup('Spike times');
  138. %% Select unit and trial
  139. nUnit = 1;
  140. nTrial = 5;
  141. indUnitSpikeTimes = contains(cellfun(@(x) x.name,group_SpikeTimes.dataArrays,'UniformOutput',0),['Unit_',num2str(nUnit),'_'])&...
  142. contains(cellfun(@(x) x.name,group_SpikeTimes.dataArrays,'UniformOutput',0),['Trial_',num2str(nTrial,'%.2d')]);
  143. dataArray_SpikeTimes = group_SpikeTimes.dataArrays{indUnitSpikeTimes};
  144. % Read data
  145. SpikeTimes = dataArray_SpikeTimes.readAllData;
  146. figure
  147. stem(dataArray_SpikeTimes.readAllData,ones(length(SpikeTimes),1))
  148. title(['Spike times - Unit ',num2str(nUnit),' - Trial ',num2str(nTrial)])
  149. xlabel(['Time (',dataArray_SpikeTimes.dimensions{1}.unit,')'])
  150. %% Multitag for the unit
  151. indMultiTagUnitSpikeTimes = contains(cellfun(@(x) x.name,block.multiTags,'UniformOutput',0),['Unit_',num2str(nUnit),'_'])&...
  152. contains(cellfun(@(x) x.name,block.multiTags,'UniformOutput',0),['Trial_',num2str(nTrial,'%.2d')]);
  153. multiTag_SpikeTimes = block.multiTags{indMultiTagUnitSpikeTimes};
  154. %% Waveform for the unit
  155. dataArray_Waveform = multiTag_SpikeTimes.features{1}.openData;
  156. % Time axis
  157. tWaveform = (0:(double(dataArray_Waveform.dataExtent(2))-1))*dataArray_Waveform.dimensions{2}.samplingInterval+dataArray_Waveform.dimensions{2}.offset;
  158. % Read data
  159. waveform = dataArray_Waveform.readAllData;
  160. % Plot
  161. figure
  162. plot(tWaveform,waveform(1,:),'b')
  163. hold on
  164. plot(tWaveform,waveform(1,:)+waveform(2,:),'b--')
  165. plot(tWaveform,waveform(1,:)-waveform(2,:),'b--')
  166. title(['Waveform - Unit',num2str(nUnit)])
  167. xlabel(['Time (',dataArray_Waveform.dimensions{2}.unit,')'])
  168. ylabel(['Voltage (',dataArray_Waveform.unit,')'])
  169. legend({'Mean','Std'})
  170. %% Source of the unit
  171. sourceUnit = dataArray_SpikeTimes.sources{1};
  172. % Electrode label
  173. sourceUnit.sources{1}.name
  174. % Anatomical location
  175. sourceUnit.sources{2}.name
  176. %% Use electrode map to get properties of the macroelectrode the unit is on
  177. groupiEEGElecrodes = block.openGroup('iEEG electrode information');
  178. nElectrode = find(strcmpi(cellfun(@(x) x.name,groupiEEGElecrodes.sources,'UniformOutput',0),sourceUnit.name));
  179. % MNI coordinates of the electrode
  180. groupiEEGElecrodes.multiTags{1}.retrieveFeatureData(nElectrode,'iEEG_Electrode_MNI_Coordinates')
  181. % Was the anatomical location manually entered?
  182. groupiEEGElecrodes.multiTags{1}.retrieveFeatureData(nElectrode,'iEEG_Electrode_Manual_Entry')