Commit 1ac7f226 authored by Jay Dubb's avatar Jay Dubb
Browse files

v1.30.2

-- Add functionality to allow unit testing of MainGUI and add unit test that launches MainGUI and generates HRF for group. The biggest change is in MainGUI and supporting graphics functions to always specify the axes handle for built-in axes display functions such plot, hold, xlim, ylim, xlabel, ylabel, legend, etc. rather than letting the axes defalt to gca.

-- Add UnitTestsAll_MainGUI to UnitTestsAll to run some basic checks on MainGUI.

-- Fix broken unit tests because the user function hmrR_Intensity2OD was changed to prompt user for input if input data was negative. Changed hmrR_Intensity2OD to detect when it is being run in unit test and with global UNIT_TEST variable and to not accept user input in that case if it is set to true.
parent 1cafc060
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -579,6 +579,14 @@ classdef DataTreeClass < handle
        end
        
        
        % ----------------------------------------------------------
        function ResetAll(obj)
            for ii = 1:length(obj.groups)
                obj.groups(ii).Reset()
            end
        end
        
        
        % ----------------------------------------------------------
        function b = IsEmpty(obj)
            b = true;
+36 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ dod = DataClass().empty();
for ii=1:length(intensity)
    dod(ii) = DataClass();
    d = intensity(ii).GetDataTimeSeries();
 
    d = ErrorCheck(d);
 
    dm = mean(abs(d),1);
    nTpts = size(d,1);
    dod(ii).SetTime(intensity(ii).GetTime());
@@ -30,3 +33,36 @@ for ii=1:length(intensity)
    dod(ii).SetMl(intensity(ii).GetMl());
    dod(ii).SetDataTypeDod();
end



%---------------------------------------------------------
function d = ErrorCheck(d)
global UNIT_TEST

if ~isempty(UNIT_TEST) && UNIT_TEST
    return;
end

% Optional (user prompt): Adding dc offset if intensity (d) has negative values
if ~isempty(d(d<=0))
    quest = {'Intensity signal has negative values. If you would like to add a dc offset, please click YES. If you would like to proceed with negative values, hit CANCEL.'};
    dlgtitle = 'Warning';
    btn1 = 'YES';
    btn2 = 'CANCEL';
    detbtn = btn1;
    answer = questdlg(quest,dlgtitle,btn1,btn2,detbtn);
    switch answer
        case 'YES'
            for j = 1:size(d,2)
                foo = d(:,j);
                if ~isempty(foo<0)
                    d(:,j) = foo + abs(min(foo));
                    foo = d(:,j);
                end
                if ~isempty(foo == 0)
                    d(:,j) = foo + min(foo(foo > 0));
                end
            end
    end
end
+17 −11
Original line number Diff line number Diff line
function Homer3(groupDirs, inputFileFormat)
function unitTest = Homer3(groupDirs, inputFileFormat, unitTest)

%  Syntax:
%       Homer3(groupDirs, inputFileFormat)
%       unitTest = Homer3(groupDirs, inputFileFormat)
%   
%  Examples:
%
@@ -10,9 +10,6 @@ function Homer3(groupDirs, inputFileFormat)
%

global logger
logger = Logger('Homer3');

logger.CurrTime();

if ~exist('groupDirs','var') || isempty(groupDirs)
    groupDirs = filesepStandard(pwd);
@@ -20,15 +17,24 @@ end
if ~exist('inputFileFormat','var') || isempty(inputFileFormat)
    inputFileFormat = '.snirf';
end
cfg = ConfigFileClass();
if ~exist('unitTest','var')
    unitTest = [];
end

if isempty(unitTest)
    logger = Logger('Homer3');
elseif unitTest.IsEmpty()
    logger = InitLogger(logger);
else
    return;
end
logger.CurrTime();
cfg = ConfigFileClass();
if strcmp(cfg.GetValue('Logging'), 'off')
    logger.SetDebugLevel(logger.Null());
end

PrintSystemInfo(logger, 'Homer3');
checkForHomerUpdates();

logger.Write(sprintf('Opened application config file %s\n', cfg.filename))
gdir = cfg.GetValue('Last Group Folder');
if isempty(gdir)
@@ -38,11 +44,11 @@ if isempty(gdir)
end

try
    MainGUI(groupDirs, inputFileFormat, logger, 'userargs');
    unitTest = MainGUI(groupDirs, inputFileFormat, unitTest, 'userargs');    
catch ME
    % Clean up in case of error make sure all open file handles are closed 
    % so we don't leave the application in a bad state
    logger.Close()
    rethrow(ME)
    logger.Close();
    rethrow(ME);
end
+18 −7
Original line number Diff line number Diff line
@@ -36,8 +36,9 @@


% --------------------------------------------------------------------
function DisplayAxesSDG(hAxes)
function DisplayAxesSDG(handles)
global maingui
global UNIT_TEST

tic;

@@ -45,8 +46,13 @@ tic;
% Command line call:
% plotAxes_SDG(guidata(gcbo),bool);
%
if nargin<1
    hAxes   = maingui.axesSDG.handles.axes;
if nargin==0
    return;
end
if ~ishandles(handles)
    hAxes = handles.axesSDG;
else
    hAxes = handles;    
end
iCh         = maingui.axesSDG.iCh;
iSrcDet     = maingui.axesSDG.iSrcDet;
@@ -65,8 +71,10 @@ end
if ~ishandles(hAxes)
    return;
end

% Set gca to be SDG axes
axes(hAxes);

% Delete all channel lines drawn
if ishandles(maingui.axesSDG.handles.ch)
    delete(maingui.axesSDG.handles.ch)
@@ -77,6 +85,7 @@ if isfield(maingui.axesSDG, 'xlim')
else
    axis(hAxes, [bbox(1), bbox(2), bbox(3), bbox(4)]);
end

%set(hAxes, 'xticklabel','', 'yticklabel','', 'xgrid','off, ygrid','off')
set(hAxes, 'xticklabel','')
bttndownfcn = get(hAxes,'ButtonDownFcn');
@@ -115,7 +124,7 @@ hCh = zeros(length(lstML),1);

% Draw all channels
for ii = 1:length(lstML)
    hCh(ii) = line2(SD.SrcPos(ml(lstML(ii),1),:), SD.DetPos(ml(lstML(ii),2),:), [], gridsize);
    hCh(ii) = line2(SD.SrcPos(ml(lstML(ii),1),:), SD.DetPos(ml(lstML(ii),2),:), [], gridsize, hAxes);
    if ismember(ii,lstExclAuto)
        % Draw auto-excluded channel
        col = [1.00 0.6 0.6];
@@ -148,7 +157,7 @@ if ~isempty(iSrcDet) && iSrcDet(1,1)~=0
    
    for idx = 1:size(iSrcDet,1)
        lwidth = 3;
        hCh(idx+ii) = line2(SD.SrcPos(iSrcDet(idx,1),:), SD.DetPos(iSrcDet(idx,2),:), [], gridsize);
        hCh(idx+ii) = line2(SD.SrcPos(iSrcDet(idx,1),:), SD.DetPos(iSrcDet(idx,2),:), [], gridsize, hAxes);
        % Attach toggle callback to the selected channels for function on
        % second click
        set(hCh(idx+ii),'color',color(idx,:), 'ButtonDownFcn',sprintf('toggleLinesAxesSDG_ButtonDownFcn(gcbo,[%d],guidata(gcbo))',idx), 'linewidth',2);
@@ -198,7 +207,9 @@ else
end

% Turn off zoom but only for SDG axes
h=zoom;
h = zoom(hAxes);
if isempty(UNIT_TEST) || ~UNIT_TEST
    setAllowAxesZoom(h, hAxes, 0);
end

% fprintf('DisplayAxesSDG: Elapsed Time - %0.3f\n', toc);
+3 −3
Original line number Diff line number Diff line
function DisplayDataConc(t, d, dStd, hbType, ch, chLst, nTrials, condition, linecolor, linestyle)
function DisplayDataConc(hAxes, t, d, dStd, hbType, ch, chLst, nTrials, condition, linecolor, linestyle)

% Parse args
if ~exist('t','var')
@@ -44,7 +44,7 @@ end
for iHb=1:length(hbType)
    for ii=length(ch(chLst)):-1:1
        dHbMl = squeeze(d(:, hbType(iHb), ch(chLst(ii))));
        h     = plot(t, dHbMl);
        h     = plot(hAxes, t, dHbMl);
        
        % fprintf('Plotting channel: %d, color: [%0.1f, %0.1f, %0.1f]\n', chLst(ii), linecolor(chLst(ii),:));
        set(h, 'color', linecolor(chLst(ii),:));
@@ -55,7 +55,7 @@ for iHb=1:length(hbType)
            dHbMlStd    = squeeze(dStd( :, hbType(iHb), ch(chLst(ii)) ));
            dHbMlStdErr = dHbMlStd./sqrt(nTrials(condition));
            idx         = [1:10:length(t)];
            h2          = errorbar(t(idx), dHbMl(idx), dHbMlStdErr(idx),'.');
            h2          = errorbar(hAxes, t(idx), dHbMl(idx), dHbMlStdErr(idx),'.');
            set(h2,'color',linecolor(chLst(ii),:));
        end
    end
Loading