Commit 975ff157 authored by Jay Dubb's avatar Jay Dubb
Browse files

v1.21.3

-- -- Step 2 of changing the way Homer3 stores the group data in memory, how it saves processed data and loads processed and acquired data. Clean up and simplify Calc() method code for generating tHRF_Common in GroupClass and SubjClass.

-- Update Homer3 to preserve capability of handling .nirs files and generating group level processing output.

-- Change the way unit test code modifies AppSettings config file and then restores it to original, in order not to have to revert change for AppSettings.cfg every time after running unit test.  Add userInterrupt function to be able to interrupt a long-running unit test with a Ctrl-C and have it automatically revert to original AppSettings.
parent 1c35139c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ classdef FileLoadSaveClass < matlab.mixin.Copyable
                        
            switch(lower(format))
                case obj.supportedFomats.matlab
                    if ismethod(obj, 'LoadMat', params)
                    if ismethod(obj, 'LoadMat')
                        obj.LoadMat(filename);
                    end
                case obj.supportedFomats.hdf5
+11 −1
Original line number Diff line number Diff line
@@ -256,7 +256,17 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        end
        
        % ---------------------------------------------------------
        function val = GetDataTimeSeries(obj)
        function val = GetDataTimeSeries(obj, options, iBlk)
            val = [];
            if ~exist('options','var')
                options = '';
            end
            if ~exist('iBlk','var') || isempty(iBlk)
                iBlk=1;
            end
            if iBlk>1
            	return
            end
            val = obj.d;
        end
        
+31 −32
Original line number Diff line number Diff line
@@ -396,6 +396,26 @@ classdef GroupClass < TreeNodeClass
        
        
        
        
        
        % ----------------------------------------------------------------------------------
        function LoadVars(obj, s, tHRF_common)
            % Set common tHRF: make sure size of tHRF, dcAvg and dcAvg is same for
            % all subjects. Use smallest tHRF as the common one.
            s.procStream.output.SettHRFCommon(tHRF_common, s.name, s.type);
            
            obj.outputVars.dodAvgSubjs{s.iSubj}    = s.procStream.output.GetVar('dodAvg');
            obj.outputVars.dodAvgStdSubjs{s.iSubj} = s.procStream.output.GetVar('dodAvgStd');
            obj.outputVars.dcAvgSubjs{s.iSubj}     = s.procStream.output.GetVar('dcAvg');
            obj.outputVars.dcAvgStdSubjs{s.iSubj}  = s.procStream.output.GetVar('dcAvgStd');
            obj.outputVars.tHRFSubjs{s.iSubj}      = s.procStream.output.GetTHRF();
            obj.outputVars.nTrialsSubjs{s.iSubj}   = s.procStream.output.GetVar('nTrials');
            obj.outputVars.SDSubjs{s.iSubj}        = s.GetMeasList();
        end
            
            
            
            
        % ----------------------------------------------------------------------------------
        function Calc(obj, options)           
            if ~exist('options','var') || isempty(options)
@@ -413,44 +433,23 @@ classdef GroupClass < TreeNodeClass
            
            % Calculate all subjs in this session
            s = obj.subjs;
            nSubj = length(s);
            nDataBlks = s(1).GetDataBlocksNum();
            tHRF_common = cell(nDataBlks,1);
            for iSubj = 1:nSubj
            tHRF_common = {};
            for iSubj = 1:length(s)
                s(iSubj).Calc();
                
                % Find smallest tHRF among the subjs. We should make this the common one.
                for iBlk = 1:nDataBlks
                    if isempty(tHRF_common{iBlk})
                        tHRF_common{iBlk} = s(iSubj).procStream.output.GetTHRF(iBlk);
                    elseif length(s(iSubj).procStream.output.GetTHRF(iBlk)) < length(tHRF_common{iBlk})
                        tHRF_common{iBlk} = s(iSubj).procStream.output.GetTHRF(iBlk);
                    end
                end
                % Find smallest tHRF among the subjs and make this the common one.
                tHRF_common = s(iSubj).procStream.output.GeneratetHRFCommon(tHRF_common);
            end
           
            
            % Instantiate all the variables that might be needed by
            % procStream.Calc() to calculate proc stream for this group
            vars = [];
            for iSubj = 1:nSubj
                % Set common tHRF: make sure size of tHRF, dcAvg and dcAvg is same for
                % all subjs. Use smallest tHRF as the common one.
                for iBlk = 1:length(tHRF_common)
                    s(iSubj).procStream.output.SettHRFCommon(tHRF_common{iBlk}, s(iSubj).name, s(iSubj).type, iBlk);
                end

                vars.dodAvgSubjs{iSubj}    = s(iSubj).procStream.output.GetVar('dodAvg');
                vars.dodAvgStdSubjs{iSubj} = s(iSubj).procStream.output.GetVar('dodAvgStd');
                vars.dcAvgSubjs{iSubj}     = s(iSubj).procStream.output.GetVar('dcAvg');
                vars.dcAvgStdSubjs{iSubj}  = s(iSubj).procStream.output.GetVar('dcAvgStd');
                vars.tHRFSubjs{iSubj}      = s(iSubj).procStream.output.GetTHRF();
                vars.nTrialsSubjs{iSubj}   = s(iSubj).procStream.output.GetVar('nTrials');
                vars.SDSubjs{iSubj}        = s(iSubj).GetMeasList();
            % Load all the output valiraibles that might be needed by procStream.Calc() to calculate proc stream for this group
            obj.outputVars = [];
            for iSubj = 1:length(s)
                obj.LoadVars(s(iSubj), tHRF_common); 
            end
            
            % Make variables in this group available to processing stream input
            obj.procStream.input.LoadVars(vars);
            obj.procStream.input.LoadVars(obj.outputVars);

            % Calculate processing stream
            obj.procStream.Calc();
+112 −72
Original line number Diff line number Diff line
@@ -40,16 +40,37 @@ classdef ProcResultClass < handle
        end
        
        
        
        % ---------------------------------------------------------------------------
        function SettHRFCommon(obj, tHRF_common, name, type, iBlk)
            if size(tHRF_common,2)<size(tHRF_common,1)
                tHRF_common = tHRF_common';
        function tHRF_common = GeneratetHRFCommon(obj, tHRF_common)
            nDataBlks = obj.GetDataBlocksNum();
            if isempty(tHRF_common)
                tHRF_common = cell(nDataBlks,1);
            end
            
            % Find smallest tHRF among the runs. We should make this the common one.
            for iBlk = 1:nDataBlks
                if isempty(tHRF_common{iBlk})
                    tHRF_common{iBlk} = obj.GetTHRF(iBlk);
                elseif length(obj.GetTHRF(iBlk)) < length(tHRF_common{iBlk})
                    tHRF_common{iBlk} = obj.GetTHRF(iBlk);
                end
            end
        end
        
        
        
        % ---------------------------------------------------------------------------
        function SettHRFCommon(obj, tHRF_common, name, type)
            for iBlk = 1:length(tHRF_common)
                if size(tHRF_common{iBlk},2)<size(tHRF_common{iBlk},1)
                    tHRF_common{iBlk} = tHRF_common{iBlk}';
                end
                t = obj.GetTHRF(iBlk);
                if isempty(t)
                    return;
                end
            n = length(tHRF_common);
                n = length(tHRF_common{iBlk});
                m = length(t);
                d = n-m;
                if d<0
@@ -97,10 +118,12 @@ classdef ProcResultClass < handle
                        end
                    end
                end
            obj.tHRF = tHRF_common;
                obj.tHRF = tHRF_common{iBlk};
            end
        end
        
        
        
        % ----------------------------------------------------------------------------------
        function var = GetVar(obj, varname, iBlk)
            var = [];
@@ -467,16 +490,33 @@ classdef ProcResultClass < handle
        % ----------------------------------------------------------------------------------
        function n = GetDataBlocksNum(obj)
            n = 0;
                
            if ~isempty(obj.dcAvg)
                if isnumeric(obj.dcAvg)
                    n = 1;
                else
                    n = length(obj.dcAvg);
                end
            elseif ~isempty(obj.dodAvg)
                if isnumeric(obj.dodAvg)
                    n = 1;
                else
                    n = length(obj.dodAvg);
                end
            elseif ~isempty(obj.dc)
                if isnumeric(obj.dc)
                    n = 1;
                else
                    n = length(obj.dc);
                end
            elseif ~isempty(obj.dod)
                if isnumeric(obj.dod)
                    n = 1;
                else
                    n = length(obj.dod);
                end
            end
        end
        
    end
    
+8 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ classdef ProcStreamClass < handle
            obj.config = struct('procStreamCfgFile','', 'defaultProcStream','','suffix','');
            cfg = ConfigFileClass();
            obj.config.procStreamCfgFile    = cfg.GetValue('Processing Stream Config File');
            obj.config.regressionTestActive = cfg.GetValue('Regression Test Active');
            copyOptions = '';
            if strcmpi(obj.getDefaultProcStream(), '_nirs')
                copyOptions = 'extended';
@@ -206,9 +207,13 @@ classdef ProcStreamClass < handle
                    eval( fcall );
                catch ME
                    msg = sprintf('Function %s generated error at line %d: %s', obj.fcalls(iFcall).name, ME.stack(1).line, ME.message);
                    menu(msg,'OK');
                    if strcmp(obj.config.regressionTestActive, 'false')
                        MessageBox(msg);
                    elseif strcmp(obj.config.regressionTestActive, 'false')
                        fprintf('%s\n', msg);
                    end
                    close(hwait);
                    assert(false, msg);
                    rethrow(ME)
                end
                
                %%%% Parse output parameters
Loading