Skip to content

Commit 9fe13dd

Browse files
committed
v1.80.4
Utils, v1.7.3 -- Add session to simulated data. Copy generated SD file with spring registration to subject folders.
1 parent 4e55f85 commit 9fe13dd

File tree

3 files changed

+84
-27
lines changed

3 files changed

+84
-27
lines changed

Utils/Shared/Version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.2
1+
1.7.3

Utils/Shared/simData/generateSimDataset.m

Lines changed: 82 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,60 @@
99
% out = generateSimDataset(dirname, nSubj, nSess, nRuns, options)
1010
%
1111
% Description:
12-
% options - { {'probe'|'digpts}, 'springs', 'data' }
12+
% options - { {'probe'|'digpts}, 'springs', 'data' }
1313
%
1414
% Examples:
15+
%
16+
% %%%%% Change current folder to <root groups test folder>
17+
% emptyGroupTestDir = 'c:/users/public/groups/emptyGroupTestDir';
18+
% if ~exist(emptyGroupTestDir,'dir'), mkdir(emptyGroupTestDir); end
19+
% cd(emptyGroupTestDir);
20+
%
21+
% %%%%% Now generate probe and/or digitized points and/or raw/unprocessed dataTree data.
22+
% %%%%% These 9 examples covers all the major AtlasViewer + Homer3 workflows
23+
%
24+
% % Example 1: probe file in SD format with spring registration and
25+
% % raw/unprocessed dataTree data with 3 subjects, 3 sessions each, and 3 runs each.
26+
% out = generateSimDataset(pwd, 3, 3, 3, 'probe:springs:data');
27+
%
28+
% % Example 2: probe file in SD format with spring registration and
29+
% % raw/unprocessed dataTree data with 3 subjects, 3 sessions each with 3 runs each.
1530
% out = generateSimDataset();
31+
%
32+
% % Example 3: probe file in SD format with spring registration and
33+
% % acquisition data with 3 subjects, 1 session each, and 3 runs each.
1634
% out = generateSimDataset(pwd);
35+
%
36+
% % Example 4: probe file in SD format with spring registration and acquisition data
37+
% % with 2 subjects with 1 session each, and each session with 5 runs each.
38+
% out = generateSimDataset(pwd, 2, 1, 5);
39+
%
40+
% % Example 5: probe file in SD format with NO registration and NO acquisition data
1741
% out = generateSimDataset(pwd, [],[],[],'probe');
18-
% out = generateSimDataset(pwd, 3,3,3,'probe:data');
42+
%
43+
% % Example 6: probe file in SD format with spring registration and NO data
1944
% out = generateSimDataset(pwd, [],[],[],'probe:springs');
45+
%
46+
% % Example 7: Unprocessed dataTree data with 3 subjects, 3 sessions, and 3 runs each
47+
% % and with acquisition files containing probe with landmark registration.
48+
% % with 3 subjects with 1 session each, and each session with 3 runs each.
2049
% out = generateSimDataset(pwd, [],[],[],'probe:landmarks:data');
21-
% out = generateSimDataset(pwd, [],[],[],'probe:landmarks:data');
50+
%
51+
% % Example 8: Digpts file with associated probe file in SD format containing measurement list
52+
% % and NO acquisition data
2253
% out = generateSimDataset(pwd, [],[],[],'digpts');
23-
% out = generateSimDataset(pwd, [],[],[],'digpts:data');
54+
%
55+
% % Example 9: Digpts file with associated probe file in SD format containing measurement list
56+
% % and data with 1 subject with 2 sessions each, and each session with 4 runs each.
57+
% out = generateSimDataset(pwd, 1, 2, 4, 'digpts:data');
58+
%
2459
%
2560
global atlasViewer
61+
global probeFilename
62+
2663
atlasViewer = [];
64+
probeFilename = 'newfile1.SD';
65+
2766
out = [];
2867

2968
t0 = tic;
@@ -35,7 +74,7 @@
3574
nSubj = 3;
3675
end
3776
if ~exist('nSess','var') || isempty(nSess)
38-
nSess = 3;
77+
nSess = 1;
3978
end
4079
if ~exist('nRuns','var') || isempty(nRuns)
4180
nRuns = 3;
@@ -73,15 +112,19 @@
73112
subjDirs = dir('sub-*');
74113
for ii = 1:length(subjDirs)
75114
digptsNew = movePts(digpts, randNearZero(1,3,t0), randNearOne(1,3,t0), randNearZero(1,3,t0));
76-
digptsNew.pathname = [filesepStandard(pwd), subjDirs(ii).name];
115+
digptsNew.pathname = [filesepStandard(dirname), subjDirs(ii).name];
77116
saveDigpts(digptsNew);
117+
if ispathvalid([dirname, probeFilename])
118+
if optionExists(options, 'springs')
119+
copyfile([dirname, probeFilename], [filesepStandard(dirname), subjDirs(ii).name, '/', probeFilename]);
120+
end
121+
end
78122
end
79123
delete('./digpts*.txt');
80124
end
81125

82126

83127

84-
85128
% ----------------------------------------------
86129
function genSimData(probe, dirname, nSubj, nSess, nRuns, t0)
87130
SD = convertProbe2SD(probe);
@@ -108,29 +151,43 @@ function genSimData(probe, dirname, nSubj, nSess, nRuns, t0)
108151
else
109152
iSubjName = sprintf('%d', iSubj);
110153
end
111-
sname = sprintf('sub-%s', iSubjName);
112-
if ispathvalid([dirname, sname])
113-
rmdir([dirname, sname], 's')
154+
subjName = sprintf('sub-%s', iSubjName);
155+
subjNameFull = filesepStandard([dirname, subjName], 'dir:nameonly');
156+
if ispathvalid(subjNameFull)
157+
rmdir(subjNameFull, 's')
114158
end
115-
mkdir([dirname, sname]);
159+
mkdir(subjNameFull);
116160

117-
for iRun = 1:nRuns
118-
for iM = 1:size(nirs.SD.MeasList,1)
119-
[nirs.t, nirs.d(:,iM)] = simulateDataTimeSeries(ntpts, 1, .4, t0);
120-
end
121-
snirf = SnirfClass(nirs.d, nirs.t, nirs.SD, [], nirs.s, nirs.CondNames);
122-
if iRun<10
123-
rname = sprintf('%s%s/%s_run0%d.snirf', dirname, sname, sname, iRun);
161+
for iSess = 1:nSess
162+
if iSess < 10
163+
iSessName = sprintf('0%d', iSess);
124164
else
125-
rname = sprintf('%s%s/%s_run%d.snirf', dirname, sname, sname, iRun);
165+
iSessName = sprintf('%d', iSess);
166+
end
167+
sessName = sprintf('ses-%s', iSessName);
168+
sessNameFull = filesepStandard([subjNameFull, sessName], 'dir:nameonly');
169+
if ispathvalid(sessNameFull)
170+
rmdir(sessNameFull, 's')
171+
end
172+
mkdir(sessNameFull);
173+
174+
for iRun = 1:nRuns
175+
for iM = 1:size(nirs.SD.MeasList,1)
176+
[nirs.t, nirs.d(:,iM)] = simulateDataTimeSeries(ntpts, 1, .4, t0);
177+
end
178+
snirf = SnirfClass(nirs.d, nirs.t, nirs.SD, [], nirs.s, nirs.CondNames);
179+
if iRun<10
180+
runNameFull = sprintf('%s%s_%s_run0%d.snirf', sessNameFull, subjName, sessName, iRun);
181+
else
182+
runNameFull = sprintf('%s%s_%s_run%d.snirf', sessNameFull, subjName, sessName, iRun);
183+
end
184+
snirf.Save(runNameFull);
185+
fprintf('Created run %s\n', runNameFull);
126186
end
127-
snirf.Save(rname);
128-
fprintf('Created run %s\n', rname);
129187
end
130188
end
131189

132190

133-
134191
% -----------------------------------------------------------------
135192
function resetDataset(dirname)
136193
if ~exist('dirname','var')
@@ -188,7 +245,7 @@ function resetDataset(dirname)
188245
B = [ ...
189246
cos(beta) 0 sin(beta) 0;
190247
0 1 0 0;
191-
-sin(beta) 0 cos(beta) 0;
248+
-sin(beta) 0 cos(beta) 0;
192249
0 0 0 1;
193250
];
194251

@@ -207,7 +264,7 @@ function resetDataset(dirname)
207264
];
208265

209266
S = [ ...
210-
s(1) 0 0 0;
267+
s(1) 0 0 0;
211268
0 s(2) 0 0;
212269
0 0 s(3) 0;
213270
0 0 0 1;
@@ -246,7 +303,7 @@ function generateRandNumSeed(time0)
246303
s = 0;
247304
while s==0
248305
s = uint64(1e4*toc(time0));
249-
end
306+
end
250307
rng(s);
251308
end
252309

Version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.80.3
1+
1.80.4

0 commit comments

Comments
 (0)