Commit 9fe13dd9 authored by jayd1860's avatar jayd1860
Browse files

v1.80.4

Utils, v1.7.3
-- Add session to simulated data. Copy generated SD file with spring registration to subject folders.
parent 4e55f850
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
1.7.2
 No newline at end of file
1.7.3
 No newline at end of file
+82 −25
Original line number Diff line number Diff line
@@ -12,18 +12,57 @@ function out = generateSimDataset(dirname, nSubj, nSess, nRuns, options)
%   options - { {'probe'|'digpts}, 'springs', 'data' }
%
% Examples:
%
%   %%%%% Change current folder to <root groups test folder>
%   emptyGroupTestDir = 'c:/users/public/groups/emptyGroupTestDir';
%   if ~exist(emptyGroupTestDir,'dir'), mkdir(emptyGroupTestDir); end
%   cd(emptyGroupTestDir);
%
%   %%%%% Now generate probe and/or digitized points and/or raw/unprocessed dataTree data.
%   %%%%% These 9 examples covers all the major AtlasViewer + Homer3 workflows
%
%   % Example 1: probe file in SD format with spring registration and
%   % raw/unprocessed dataTree data with 3 subjects, 3 sessions each, and 3 runs each.
%   out = generateSimDataset(pwd, 3, 3, 3, 'probe:springs:data');
%
%   % Example 2: probe file in SD format with spring registration and
%   % raw/unprocessed dataTree data with 3 subjects, 3 sessions each with 3 runs each.
%   out = generateSimDataset();
%
%   % Example 3: probe file in SD format with spring registration and
%   % acquisition data with 3 subjects, 1 session each, and 3 runs each.
%   out = generateSimDataset(pwd);
%
%   % Example 4: probe file in SD format with spring registration and acquisition data
%   % with 2 subjects with 1 session each, and each session with 5 runs each.
%   out = generateSimDataset(pwd, 2, 1, 5);
%
%   % Example 5: probe file in SD format with NO registration and NO acquisition data
%   out = generateSimDataset(pwd, [],[],[],'probe');
%   out = generateSimDataset(pwd, 3,3,3,'probe:data');
%
%   % Example 6: probe file in SD format with spring registration and NO data
%   out = generateSimDataset(pwd, [],[],[],'probe:springs');
%
%   % Example 7: Unprocessed dataTree data with 3 subjects, 3 sessions, and 3 runs each
%   % and with acquisition files containing probe with landmark registration.
%   % with 3 subjects with 1 session each, and each session with 3 runs each.
%   out = generateSimDataset(pwd, [],[],[],'probe:landmarks:data');
%   out = generateSimDataset(pwd, [],[],[],'probe:landmarks:data');
%
%   % Example 8: Digpts file with associated probe file in SD format containing measurement list
%   % and NO acquisition data
%   out = generateSimDataset(pwd, [],[],[],'digpts');
%   out = generateSimDataset(pwd, [],[],[],'digpts:data');
%
%   % Example 9: Digpts file with associated probe file in SD format containing measurement list
%   % and data with 1 subject with 2 sessions each, and each session with 4 runs each.
%   out = generateSimDataset(pwd, 1, 2, 4, 'digpts:data');
%
%
global atlasViewer
global probeFilename

atlasViewer = [];
probeFilename = 'newfile1.SD';

out = [];

t0 = tic;
@@ -35,7 +74,7 @@ if ~exist('nSubj','var') || isempty(nSubj)
    nSubj = 3;
end
if ~exist('nSess','var') || isempty(nSess)
    nSess = 3;
    nSess = 1;
end
if ~exist('nRuns','var') || isempty(nRuns)
    nRuns = 3;
@@ -73,15 +112,19 @@ if optionExists(options, 'data')
    subjDirs = dir('sub-*');
    for ii = 1:length(subjDirs)
        digptsNew = movePts(digpts, randNearZero(1,3,t0), randNearOne(1,3,t0), randNearZero(1,3,t0));
        digptsNew.pathname = [filesepStandard(pwd), subjDirs(ii).name];
        digptsNew.pathname = [filesepStandard(dirname), subjDirs(ii).name];
        saveDigpts(digptsNew);
        if ispathvalid([dirname, probeFilename])
            if optionExists(options, 'springs')
                copyfile([dirname, probeFilename], [filesepStandard(dirname), subjDirs(ii).name, '/', probeFilename]);
            end
        end
    end
    delete('./digpts*.txt');
end




% ----------------------------------------------
function genSimData(probe, dirname, nSubj, nSess, nRuns, t0)
SD = convertProbe2SD(probe);
@@ -108,11 +151,25 @@ for iSubj = 1:nSubj
    else
        iSubjName = sprintf('%d', iSubj);
    end
    sname = sprintf('sub-%s', iSubjName);
    if ispathvalid([dirname, sname])
        rmdir([dirname, sname], 's')
    subjName = sprintf('sub-%s', iSubjName);
    subjNameFull = filesepStandard([dirname, subjName], 'dir:nameonly');
    if ispathvalid(subjNameFull)
        rmdir(subjNameFull, 's')
    end
    mkdir([dirname, sname]);
    mkdir(subjNameFull);
    
    for iSess = 1:nSess
        if iSess < 10
            iSessName = sprintf('0%d', iSess);
        else
            iSessName = sprintf('%d', iSess);
        end
        sessName = sprintf('ses-%s', iSessName);
        sessNameFull = filesepStandard([subjNameFull, sessName], 'dir:nameonly');
        if ispathvalid(sessNameFull)
            rmdir(sessNameFull, 's')
        end
        mkdir(sessNameFull);
        
        for iRun = 1:nRuns
            for iM = 1:size(nirs.SD.MeasList,1)
@@ -120,15 +177,15 @@ for iSubj = 1:nSubj
            end
            snirf = SnirfClass(nirs.d, nirs.t, nirs.SD, [], nirs.s, nirs.CondNames);
            if iRun<10
            rname = sprintf('%s%s/%s_run0%d.snirf', dirname, sname, sname, iRun);
                runNameFull = sprintf('%s%s_%s_run0%d.snirf', sessNameFull, subjName, sessName, iRun);
            else
            rname = sprintf('%s%s/%s_run%d.snirf', dirname, sname, sname, iRun);
                runNameFull = sprintf('%s%s_%s_run%d.snirf', sessNameFull, subjName, sessName, iRun);
            end
            snirf.Save(runNameFull);
            fprintf('Created run %s\n', runNameFull);
        end
        snirf.Save(rname);
        fprintf('Created run %s\n', rname);
    end
end



% -----------------------------------------------------------------
+1 −1
Original line number Diff line number Diff line
1.80.3
 No newline at end of file
1.80.4
 No newline at end of file