/external/fieldtrip/trunk/utilities/ft_datatype_source.m

http://open-realtime-fmri.googlecode.com/ · MATLAB · 169 lines · 72 code · 17 blank · 80 comment · 22 complexity · bfc01980e50f185b4feebd535a10dfc7 MD5 · raw file

  1. function source = ft_datatype_source(source, varargin)
  2. % FT_DATATYPE_SOURCE describes the FieldTrip MATLAB structure for source data
  3. %
  4. % The source datatype represents source-level data typically obtained after
  5. % calling FT_SOURCEANALYSIS.
  6. %
  7. % An example of a source structure obtained after performing DICS (a frequency
  8. % domain beamformer scanning method) is shown here
  9. %
  10. % pos: [6732x3 double] positions at which the source activity could have been estimated
  11. % inside: [1x3415 double] indices to the positions at which the source activity is actually estimated
  12. % outside: [1x3317 double] indices to the positions at which the source activity has not been estimated
  13. % dim: [xdim ydim zdim] if the positions can be described as a 3D regular grid, this contains the
  14. % dimensionality of the 3D volume
  15. % cumtapcnt: [120x1 double] information about the number of tapers per original trial
  16. % freq: 6 the frequency of the oscillations at which the activity is estimated
  17. % method: 'singletrial' specifies how the data is represented
  18. % cfg: [1x1 struct] the configuration used by the function that generated this data structure
  19. % pow: [6732x120 double] the numeric data
  20. % powdimord: 'pos_rpt' defines how the numeric data has to be interpreted,
  21. % in this case 6732 dipole positions x 120 observations
  22. %
  23. % Required fields:
  24. % - pos, dimord
  25. %
  26. % Optional fields:
  27. % - time, freq, pow, mom, ori, dim, cumtapcnt, channel, other fields with a dimord
  28. %
  29. % Deprecated fields:
  30. % - method
  31. %
  32. % Obsoleted fields:
  33. % - xgrid, ygrid, zgrid, transform, latency, frequency
  34. %
  35. % Revision history:
  36. %
  37. % (2011/latest) The source representation should always be irregular, i.e. not
  38. % a 3-D volume, contain a "pos" field and not contain a "transform".
  39. %
  40. % (2010) The source structure should contain a general "dimord" or specific
  41. % dimords for each of the fields. The source reconstruction in the avg and
  42. % trial substructures has been moved to the toplevel.
  43. %
  44. % (2007) The xgrid/ygrid/zgrid fields have been removed, because they are
  45. % redundant.
  46. %
  47. % (2003) The initial version was defined
  48. %
  49. % See also FT_DATATYPE and FT_DATATYPE_xxx
  50. % Copyright (C) 2011, Robert Oostenveld
  51. %
  52. % This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
  53. % for the documentation and details.
  54. %
  55. % FieldTrip is free software: you can redistribute it and/or modify
  56. % it under the terms of the GNU General Public License as published by
  57. % the Free Software Foundation, either version 3 of the License, or
  58. % (at your option) any later version.
  59. %
  60. % FieldTrip is distributed in the hope that it will be useful,
  61. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  62. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  63. % GNU General Public License for more details.
  64. %
  65. % You should have received a copy of the GNU General Public License
  66. % along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
  67. %
  68. % $Id: ft_datatype_source.m 3039 2011-03-02 10:16:32Z jansch $
  69. % FIXME: I am not sure whether the removal of the xgrid/ygrid/zgrid fields
  70. % was really in 2007
  71. % get the optional input arguments, which should be specified as key-value pairs
  72. version = keyval('version', varargin); if isempty(version), version = 'latest'; end
  73. if strcmp(version, 'latest')
  74. version = '2011';
  75. end
  76. % old data structures may use latency/frequency instead of time/freq. It is
  77. % unclear when these were introduced and removed again, but they were never
  78. % used by any fieldtrip function itself
  79. if isfield(source, 'frequency'),
  80. source.freq = source.frequency;
  81. source = rmfield(source, 'frequency');
  82. end
  83. if isfield(source, 'latency'),
  84. source.time = source.latency;
  85. source = rmfield(source, 'latency');
  86. end
  87. switch version
  88. case '2011'
  89. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  90. if isfield(source, 'xgrid')
  91. source = rmfield(source, 'xgrid');
  92. end
  93. if isfield(source, 'ygrid')
  94. source = rmfield(source, 'ygrid');
  95. end
  96. if isfield(source, 'zgrid')
  97. source = rmfield(source, 'zgrid');
  98. end
  99. if isfield(source, 'transform')
  100. source = rmfield(source, 'transform');
  101. end
  102. % ensure that it has a dimord (or multiple for the different fields)
  103. source = fixdimord(source);
  104. case '2010'
  105. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  106. if isfield(source, 'xgrid')
  107. source = rmfield(source, 'xgrid');
  108. end
  109. if isfield(source, 'ygrid')
  110. source = rmfield(source, 'ygrid');
  111. end
  112. if isfield(source, 'zgrid')
  113. source = rmfield(source, 'zgrid');
  114. end
  115. % ensure that it has a dimord (or multiple for the different fields)
  116. source = fixdimord(source);
  117. case '2007'
  118. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  119. if isfield(source, 'dimord')
  120. source = rmfield(source, 'dimord');
  121. end
  122. if isfield(source, 'xgrid')
  123. source = rmfield(source, 'xgrid');
  124. end
  125. if isfield(source, 'ygrid')
  126. source = rmfield(source, 'ygrid');
  127. end
  128. if isfield(source, 'zgrid')
  129. source = rmfield(source, 'zgrid');
  130. end
  131. case '2003'
  132. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  133. if isfield(source, 'dimord')
  134. source = rmfield(source, 'dimord');
  135. end
  136. if ~isfield(source, 'xgrid') || ~isfield(source, 'ygrid') || ~isfield(source, 'zgrid')
  137. if isfield(source, 'dim')
  138. minx = min(source.pos(:,1));
  139. maxx = max(source.pos(:,1));
  140. miny = min(source.pos(:,2));
  141. maxy = max(source.pos(:,2));
  142. minz = min(source.pos(:,3));
  143. maxz = max(source.pos(:,3));
  144. source.xgrid = linspace(minx, maxx, source.dim(1));
  145. source.ygrid = linspace(miny, maxy, source.dim(2));
  146. source.zgrid = linspace(minz, maxz, source.dim(3));
  147. end
  148. end
  149. otherwise
  150. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  151. error('unsupported version "%s" for source datatype', version);
  152. end