|
| 1 | +classdef AcqDataClass < matlab.mixin.Copyable |
| 2 | + |
| 3 | + properties (Access = private) |
| 4 | + logger |
| 5 | + end |
| 6 | + properties (Access = protected) |
| 7 | + errmsgs |
| 8 | + end |
| 9 | + |
| 10 | + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 11 | + % These methods must be implemented in any derived class |
| 12 | + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 13 | + methods(Abstract) |
| 14 | + |
| 15 | + % --------------------------------------------------------- |
| 16 | + objnew = GetFormatVersion(obj, options); |
| 17 | + |
| 18 | + % --------------------------------------------------------- |
| 19 | + val = GetFormatVersionString(obj); |
| 20 | + |
| 21 | + % --------------------------------------------------------- |
| 22 | + t = GetTime(obj, iBlk) |
| 23 | + |
| 24 | + % --------------------------------------------------------- |
| 25 | + datamat = GetDataTimeSeries(obj, options, iBlk) |
| 26 | + |
| 27 | + % --------------------------------------------------------- |
| 28 | + SD = GetSDG(obj,option) |
| 29 | + |
| 30 | + % --------------------------------------------------------- |
| 31 | + srcpos = GetSrcPos(obj,option) |
| 32 | + |
| 33 | + % --------------------------------------------------------- |
| 34 | + detpos = GetDetPos(obj,option) |
| 35 | + |
| 36 | + % --------------------------------------------------------- |
| 37 | + ml = GetMeasList(obj, iBlk) |
| 38 | + |
| 39 | + |
| 40 | + % --------------------------------------------------------- |
| 41 | + wls = GetWls(obj) |
| 42 | + |
| 43 | + % --------------------------------------------------------- |
| 44 | + SetStims_MatInput(obj, s, t, CondNames) |
| 45 | + |
| 46 | + % --------------------------------------------------------- |
| 47 | + s = GetStims(obj, t) |
| 48 | + |
| 49 | + % --------------------------------------------------------- |
| 50 | + CondNames = GetConditions(obj) |
| 51 | + |
| 52 | + |
| 53 | + % --------------------------------------------------------- |
| 54 | + SetConditions(obj, CondNames) |
| 55 | + |
| 56 | + % --------------------------------------------------------- |
| 57 | + aux = GetAuxiliary(obj) |
| 58 | + |
| 59 | + % --------------------------------------------------------- |
| 60 | + SetStimDuration(obj, icond, duration); |
| 61 | + |
| 62 | + % --------------------------------------------------------- |
| 63 | + duration = GetStimDuration(obj, icond); |
| 64 | + |
| 65 | + % --------------------------------------------------------- |
| 66 | + n = GetDataBlocksNum(obj); |
| 67 | + |
| 68 | + % --------------------------------------------------------- |
| 69 | + [iDataBlks, ich] = GetDataBlocksIdxs(obj, ich); |
| 70 | + |
| 71 | + % --------------------------------------------------------- |
| 72 | + objnew = CopyMutable(obj, options); |
| 73 | + |
| 74 | + end |
| 75 | + |
| 76 | + |
| 77 | + methods |
| 78 | + |
| 79 | + % ------------------------------------------------------- |
| 80 | + function Initialize(obj) |
| 81 | + global logger |
| 82 | + obj.logger = InitLogger(logger); |
| 83 | + end |
| 84 | + |
| 85 | + |
| 86 | + % ------------------------------------------------------- |
| 87 | + function err = Error(obj) |
| 88 | + err = obj.GetError(); |
| 89 | + end |
| 90 | + |
| 91 | + |
| 92 | + % --------------------------------------------------------- |
| 93 | + function msg = GetErrorMsg(obj) |
| 94 | + msg = ''; |
| 95 | + if isempty(obj) |
| 96 | + msg = 'AcqDataClass object is empty'; |
| 97 | + return; |
| 98 | + end |
| 99 | + if isempty(obj.errmsgs) |
| 100 | + return; |
| 101 | + end |
| 102 | + if ~obj.GetError() |
| 103 | + return; |
| 104 | + end |
| 105 | + msg = obj.errmsgs{abs(obj.GetError())}; |
| 106 | + end |
| 107 | + |
| 108 | + |
| 109 | + % ------------------------------------------------------- |
| 110 | + function FreeMemory(obj, filename) |
| 111 | + if ~exist('filename','var') |
| 112 | + filename = ''; |
| 113 | + end |
| 114 | + if isempty(filename) |
| 115 | + return; |
| 116 | + end |
| 117 | + obj.Initialize(); |
| 118 | + end |
| 119 | + |
| 120 | + |
| 121 | + % --------------------------------------------------------- |
| 122 | + function bbox = GetSdgBbox(obj) |
| 123 | + bbox = []; |
| 124 | + |
| 125 | + optpos = [obj.GetSrcPos('2D'); obj.GetDetPos('2D')]; |
| 126 | + if isempty(optpos) |
| 127 | + return |
| 128 | + end |
| 129 | + |
| 130 | + xmax = max(optpos(:,1)); |
| 131 | + ymax = max(optpos(:,2)); |
| 132 | + |
| 133 | + xmin = min(optpos(:,1)); |
| 134 | + ymin = min(optpos(:,2)); |
| 135 | + |
| 136 | + width = xmax-xmin; |
| 137 | + height = ymax-ymin; |
| 138 | + |
| 139 | + if width==0 |
| 140 | + width = 1; |
| 141 | + end |
| 142 | + if height==0 |
| 143 | + height = 1; |
| 144 | + end |
| 145 | + |
| 146 | + px = width * 0.05; |
| 147 | + py = height * 0.05; |
| 148 | + |
| 149 | + bbox = [xmin-px, xmax+px, ymin-py, ymax+py]; |
| 150 | + end |
| 151 | + |
| 152 | + |
| 153 | + % ---------------------------------------------------------------------------------- |
| 154 | + function varval = GetVar(obj, varname) |
| 155 | + if ismethod(obj,['Get_', varname]) |
| 156 | + varval = eval( sprintf('obj.Get_%s()', varname) ); |
| 157 | + elseif ismethod(obj,['Get', varname]) |
| 158 | + varval = eval( sprintf('obj.Get%s()', varname) ); |
| 159 | + elseif isproperty(obj, varname) |
| 160 | + varval = eval( sprintf('obj.%s', varname) ); |
| 161 | + else |
| 162 | + varval = []; |
| 163 | + end |
| 164 | + |
| 165 | + % If varval is a class object with an IsEmpty() method and length of varval is one or |
| 166 | + % less, then use it determine whether it's valid. If not, return empty as if it were |
| 167 | + % really empty. This is useful when we want to copy only part of an object to save on space. |
| 168 | + % For instance to reconstruct nirs style 's' variable from a SNIRF stim object we need the t |
| 169 | + % property from a SNIRF data container, but we only need that one property not the whole thing |
| 170 | + % so we initilize only the t property. We don't want this partially initialized data object |
| 171 | + % to be found (by GetVar) and used directly in the proc stream processing, we only want to use |
| 172 | + % indirectly to retrieve s from stim. So we do this check to see if it's valid. It won't be |
| 173 | + % since it's only partially initialized. |
| 174 | + if isa(varval, 'handle') && ismethod(varval,'IsEmpty') |
| 175 | + if length(varval)==1 && varval(1).IsEmpty() |
| 176 | + varval = []; |
| 177 | + end |
| 178 | + end |
| 179 | + end |
| 180 | + |
| 181 | + |
| 182 | + % ---------------------------------------------------------------------------------- |
| 183 | + function t = GetTimeCombined(obj) |
| 184 | + % Function combines the time vectors for all data blocks into one time vectors. |
| 185 | + t = obj.GetTime(1); |
| 186 | + tStart = t(1); |
| 187 | + tEnd = t(end); |
| 188 | + tStep = mean(diff(t)); |
| 189 | + |
| 190 | + nBlks = obj.GetDataBlocksNum(); |
| 191 | + for iBlk=2:nBlks |
| 192 | + t = obj.GetTime(iBlk); |
| 193 | + if t(1) < tStart |
| 194 | + tStart = t(1); |
| 195 | + end |
| 196 | + if t(end) > tEnd |
| 197 | + tEnd = t(end); |
| 198 | + end |
| 199 | + if mean(diff(t)) < tStep |
| 200 | + tStep = mean(diff(t)); |
| 201 | + end |
| 202 | + end |
| 203 | + t = tStart:tStep:tEnd; |
| 204 | + end |
| 205 | + |
| 206 | + |
| 207 | + % ---------------------------------------------------------------------------------- |
| 208 | + function data = GetStimData(~, ~) |
| 209 | + data = []; |
| 210 | + end |
| 211 | + |
| 212 | + |
| 213 | + % ---------------------------------------------------------------------------------- |
| 214 | + function val = GetStimDataLabels(~, ~) |
| 215 | + val = {}; |
| 216 | + end |
| 217 | + |
| 218 | + |
| 219 | + % ---------------------------------------------------------------------------------- |
| 220 | + function b = equal(obj, obj2) |
| 221 | + b = true; |
| 222 | + if isempty(obj.GetFilename) |
| 223 | + return; |
| 224 | + end |
| 225 | + if isempty(obj2.GetFilename) |
| 226 | + return; |
| 227 | + end |
| 228 | + [~, fname1, ext1] = fileparts(obj.GetFilename); |
| 229 | + [~, fname2, ext2] = fileparts(obj2.GetFilename); |
| 230 | + if ~strcmpi([fname1, ext1], [fname2, ext2]) |
| 231 | + b = false; |
| 232 | + end |
| 233 | + end |
| 234 | + |
| 235 | + |
| 236 | + % ---------------------------------------------------------------------------------- |
| 237 | + function status = Mismatch(obj, obj2) |
| 238 | + status = 0; |
| 239 | + msg = {}; |
| 240 | + if ~exist('obj2','var') |
| 241 | + return; |
| 242 | + end |
| 243 | + if ~obj.equal(obj2) |
| 244 | + [~, fname, ext] = fileparts(obj.GetFilename); |
| 245 | + msg{1} = sprintf('WARNING: The acquisition file "%s" does not match the derived data in this group folder. ', [fname, ext]); |
| 246 | + msg{2} = sprintf('Are you sure this acquisition file belongs in this group folder?'); |
| 247 | + obj.logger.Write([msg{:}]) |
| 248 | + end |
| 249 | + end |
| 250 | + |
| 251 | + |
| 252 | + |
| 253 | + end |
| 254 | + |
| 255 | +end |
0 commit comments