Commit d80dc2c0 authored by Jay Dubb's avatar Jay Dubb
Browse files

v1.29.3

-- Fix not being able to load Snirf data because of missing OR invalid stim or AuxClass.
-- Add DebugLevel class to beb able to set various debug levels to - for instance - simulate bad data for testing. Add debuglevel fields to AuxClass and StimClass to be able to generate bad data at when saving a snirf file (when converting from other formats)
parent 809d37b8
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -7,6 +7,11 @@ classdef AuxClass < FileLoadSaveClass
        timeOffset
    end

    % Properties not part of the SNIRF spec. These parameters aren't loaded or saved to files
    properties (Access = private)
        debuglevel
    end    

    methods
        
        % -------------------------------------------------------
@@ -14,6 +19,8 @@ classdef AuxClass < FileLoadSaveClass
            % Set class properties not part of the SNIRF format
            obj.SetFileFormat('hdf5');

            obj.debuglevel = DebugLevel('none');
            
            obj.timeOffset = 0;
            if nargin==1
                if isa(varargin{1}, 'AuxClass')
@@ -113,6 +120,10 @@ classdef AuxClass < FileLoadSaveClass
                H5F.close(fid);
            end     
            
            if obj.debuglevel.Get() == obj.debuglevel.SimulateBadData()
                obj.SimulateBadData();
            end
            
            hdf5write_safe(fileobj, [location, '/name'], obj.name);
            hdf5write_safe(fileobj, [location, '/dataTimeSeries'], obj.dataTimeSeries);
            hdf5write_safe(fileobj, [location, '/time'], obj.time);
@@ -236,6 +247,11 @@ classdef AuxClass < FileLoadSaveClass
        end
        
        
        % ----------------------------------------------------------------------------------
        function SimulateBadData(obj)
            obj.dataTimeSeries(end,:) = [];
        end
        
    end
    
end
+10 −4
Original line number Diff line number Diff line
@@ -261,9 +261,9 @@ classdef SnirfClass < AcqDataClass & FileLoadSaveClass
                '''formatVersion'' is invalid.'
                '''metaDataTags'' is invalid.'
                '''data'' is invalid.'
                '''stim'' is invalid.'
                '''stim'' is invalid and could not be loaded'
                '''probe'' is invalid.'
                '''aux'' is invalid.'
                '''aux'' is invalid and could not be loaded'
                };
        end
        
@@ -538,7 +538,10 @@ classdef SnirfClass < AcqDataClass & FileLoadSaveClass

                %%%% Load stim
                if obj.LoadStim(obj.fid) < 0 && err == 0
                    err = -5;
                    % Optional field: even if invalid we still want to be
                    % able to work with the rest of the data. Only log
                    % warning
                    err = 5;
                end

                %%%% Load probe
@@ -548,7 +551,10 @@ classdef SnirfClass < AcqDataClass & FileLoadSaveClass

                %%%% Load aux. This is an optional field
                if obj.LoadAux(obj.fid) < 0 && err == 0
                    err = -7;
                    % Optional field: even if invalid we still want to be
                    % able to work with the rest of the data. Only log
                    % warning
                    err = 7;
                end
                
                % Close group
+22 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ classdef StimClass < FileLoadSaveClass
    % Properties not part of the SNIRF spec. These parameters aren't loaded or saved to files
    properties (Access = private)
        errmargin  % Margin for interpolating onset times. Not part of SNIRF
        debuglevel
    end    
    
    methods
@@ -20,6 +21,8 @@ classdef StimClass < FileLoadSaveClass
            obj.SetFileFormat('hdf5');
            obj.errmargin = 1e-2;
            obj.states = [];
            obj.debuglevel = DebugLevel('None');
            
            if nargin==1 
                if isa(varargin{1}, 'StimClass')
                    obj.Copy(varargin{1});
@@ -154,6 +157,10 @@ classdef StimClass < FileLoadSaveClass
                H5F.close(fid);
            end
            
            if obj.debuglevel.Get() == obj.debuglevel.SimulateBadData()
                obj.SimulateBadData();
            end
            
            hdf5write_safe(fileobj, [location, '/name'], obj.name);
                        
            % Since this is a writable writeable parameter AFTER it's creation, we
@@ -236,6 +243,11 @@ classdef StimClass < FileLoadSaveClass
        % ----------------------------------------------------------------------------------
        function err = ErrorCheck(obj)
            err = 0;
            
            % According to SNIRF spec, stim data is invalid if it has > 0 AND < 3 columns
            if isempty(obj.data)
                return;
            end
            if size(obj.data, 2)<3
                err = -2;
                return;
@@ -573,6 +585,14 @@ classdef StimClass < FileLoadSaveClass
            nbytes = sizeof(obj.states) + sizeof(obj.name) + sizeof(obj.data) + sizeof(obj.GetFilename()) + sizeof(obj.GetFileFormat()) + sizeof(obj.GetSupportedFormats()) + 8;
        end

               
        % ----------------------------------------------------------------------------------
        function SimulateBadData(obj)
            onsets = 10:20.2:100;
            obj.data = [onsets(:), zeros(length(onsets),1)];
        end
        
        
    end
    
end

Utils/DebugLevel.m

0 → 100644
+40 −0
Original line number Diff line number Diff line
classdef DebugLevel
    properties
        possibleValues
        value
    end
                
    methods

        % ----------------------------------------------------------------------------------
        function obj = DebugLevel(value) %#ok<*INUSD>
            obj.possibleValues = struct('none',0,'simulateBadData',1);            
            switch(lower(value))
                case 'none'
                    obj.value = obj.possibleValues.none;
                case 'simulatebaddata'
                    obj.value = obj.possibleValues.simulateBadData;
                otherwise
                    obj.value = obj.possibleValues.none;                    
            end
        end
        
        
        % ----------------------------------------------------------------------------------
        function value = Get(obj) 
            value = obj.value;
        end
        
        
        % ----------------------------------------------------------------------------------
        function value = SimulateBadData(obj) 
            value = obj.possibleValues.simulateBadData;
        end
        
        % ----------------------------------------------------------------------------------
        function value = None(obj) 
            value = obj.possibleValues.None;
        end
        
    end
end
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -2,5 +2,5 @@ function vrnnum = getVernum()

vrnnum{1} = '1';   % Major version #
vrnnum{2} = '29';  % Major sub-version #
vrnnum{3} = '2';   % Minor version #
vrnnum{3} = '3';   % Minor version #
vrnnum{4} = '0';   % Minor sub-version # or patch #: 'p1', 'p2', etc