Unverified Commit f860f7bb authored by jayd1860's avatar jayd1860 Committed by GitHub
Browse files

v1.38.3 -- Fix typo causing matlab exception in ProbeClass.m 3d-to-2d optode projection code (#138)

* v1.38.3

-- Fix typo causing matlab exception in ProbeClass.m 3d-to-2d optode projection code
-- Change output folder name in AppSettings.cfg to be derivatives/homer to be BIDS compliant
-- Add backward compatibility code to detect and move derived output in old folders to new BIDS compliant folder derivatives/homer

* v1.38.4

-- Convert export of processing stream functions from .txt to JSON .json format in compliance with BIDS.
-- Add Qianqian's JSON library jsonlab to support the exporting of processing stream functions
-- Add fields ExcludedTime and ExcludedChannels to exported proc stream functions
parent 5e0b668f
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -157,10 +157,8 @@ classdef ProbeClass < FileLoadSaveClass
            
            if isempty(obj.sourcePos2D) && isempty(obj.detectorPos2D)
                if isempty(obj.landmarkPos3D) || ~obj.isValidLandmarkLabels()
                    optodePos3D = [];
                    nSource = 0;
                    nSource = size(obj.sourcePos3D,1);
                    optodePos3D = [obj.sourcePos3D; obj.detectorPos3D];
                    nSource = size(optodePos3D,1);
                    
                    optodePos2D = project_3D_to_2D(optodePos3D);
                    if ~isempty(optodePos2D)
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ No
don't ask again

% Output Folder Name # 
homerOutput
derivatives/homer

% Output File Name # 
groupResults.mat
+70 −38
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ classdef GroupClass < TreeNodeClass
    
    properties % (Access = private)
        outputFilename
        oldDerivedPaths
        derivedPathBidsCompliant
    end
    
    
@@ -21,6 +23,8 @@ classdef GroupClass < TreeNodeClass
            obj@TreeNodeClass(varargin);

            obj.InitVersion();
            obj.oldDerivedPaths = {obj.path, [obj.path, 'homerOutput']};
            obj.derivedPathBidsCompliant = 'derivatives/homer';
            
            if nargin<3 || ~strcmp(varargin{3}, 'noprint')
                obj.logger.Write('Current GroupClass version %s\n', obj.GetVersionStr());
@@ -1071,10 +1075,12 @@ classdef GroupClass < TreeNodeClass

        % ----------------------------------------------------------------------------------
        function BackwardCompatability(obj)
            if ispathvalid([obj.path, 'groupResults.mat'])
            for jj = 1:length(obj.oldDerivedPaths)
                oldDerivedPath = filesepStandard(obj.oldDerivedPaths{jj});
                if ispathvalid([oldDerivedPath, 'groupResults.mat'])
                    try
                    g = load([obj.path, 'groupResults.mat']);
                catch ME
                        g = load([oldDerivedPath, 'groupResults.mat']);
                    catch
                        g = [];
                    end
                    
@@ -1095,24 +1101,50 @@ classdef GroupClass < TreeNodeClass
                        return;
                    end
                    
                msg = sprintf('Detected derived data in an old Homer3 format.');
                    oldDerivedPathRel = pathsubtract(oldDerivedPath, obj.path);
                    if oldDerivedPathRel(end) == '/' || oldDerivedPathRel(end) == '\'
                        oldDerivedPathRel(end) = '';
                    end
                    msg{1} = sprintf('Detected derived data in older Homer3 folder "%s" ', oldDerivedPathRel);
                    if pathscompare(obj.derivedPathBidsCompliant, obj.outputDirname, 'nameonly')
                        msg{2} = sprintf('The current derived output folder, "%s", is BIDS compliant. ', ...
                            filesepStandard(obj.derivedPathBidsCompliant, 'filesepwide:nameonly'));
                    else
                        msg{2} = '.';
                    end
                    msg = [msg{:}];
                    obj.logger.Write('Backward Compatability:   %s\n', msg);
                    
                    % If we're here it means that old format homer3 data exists
                    % AND NO new homer3 format data exists
                q = MenuBox(sprintf('%s. Do you want to save it in the new format?', msg),{'Yes','No'});
                    q = MenuBox(sprintf('%s Do you want to move %s to the new folder?', msg, oldDerivedPathRel),{'Yes','No'});
                    if q==1
                    obj.BackwardCompatability@TreeNodeClass();
                    for ii = 1:length(obj.subjs)
                        obj.subjs(ii).BackwardCompatability();
                        if ispathvalid([obj.path, obj.outputDirname])
                            try
                                rmdir([obj.path, obj.outputDirname], 's')
                            catch
                                MenuBox(sprintf('ERROR:  Could not remove new derived folder'),{'OK'});
                                return
                            end
                        end
                        obj.logger.Write('Moving %s to %s\n', oldDerivedPath, [obj.path, obj.outputDirname]);
                        movefile(oldDerivedPath, [obj.path, obj.outputDirname])
                        
                    obj.logger.Write('Moving %s to %s\n', 'groupResults.mat', [obj.path, obj.outputDirname, obj.outputFilename]);
                    movefile('groupResults.mat', [obj.path, obj.outputDirname, obj.outputFilename])
                        if ispathvalid([obj.path, obj.outputDirname, obj.outputFilename])
                            if ~strcmp(obj.outputFilename, 'groupResults.mat')
                                obj.logger.Write('Moving %s to %s\n', [obj.path, obj.outputDirname, 'groupResults.mat'], ...
                                    [obj.path, obj.outputDirname, obj.outputFilename])
                                movefile([obj.path, obj.outputDirname, 'groupResults.mat'], [obj.path, obj.outputDirname, obj.outputFilename])
                            end
                        end
                    end
                    break
                end
                
            end            
        end
            
        
    end  % Private methods

end % classdef GroupClass < TreeNodeClass
+36 −11
Original line number Diff line number Diff line
@@ -355,6 +355,27 @@ classdef ProcStreamClass < handle
        end
        
        
        % ----------------------------------------------------------------------------------        
        function mlActMan = CompressMlActMan(obj)
            mlActMan = [];
            if isempty(obj.input.mlActMan)
                return
            end
            mlActMan = compressLogicalArray(obj.input.mlActMan{1});
        end
        
        
        % ----------------------------------------------------------------------------------        
        function tIncMan = CompresstIncMan(obj)
            tIncMan = [];
            if isempty(obj.input.tIncMan)
                return
            end
            tIncMan = compressLogicalArray(obj.input.tIncMan{1});
        end
                
                
                
        % ----------------------------------------------------------------------------------        
        function ExportProcStream(obj, filename, fcalls)
            global logger             
@@ -363,13 +384,17 @@ classdef ProcStreamClass < handle
                return;
            end
            [p,f] = fileparts(temp); 
            fname = [filesepStandard(p), f, '_ProcStream.txt'];
            fname = [filesepStandard(p), f, '_processing.json'];
            if obj.ExportProcStreamFunctions()==true
                fid = fopen(fname, 'w');                
                logger.Write('Saving processing stream  %s:\n', fname);
                for ii = 1:length(fcalls)
                    fprintf(fid, '%s\n', fcalls{ii});
                end
                appname = sprintf('%s, (v%s)', getNamespace(), getVernum(getNamespace()));
                dt      = sprintf('%s', char(datetime(datetime, 'Format','MMMM d, yyyy,   HH:mm:ss')));
                mlActManCompressed = obj.CompressMlActMan();
                tIncManCompressed = obj.CompresstIncMan();
                jsonstruct = struct('ApplicationNsme',appname, 'DateTime',dt, 'ExcludedTime',tIncManCompressed, 'ExcludedChannels',mlActManCompressed, 'FunctionsCalls',{fcalls});
                jsonStr = savejson('Processing', jsonstruct);
                fid = fopen(fname, 'w');                
                fwrite(fid, jsonStr, 'uint8');
                fclose(fid);
            else
                if ispathvalid(fname)
+12 −7
Original line number Diff line number Diff line
@@ -825,19 +825,22 @@ classdef TreeNodeClass < handle
        
        % ----------------------------------------------------------------------------------
        function ExportProcStreamFunctionsSummary(obj)
            fmt = '.json';
            suffix = ['_processing',fmt];
            
            fid = fopen([obj.path, obj.outputDirname, 'ProcStreamFunctionsSummary.txt'], 'w');
            fprintf(fid, 'Application Name :   %s, (v%s)\n', getNamespace(), getVernum(getNamespace()));
            fprintf(fid, 'Date/Time        :   %s\n\n\n\n', char(datetime(datetime, 'Format','MMMM d, yyyy,   HH:mm:ss')));                        
            procStreamFunctionsExportFilenames = findTypeFiles([obj.path, obj.outputDirname], '.txt');            
            procStreamFunctionsExportFilenames = findTypeFiles([obj.path, obj.outputDirname], fmt);            
            for ii = 1:length(procStreamFunctionsExportFilenames)
                [~, fname, ext] = fileparts(procStreamFunctionsExportFilenames{ii});
                fname = [fname, ext]; %#ok<AGROW>
                if ~strcmp(fname(end-length('_ProcStream.txt')+1 : end), '_ProcStream.txt')
                if ~strcmp(fname(end-length(suffix)+1 : end), suffix)
                    continue;
                end
                k = strfind(procStreamFunctionsExportFilenames{ii}, obj.outputDirname);
                iS = k+length(obj.outputDirname);
                iE = length(procStreamFunctionsExportFilenames{ii}) - length('_ProcStream.txt');
                iE = length(procStreamFunctionsExportFilenames{ii}) - length(suffix);
                fname = procStreamFunctionsExportFilenames{ii}(iS : iE);
                objtype = lower(class(obj.procStream.input.acquired));
                j = strfind(objtype, 'class');
@@ -850,10 +853,12 @@ classdef TreeNodeClass < handle
                fprintf(fid, '%s\n', uint32('-') + uint32(zeros(1, length([fname, ext])+2)));
                fprintf(fid, '%s :\n', [fname, ext]);
                fprintf(fid, '%s\n', uint32('-') + uint32(zeros(1, length([fname, ext])+2)));
                fid2 = fopen(procStreamFunctionsExportFilenames{ii}, 'rt');
                txt = fread(fid2, 100000);                
                fclose(fid2);
                fprintf(fid, '%s\n', txt);                
                txt = loadjson(procStreamFunctionsExportFilenames{ii});
                fcalls = txt.Processing.FunctionsCalls;
                for kk = 1:length(fcalls)
                    fprintf(fid, '%s\n', fcalls{kk});
                end
                fprintf(fid, '\n\n');
            end
            fclose(fid);
        end
Loading