forked from optospinlab/modularControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcProcessedData.m
More file actions
147 lines (112 loc) · 6.31 KB
/
Copy pathmcProcessedData.m
File metadata and controls
147 lines (112 loc) · 6.31 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
classdef mcProcessedData < handle
% mcProcessedData contains, as the name might suggest, a processed version
% of the N-dimensional data stored in a mcData structure. The data can be 1D (plot) or 2D
% (colormap) (and maybe eventually 3D). The parent mcData structure is
% referenced in 'parent'. The data that is processed is 'data'. The
% parameters that define the proccessing procedure is defined in 'params'.
%
% Syntax:
% pd = mcProcessedData(parent) % Proccess parent data (mcData) with default settings
% pd = mcProcessedData(parent, params) % Proccess parent data (mcData) with settings defined by 'params'
%
% Status: Mostly finished, but has no clue what to do when data is not numeric (3D not done also). params not currently used,
% but probably will be when RGB is implemented.
% Update 12/21: Revising; above is no longer accurate.
properties
parent = []; % Parent mcData class.
viewer = []; % Parent(ish) mcViewer class.
listener = []; % Listens to changes in parent.
input = 1; % Input to proccess...
end
properties (SetObservable)
data = NaN;
end
methods
function pd = mcProcessedData(varin)
if nargin == 1
pd.parent = varin;
elseif nargin == 2
pd.parent = varin{1};
end
prop = findprop(pd.parent, 'd');
pd.listener.d = event.proplistener(pd.parent, prop, 'PostSet', @pd.parentChanged_Callback);
prop2 = findprop(pd.parent, 'r');
pd.listener.r = event.proplistener(pd.parent, prop2, 'PostSet', @pd.parentChanged_Callback);
end
function m = min(pd)
m = min(min(min(pd.data)));
end
function M = max(pd)
M = max(max(max(pd.data)));
end
function parentChanged_Callback(pd, ~, ~)
pd.process();
end
function process(pd)
% pd.parent.r == pd
% pd
% pd.parent.dataViewer.r
if (pd.parent.dataViewer.isRGB || pd.parent.dataViewer.r == pd) && pd.parent.dataViewer.shouldPlot
switch pd.parent.r.plotMode
case {0, 'histogram'}
% Do nothing.
pd.parent.dataViewer.plotData_Callback(0,0);
case {1, '1D'}
selTypeX = pd.parent.r.l.type(pd.parent.r.l.layer == 1);
if ~(selTypeX == 0 || selTypeX == pd.input)
error('mcProcessedData.proccess(): mcDataViewer should prevent this from happening')
end
relevant = pd.parent.r.l.type == 0 | pd.parent.r.l.type == pd.input;
nums = 1:length(pd.parent.r.l.layer);
nums(relevant)= 1:sum(relevant); % This is neccessary if there are multiple inputs.
toMean = relevant & pd.parent.r.l.layer == 2;
d = pd.parent.d.data{pd.input};
for ii = nums(toMean)
d = nanmean(d, ii);
end
final = relevant & pd.parent.r.l.lengths ~= 1 & pd.parent.r.l.layer ~= 2; % If relevant and not singleton or meaned.
d = squeeze(d); % Remove singleton dimensions (whether natural or meaned).
nums = 1:length(final);
axisXindex = nums(pd.parent.r.l.layer(final) == 1);
pd.data = d( getIndex(pd.parent.r.l.lengths(final), pd.parent.r.l.layer(final) - 2, axisXindex) );
case {2, '2D'}
selTypeX = pd.parent.r.l.type(pd.parent.r.l.layer == 1);
selTypeY = pd.parent.r.l.type(pd.parent.r.l.layer == 2);
% selTypeX = pd.parent.r.l.type(pd.parent.r.l.layer == 1)
% selTypeY = pd.parent.r.l.type(pd.parent.r.l.layer == 2)
% in = pd.input
% len = pd.parent.r.l.lengths
% l = pd.parent.r.l.layer
% t = pd.parent.r.l.type
if isempty(selTypeX) || isempty(selTypeY)
warning('mcProcessedData(): Layer has not updated properly...');
return;
end
% tx = selTypeX == 0 || selTypeX == pd.input
% ty = selTypeY == 0 || selTypeY == pd.input
if ~(selTypeX == 0 || selTypeX == pd.input) || ~(selTypeY == 0 || selTypeY == pd.input)
error('mcProcessedData.proccess(): mcDataViewer should prevent this from happening')
end
relevant = pd.parent.r.l.type == 0 | pd.parent.r.l.type == pd.input;
nums = 1:length(pd.parent.r.l.layer);
nums(relevant)= 1:sum(relevant); % This is neccessary if there are multiple inputs.
toMean = relevant & pd.parent.r.l.layer == 3;
d = pd.parent.d.data{pd.input};
for ii = nums(toMean)
d = nanmean(d, ii);
end
final = relevant & pd.parent.r.l.lengths ~= 1 & pd.parent.r.l.layer ~= 3; % If relevant and not singleton or meaned.
d = squeeze(d); % Remove singleton dimensions (whether natural or meaned).
nums = 1:length(final);
axisXindex = nums(pd.parent.r.l.layer(final) == 1);
axisYindex = nums(pd.parent.r.l.layer(final) == 2);
pd.data = d( getIndex(pd.parent.r.l.lengths(final), pd.parent.r.l.layer(final) - 3, axisXindex, axisYindex) );
case {3, '3D'}
error('3D NotImplemented');
otherwise
error('Plotmode not recognized...');
end
end
end
end
end