-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssm_plotOnMesh.m
127 lines (101 loc) · 3.88 KB
/
ssm_plotOnMesh.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
function fH = ssm_plotOnMesh(sensor_data, title_txt, figure_num, data_hdr, plotType, highlightChannels, channelVis)
%Plot a surface map of the MEG sensor data
% fH = ssm_plotOnMesh(sensor_data, [title_txt], [figure_num], meg_files, [plotType], [highlightChannels], [channelVis])
%
% Inputs
% sensor_data: 1x157 vector of sensor data (if longer than 157, then
% truncate)
% title: optional string for title of plot
% figure_num: optional integer to specify figure number
% plotType: any of '2d', '3d', 'both'
%
% Output
% fH: figure handle (integer)
%
% Example:
% fH = ssm_plotOnMesh(randn(1,157), 'my random data', 999);
% check inputs
if ~exist('plotType', 'var') || isempty(plotType), plotType = 'both'; end
if ~exist('highlightChannels', 'var') || isempty(highlightChannels), highlightChannels = []; end
if ~exist('channelVis','var') || isempty(channelVis), channelVis = 'off'; end
% check length of sensor data
if length(sensor_data) > 157, sensor_data = sensor_data(1:157); end
%% Old mesh
% % Build an interpolant function of the z-dimension of the sensor locations
% F.z = TriScatteredInterp(xyz(:,1), xyz(:,2), xyz(:,3), 'natural');
%
% % Build an interpolant function of the sensor data
% F.data = TriScatteredInterp(xyz(:,1), xyz(:,2), sensor_data(1:157)', 'natural');
%
% % Sample the interpolant at these grid points
% % Grid ranges from -15 to +15 as the stored xyz values range from ~ -13 to 13
% ti = -15:1:15;
% [qx,qy] = meshgrid(ti,ti);
% qz = F.z(qx,qy);
%
% sensor_data_interpolated = F.data(qx,qy);
%% New mesh - Requires fieldtrip
% add fieldtrip matlab code
if isempty(which('ft_analysispipeline')),
addpath(genpath('/Volumes/server/Projects/MEG/code/fieldtrip'));
end
switch lower(plotType)
case {'3d', 'both'}
% Load the sensor positions in 3 space
tmp = load('meg160xyz');
xyz = tmp.xyz;
% set up figure
if exist('figure_num', 'var'), fH = figure(figure_num); clf;
else fH = figure; clf; end
set(fH, 'Color', 'w')
% Get labels
colorbar
ylabel(' Right Left ')
xlabel(' Posterior Anterior ')
zlabel(' Inferior Superior ')
ft_plot_topo3d(xyz,sensor_data); hold on;
label_add(xyz)
% add a title if requested
if exist('title_txt', 'var') && ~isempty(title_txt), title(title_txt); end
end
%% NEW TOPOPLOT
switch lower(plotType)
case {'2d', 'both'}
% rawdir = '/Volumes/server/Projects/MEG/SSMEG/02_SSMEG_02_28_2014/raw';
%if notDefined('meg_files')
% meg_files = dir(fullfile(rawdir,'*.sqd'));
%end
% data_hdr = ft_read_header(fullfile(rawdir,meg_files(1).name));
if notDefined('data_hdr')
data_hdr = load('hdr'); data_hdr = data_hdr.hdr;
end
cfg=[];
cfg.interpolation = 'nearest';
% cfg.interpolation = 'v4';
cfg.layout = ft_prepare_layout(cfg, data_hdr);
cfg.style='straight';
% cfg.style='blank';
cfg.electrodes = channelVis;
% cfg.electrodes ='numbers';
% cfg.electrodes = 'off';
% cfg.electrodes = 'on';
if ~isempty(highlightChannels)
cfg.electrodes = 'on';
cfg.highlight = highlightChannels;
cfg.hlcolor = [1 1 1];
end
% cfg.colorbar='yes';
cfg.colorbar='no';
cfg.maplimits='maxmin';
cfg.data = sensor_data';
for ii = 1:length(cfg.data)
if isnan(cfg.data(ii))
cfg.data(ii) = nanmedian(sensor_data);
end
end
%figure; clf;
topoplot(cfg,cfg.data);
fH = gcf;
% add a title if requested
if exist('title_txt', 'var') && ~isempty(title_txt), title(title_txt); end
end