Unverified Commit 34c2eb77 authored by stephen scott tucker's avatar stephen scott tucker Committed by GitHub
Browse files

v1.30.5 -- Param errchk (#46)



* prevented ArgClass Extract from indexing into empty list

* FuncCallClass GetInputs and GetOutputs convenience function for returning strings

* GetProcInputs method returns all properties of ProcInputClass for use with proc stream checking

* Processing stream is only run if Check returns zero, else an error msg is raised

* Changed uses of properties to propnames in ProcInputClass GetProcInputs

* Added default property to ParamClass to store values defined in cfg files and registry

* Parameter definition uses new default property

* EditParam method of ProcStreamClass uses parameter defaults to resolve bad edits

* ProcStreamOptionsGUI is more robust to bad edits

* Added CheckParams method to FuncCallClass which calls errchk function associated with user function if it exists

* Added convenience function to return script-friendly version of param value

* Demo errchk function for hmrR_GLM

* Updated helpstring to reflect new ProcStreamOptionsGUI constraints

* CheckParams called on parameter edit

* CheckParams called on proc stream calc

* prevented ArgClass Extract from indexing into empty list

* FuncCallClass GetInputs and GetOutputs convenience function for returning strings

* GetProcInputs method returns all properties of ProcInputClass for use with proc stream checking

* Processing stream is only run if Check returns zero, else an error msg is raised

* Changed uses of properties to propnames Util fn

* Added explicit list of prereqs to ignore to allow fns like tCCA to work before processing stream has been run

* Added a few more excluded arguments from prereq flagging

* Added Prerequisites to help function

* Registries GetEntryByName function, Proc stream Check rework

* Suppressed debug

* CheckOrder implemented at run, subj, group levels-- only checks runs for now

* Improved string parsing and error dialog on procstream save

* Merge development branch GLM function

* Introduced the Edit method of ParamClass for variable format; removed constraints on parameter length

* Updated hmrR_errchk with c_vector param

* Version 1.30.4

* v1.30.5

Co-authored-by: default avatardejar14 <67239853+dejar14@users.noreply.github.com>
Co-authored-by: default avatarjayd1860 <44243610+jayd1860@users.noreply.github.com>
parent 28a3bbc6
Loading
Loading
Loading
Loading
+28 −8
Original line number Original line Diff line number Diff line
@@ -31,7 +31,7 @@ classdef FuncCallClass < handle
            %        argOut.str: 'dod'
            %        argOut.str: 'dod'
            %         argIn.str: '(dod,t'
            %         argIn.str: '(dod,t'
            %          paramIn: [1x2 ParamClass]
            %          paramIn: [1x2 ParamClass]
            %             help: '  Perform a bandpass filter'
            %             help: '  Perform a bandpass filter'
            %
            %
            obj.name       = '';
            obj.name       = '';
            obj.nameUI     = '';
            obj.nameUI     = '';
@@ -256,7 +256,7 @@ classdef FuncCallClass < handle
            %        argOut: 'dod'
            %        argOut: 'dod'
            %         argIn.str: '(dod,t'
            %         argIn.str: '(dod,t'
            %       paramIn: [1x2 ParamClass]
            %       paramIn: [1x2 ParamClass]
            %          help: '  Perform a bandpass filter'
            %          help: '  Perform a bandpass filter'
            %   
            %   
            obj.err = 0;            
            obj.err = 0;            
            if nargin<2
            if nargin<2
@@ -341,7 +341,8 @@ classdef FuncCallClass < handle
                            end
                            end
                        end
                        end
                        pvalue = str2num(textstr{ii+2});                       
                        pvalue = str2num(textstr{ii+2});                       
                        obj.paramIn(end+1) = ParamClass(pname, pformat, pvalue);
                        % Save default values in ParamClass
                        obj.paramIn(end+1) = ParamClass(pname, pformat, pvalue, pvalue);
                        obj.GetParamHelp(length(obj.paramIn));
                        obj.GetParamHelp(length(obj.paramIn));
                        flag = 2;
                        flag = 2;
                    end
                    end
@@ -415,11 +416,9 @@ classdef FuncCallClass < handle
                if length(obj.paramIn) ~= length(obj2.paramIn)
                if length(obj.paramIn) ~= length(obj2.paramIn)
                    return;
                    return;
                end
                end
                for ii=1:length(obj.paramIn)
%               Must have the same number of params, but their individual
                    if obj.paramIn(ii) ~= obj2.paramIn(ii)
%               lengths can differ
                        return;

                    end
                end
            elseif isstruct(obj2)
            elseif isstruct(obj2)
                % Name 
                % Name 
                k = find(obj.name=='_');
                k = find(obj.name=='_');
@@ -622,6 +621,27 @@ classdef FuncCallClass < handle
            nbytes = sum(nbytes);
            nbytes = sum(nbytes);
        end
        end


        % ----------------------------------------------------------------------------------        
        function errmsg = CheckParams(obj)
            errmsg = '';
            paramValStr = '';
            if exist([obj.name, '_errchk'], 'file')  % If errchk fn is on path
                for i = 1:length(obj.paramIn)  % Assemble list of args
                   paramValStr = [paramValStr, obj.paramIn(i).GetFormattedValue()]; %#ok<AGROW>
                   if i < length(obj.paramIn)
                       paramValStr = [paramValStr, ',']; %#ok<AGROW>
                   end
                end
                % Call the errchk function which returns a non-empty string
                % if there is an error
                eval(['errmsg = ', obj.name, '_errchk(', paramValStr, ')']);
                if ~isempty(errmsg)
                   errmsg = [obj.name, ': ', errmsg];
                end
            else
               return;
            end
        end
        
        
        % ----------------------------------------------------------------------------------        
        % ----------------------------------------------------------------------------------        
        function val = GetVar(obj, name)
        function val = GetVar(obj, name)
+37 −4
Original line number Original line Diff line number Diff line
@@ -2,8 +2,9 @@ classdef ParamClass < matlab.mixin.Copyable
    
    
    properties
    properties
        name
        name
        value
        value       % Current value of parameter
        format
        default     % Default value loaded from the function helpstring
        format      % printf-format string for scalar(s) in value
        help
        help
    end
    end
    
    
@@ -11,11 +12,11 @@ classdef ParamClass < matlab.mixin.Copyable
        
        
        % ----------------------------------------------------------------------------------
        % ----------------------------------------------------------------------------------
        function obj = ParamClass(varargin)
        function obj = ParamClass(varargin)
            % FuncCallClass's Encode handles ParamClass construction
            obj.name   = '';
            obj.name   = '';
            obj.value  = [];
            obj.value  = [];
            obj.format = '';
            obj.format = '';
            obj.help   = '';
            obj.help   = '';
            
            if nargin==0
            if nargin==0
                return;
                return;
            elseif nargin==1
            elseif nargin==1
@@ -27,6 +28,11 @@ classdef ParamClass < matlab.mixin.Copyable
                obj.name   = varargin{1};
                obj.name   = varargin{1};
                obj.format = varargin{2};
                obj.format = varargin{2};
                obj.value  = varargin{3};
                obj.value  = varargin{3};
            elseif nargin==4
                obj.name   = varargin{1};
                obj.format = varargin{2};
                obj.value  = varargin{3};
                obj.default = varargin{4};
            end
            end
        end
        end
        
        
@@ -75,6 +81,17 @@ classdef ParamClass < matlab.mixin.Copyable
            end
            end
        end
        end
        
        
        % ----------------------------------------------------------------------------------
        function str = GetFormattedValue(obj)
            % Returns the string version of the value using the format
            % property, including brackets for arrays
            valstr = sprintf(obj.format, obj.value);
            if length(obj.value) > 1
                str = ['[', valstr, ']'];
            else
                str = valstr;
            end
        end
        
        
        % ----------------------------------------------------------------------------------
        % ----------------------------------------------------------------------------------
        function val = GetName(obj)
        function val = GetName(obj)
@@ -91,6 +108,22 @@ classdef ParamClass < matlab.mixin.Copyable
            val = obj.format;
            val = obj.format;
        end
        end


        % ----------------------------------------------------------------------------------
        function val = GetDefault(obj)
            val = obj.default;
        end

        % ----------------------------------------------------------------------------------
        function err = Edit(obj, val)
            % Assign a new value to the parameter, affecting both the value
            % and format
            obj.value = val;
            eachformat = strsplit(obj.format);
            formatlen = length(val);
            obj.format = strtrim(repmat([eachformat{1}, ' '], 1, formatlen));
            err = 0;  % Error checking i.e. max length
        end
        
        % ----------------------------------------------------------------------------------
        % ----------------------------------------------------------------------------------
        function str = Encode(obj)
        function str = Encode(obj)
            str = '';
            str = '';
+4 −2
Original line number Original line Diff line number Diff line
@@ -192,7 +192,9 @@ classdef ProcStreamClass < handle
        
        
        % ----------------------------------------------------------------------------------
        % ----------------------------------------------------------------------------------
        function str = EditParam(obj, iFcall, iParam, val)
        function str = EditParam(obj, iFcall, iParam, val)
            % Returns "" if the edit is rejected or the string 
            str = '';
            str = '';
            param = obj.fcalls(iFcall).paramIn(iParam);
            if isempty(iFcall)
            if isempty(iFcall)
                return;
                return;
            end
            end
@@ -205,8 +207,8 @@ classdef ProcStreamClass < handle
            if isempty(obj.fcalls(iFcall).paramIn)
            if isempty(obj.fcalls(iFcall).paramIn)
                return;
                return;
            end
            end
            obj.fcalls(iFcall).paramIn(iParam).value = val;
            param.Edit(val);
            str = sprintf(obj.fcalls(iFcall).paramIn(iParam).format, val);
            str = sprintf(param.format, val);
        end
        end




+2 −6
Original line number Original line Diff line number Diff line
@@ -44,7 +44,7 @@
%                Defaults: p=8.6 q=0.547
%                Defaults: p=8.6 q=0.547
%                The peak is at time p*q.  The FWHM is about 2.3*sqrt(p)*q.
%                The peak is at time p*q.  The FWHM is about 2.3*sqrt(p)*q.
% paramsBasis - Parameters for the basis function depends on idxBasis
% paramsBasis - Parameters for the basis function depends on idxBasis
%               idxBasis=1 [stdev step] where stdev is the width of the
%               idxBasis=1 [stdev step ~ ~ ~ ~] where stdev is the width of the
%                  gaussian and step is the temporal spacing between
%                  gaussian and step is the temporal spacing between
%                  consecutive gaussians
%                  consecutive gaussians
%               idxBasis=2. [tau sigma T] applied to both HbO and HbR
%               idxBasis=2. [tau sigma T] applied to both HbO and HbR
@@ -259,11 +259,7 @@ for iBlk=1:length(data_y)
        
        
    elseif idxBasis==2
    elseif idxBasis==2
        % Modified Gamma
        % Modified Gamma
        if length(paramsBasis)==3
            nConc = 1;
        elseif length(paramsBasis)==6
        nConc = 2;
        nConc = 2;
        end
        
        
        nB = 1;
        nB = 1;
        tbasis = zeros(ntHRF,nB,nConc);
        tbasis = zeros(ntHRF,nB,nConc);
+20 −0
Original line number Original line Diff line number Diff line
% PARAMETERS:
% trange: [-2.0, 20.0]
% glmSolveMethod: 1
% idxBasis: 1
% paramsBasis: [1.0 1.0 0.0 0.0 0.0 0.0], maxnum: 6
% rhoSD_ssThresh: 15.0
% flagNuisanceRMethod: 1
% driftOrder: 3
% c_vector: 0
function errmsg = hmrR_GLM_errchk(trange, glmSolveMethod, idxBasis, paramsBasis, rhoSD_ssThresh, flagNuisanceRMethod, driftOrder, c_vector)
    errmsg = '';
    % Define parameter error cases below and return an informative message
    if idxBasis > 4 || idxBasis < 1
       errmsg = 'Select a valid basis function (0-4)';
       return
    elseif glmSolveMethod > 2 || glmSolveMethod < 1
       errmsg = 'Select a valid solve method (1-2)'
       return
    end
end
 No newline at end of file
Loading