Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

KTUEAMapFile.m.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. classdef KTUEAMapFile
  2. % UEAMAPFILE -- Defines a class that contains information on a UEA
  3. % electrode array using CMP files provided by Blackrock Microsystems.
  4. %
  5. % To load a CMP file type 'MapName = UEAMapFile' where MapName is the name
  6. % of the variable that will be created and will contain the map class.
  7. %
  8. % Example: myArrayMap = UEAMapFile;
  9. %
  10. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  11. % METHODS:
  12. %
  13. % There are several available methods for mapfiles. Here's a list and a
  14. % description of what they perform.
  15. %
  16. % Electrode2Channel(Electrode):
  17. % Will return the Channel number corresponding to a passed Electrode.
  18. %
  19. % Channel2Electrode(Channel):
  20. % Will return the Electrode number corresponding to a passed Channel.
  21. %
  22. % GetChannelBankID(Channel):
  23. % Returns the BankID for a passed Channel.
  24. %
  25. % GetChannelPin(Channel):
  26. % Returns the Pin for a passed Channel.
  27. %
  28. % GetChannelLabel(Channel):
  29. % Returns the Label for a passed Channel.
  30. %
  31. % GenerateChannelSubplot(Channel):
  32. % Returns a subplot handle for the passed Channel to be used in plotting
  33. % UEA-like maps.
  34. %
  35. % GenerateChannelSubplotNames(Channel):
  36. % Plots the names of channels and electrodes on the subplot corresponding
  37. % to the passed Channel.
  38. %
  39. % GetChannelColumnRow(Channel):
  40. % Returns the Column and Row positions of the passed number that is used
  41. % to plot UEA-like maps.
  42. %
  43. % PlotCMP:
  44. % Will plot a map of the CMP Map with all the electrode and channel
  45. % names.
  46. %
  47. % Kian Torab
  48. % Blackrock Microsystems
  49. % ktorab@blackrockmicro.com
  50. %
  51. % Version 1.5
  52. %%
  53. properties (SetAccess = private)
  54. ElecNum
  55. ChanNum
  56. Column
  57. Row
  58. Bank
  59. Pin
  60. Label
  61. pathHandle
  62. fileHandle
  63. end
  64. methods (Hidden)
  65. function obj = KTUEAMapFile(fileName)
  66. if ~exist('fileName', 'var')
  67. if exist('getFile.m', 'file') == 2
  68. [obj.fileHandle obj.pathHandle] = getFile('*.cmp', 'Open a CMP Mapfile...');
  69. else
  70. [obj.fileHandle obj.pathHandle] = uigetfile('*.cmp', 'Open a CMP Mapfile...');
  71. end
  72. if ~obj.fileHandle
  73. disp('No file was selected.');
  74. return;
  75. end
  76. mapfileDataCell = importdata([obj.pathHandle obj.fileHandle], ' ', 200);
  77. else
  78. mapfileDataCell = importdata(fileName, ' ', 200);
  79. end
  80. lastJunkIDX = find(~cellfun(@isempty, strfind(mapfileDataCell, '//')) == 1, 1, 'last') + 1;
  81. mapfileDataCell(1:lastJunkIDX) = [];
  82. mapfileDataCellParsed = regexp(mapfileDataCell, '\t', 'split');
  83. if size(mapfileDataCellParsed, 2) == 1
  84. mapfileDataCellParsed = regexp(mapfileDataCell, '\s+', 'split');
  85. end
  86. for i = 1:size(mapfileDataCellParsed, 1)
  87. if ~all(isspace(mapfileDataCell{i}))
  88. obj.Column(i) = str2num(mapfileDataCellParsed{i,:}{1});
  89. obj.Row(i) = str2num(mapfileDataCellParsed{i,:}{2});
  90. obj.Bank(i) = mapfileDataCellParsed{i,:}{3}-'@';
  91. obj.Pin(i) = str2num(mapfileDataCellParsed{i,:}{4});
  92. ElectNum = str2num(mapfileDataCellParsed{i,:}{5}(5:end));
  93. if isempty(ElectNum)
  94. obj.ElecNum(i) = str2num(mapfileDataCellParsed{i,:}{5}(2:end-4));
  95. else
  96. obj.ElecNum(i) = ElectNum;
  97. end
  98. obj.ChanNum(i) = (obj.Bank(i) - 1) * 32 + obj.Pin(i);
  99. obj.Label{i} = mapfileDataCellParsed{i,:}{5};
  100. end
  101. end
  102. end
  103. end
  104. methods
  105. function validFlag = isValid(obj)
  106. if ~obj.getFilename
  107. validFlag = 0;
  108. else
  109. validFlag = 1;
  110. end
  111. end
  112. function FilePath = getPathName(obj)
  113. FilePath = obj.pathHandle;
  114. end
  115. function FileName = getFilename(obj)
  116. FileName = obj.fileHandle;
  117. end
  118. function Channel = Electrode2Channel(obj, Electrode)
  119. if ~exist('Electrode', 'var'); disp('Electrode is a required input. Refer to help for more information.'); return; end;
  120. if isempty(obj.ChanNum(obj.ElecNum == Electrode(1)))
  121. disp('Electrode number is invalid.');
  122. Channel = [];
  123. return;
  124. end
  125. for ElecIDX = 1:length(Electrode)
  126. Channel(ElecIDX) = obj.ChanNum(obj.ElecNum == Electrode(ElecIDX));
  127. end
  128. end
  129. function Electrode = Channel2Electrode(obj, Channel)
  130. if isempty(obj.ElecNum(obj.ChanNum == Channel(1)))
  131. disp('Channel number is invalid.');
  132. Electrode = [];
  133. return;
  134. end
  135. if ~exist('Channel', 'var'); disp('Channel is a required input. Refer to help for more information.'); return; end;
  136. for ChanIDX = 1:length(Channel)
  137. Electrode(ChanIDX) = obj.ElecNum(obj.ChanNum == Channel(ChanIDX));
  138. end
  139. end
  140. function BankID = getChannelBankID(obj, Channel)
  141. BankID = obj.Bank(obj.ChanNum == Channel);
  142. end
  143. function Label = getChannelLabel(obj, Channel)
  144. Label = char(obj.Label{obj.ChanNum == Channel});
  145. end
  146. function Pin = getChannelPin(obj, Channel)
  147. Pin = obj.Pin(obj.ChanNum == Channel);
  148. end
  149. function spHandle = GenerateChannelSubplot(obj, Channel)
  150. if ~exist('Channel', 'var'); disp('Channel is a required input. Refer to help for more information.'); return; end;
  151. [x, y] = getChannelColumnRow(obj, Channel);
  152. spHandle=subplot('position', [x/10+0.004, y/10+0.004, 1/10-0.004, 1/10-0.004]);
  153. axis off;
  154. box on;
  155. set(spHandle,'XTickLabel', []);
  156. set(spHandle,'YTickLabel', []);
  157. %%
  158. end
  159. function GenerateChannelSubplotNames(obj, Channel, fColor)
  160. if ~exist('Channel', 'var'); disp('Channel is a required input. Refer to help for more information.'); return; end;
  161. if ~exist('fColor', 'var'); fColor = [1,1,1]; end
  162. Electrode = Channel2Electrode(obj, Channel);
  163. text(0.13, 0.23, ['elec ', num2str(Electrode)], 'Color', fColor, 'FontSize', 8);
  164. text(0.13, 0.10, ['chan ', num2str(Channel)], 'Color', fColor, 'FontSize', 8);
  165. end
  166. function [x, y] = getChannelColumnRow(obj, Channel)
  167. if ~exist('Channel', 'var'); disp('Channel is a required input. Refer to help for more information.'); return; end;
  168. x = obj.Column(obj.ChanNum == Channel);
  169. y = obj.Row(obj.ChanNum == Channel);
  170. end
  171. function PlotCMP(obj)
  172. figure;
  173. for Channel = 1:96
  174. GenerateChannelSubplot(obj, Channel);
  175. GenerateChannelSubplotNames(obj, Channel, [0,0,0]);
  176. end
  177. end
  178. function setAxisBackgroundColor(~, curColor)
  179. if isa(curColor, 'double') && (length(curColor) == 3)
  180. if all(curColor <= 1) && all(curColor >= 0)
  181. set(gca, 'Color', curColor);
  182. else
  183. disp('The color values have to be between 0 and 1.');
  184. end
  185. elseif isa(curColor, 'char')
  186. try
  187. set(gca, 'Color', curColor);
  188. catch
  189. disp('Color is not valid. Type ''doc color'' for more information.');
  190. end
  191. else
  192. disp('The input needs to be a valid color input.');
  193. disp('A valid color input is a vector of length 3 of values between 0 and 1.');
  194. end
  195. end
  196. function setXAxisColor(~, curColor)
  197. if isa(curColor, 'double') && (length(curColor) == 3)
  198. if all(curColor <= 1) && all(curColor >= 0)
  199. set(gca, 'XColor', curColor);
  200. else
  201. disp('The color values have to be between 0 and 1.');
  202. end
  203. elseif isa(curColor, 'char')
  204. try
  205. set(gca, 'XColor', curColor);
  206. catch
  207. disp('Color is not valid. Type ''doc color'' for more information.');
  208. end
  209. else
  210. disp('The input needs to be a valid color input.');
  211. disp('A valid color input is a vector of length 3 of values between 0 and 1.');
  212. end
  213. end
  214. function setYAxisColor(~, curColor)
  215. if isa(curColor, 'double') && (length(curColor) == 3)
  216. if all(curColor <= 1) && all(curColor >= 0)
  217. set(gca, 'YColor', curColor);
  218. else
  219. disp('The color values have to be between 0 and 1.');
  220. end
  221. elseif isa(curColor, 'char')
  222. try
  223. set(gca, 'YColor', curColor);
  224. catch
  225. disp('Color is not valid. Type ''doc color'' for more information.');
  226. end
  227. else
  228. disp('The input needs to be a valid color input.');
  229. disp('A valid color input is a vector of length 3 of values between 0 and 1.');
  230. end
  231. end
  232. function setAxesColor(~, curColor)
  233. if isa(curColor, 'double') && (length(curColor) == 3)
  234. if all(curColor <= 1) && all(curColor >= 0)
  235. set(gca, 'YColor', curColor);
  236. set(gca, 'XColor', curColor);
  237. else
  238. disp('The color values have to be between 0 and 1.');
  239. end
  240. elseif isa(curColor, 'char')
  241. try
  242. set(gca, 'YColor', curColor);
  243. set(gca, 'XColor', curColor);
  244. catch
  245. disp('Color is not valid. Type ''doc color'' for more information.');
  246. end
  247. else
  248. disp('The input needs to be a valid color input.');
  249. disp('A valid color input is a vector of length 3 of values between 0 and 1.');
  250. end
  251. end
  252. end
  253. end