-
Notifications
You must be signed in to change notification settings - Fork 0
/
cni_qaSummary.m
160 lines (130 loc) · 4.98 KB
/
cni_qaSummary.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
%% Draft
%% Open a channel to the cni Flywheel instance
cni = scitran('cni');
qaProject = cni.lookup('cni/qa');
% Find the sessions created after a certain date.
qaSessions = qaProject.sessions.find('created>2021-03-15');
fprintf('Found %d sessions\n',numel(qaSessions));
%% Find all the analyses with a 'cni-tsnr' in the label
qq = 1;
clear qaData
for ss=1:numel(qaSessions)
% Get the analyses
qaAnalyses = qaSessions{ss}.analyses();
if ~isempty(qaAnalyses)
qaAnalyses = stSelect(qaAnalyses,'label','cni-tsnr');
if ~isempty(qaAnalyses)
for aa = 1:numel(qaAnalyses)
% Find the result file
thisFile = stSelect(qaAnalyses{aa}.files,'name','result');
if isempty(thisFile)
fprintf('No result.json file found\n');
stPrint(qaAnalyses{aa}.files,'name');
else
fprintf('Analyses with a result file found in session %d\n',ss);
% Download the file and read its contents
thisFile{1}.download('result.json');
tmp = jsonread('result.json');
tmp.created = qaAnalyses{aa}.created;
% Find which acquisition has the input file from
% the analyses. The acquisition label should be
% the same when we plot the snr or sfnr.
% This is the id of a file. We want to find which
% acquisition contains this file.
% This is the analysis
% qaAnalyses{aa}.inputs{1}.parentRef
% The acquisition is empty in this case.
% qaAnalyses{aa}.inputs{1}.parents
% This is the fileId. How can we find it and the
% acquisition that contains it? Use lookup?
%
% To find the acquisition, we can get session for
% the analysis this way where the ID is the
% session id
%
% theSession = cni.fw.sessions.findOne('_id=604f89af9cf87cf7bb3da252')
% Loop through the acqusitions to find the file
%
% acquisitions = cni.fw.acquisitions.find('session=sessionID')
% Ver 17 will have cni.fw.files.find and
% cni.fw.analyes.find
fileid = qaAnalyses{aa}.inputs{1}.fileId;
thisAcq = cni.search('acquisition','fileid',fileid,'container',true);
if ~isempty(thisAcq)
tmp.acquisition = thisAcq{1}.label;
else
fprintf('No acquisition found for input file on analysis %d\n',aa);
tmp.acquisition = 'Unknown acq';
end
qaData{qq} = tmp; %#ok<SAGROW>
qq = qq+1;
end
end
end
end
end
%% Now we could pull out the variables we want
%
% Say we want the snr for all the acquisitions with a label
% or the sfnr.
acqNames = {'BOLD EPI Ax','Ax EPI'};
stPrint(qaData,'acquisition');
acq1 = stSelect(qaData,'acquisition',acqNames{1});
acq2 = stSelect(qaData,'acquisition',acqNames{2});
%%
clear s t d
mrvNewGraphWin;
for ii=1:numel(acq1)
s(ii) = str2double(acq1{ii}.sfnr_center);
d(ii) = acq1{ii}.created;
end
plot(d,s,'LineWidth',2)
grid on
title(acqNames{1});
%%
clear s t d
mrvNewGraphWin;
for ii=1:numel(acq2)
s(ii) = str2double(acq2{ii}.sfnr_center);
% t(ii) = str2double(acq2{ii}.tsnr_center);
d(ii) = acq2{ii}.created;
end
plot(d,s,'LineWidth',2)
title(acqNames{2});
grid on
%% This would be all sessions in the project.
% qaSessions = qaProject.sessions();
%% Get the QA project information
%{
qaProject = cni.lookup('cni/qa');
% This gets a partial download of the session information. To get the full
% download
qaSessions = qaProject.sessions();
%%
id = qaSessions{end-12}.id;
thisSession = cni.fw.get(id);
an = thisSession.analyses();
thisA = cni.fw.get('60f7348b20c8ff1669df479f');
qaFiles = thisA.files;
stPrint(qaFiles,'name')
qaFiles{8}.download('thisresult.json');
result = jsonread('thisresult.json');
%}
%% Could we search for qa project sessions with a recent date?
% I guess so! We must 'fw' true it takes a lot longer but we get back
% everything. If we do not, then we get a good summary. Might be enough.
%{
qaSessions = cni.search('session',...
'project label exact','qa',...
'session after time','now-26w',...
'container',true);
size(qaSessions)
%}
%% For each session, we can find the acquisitions and analyses this way
% We will loop on these to get all the snr and sfnr data
% ss = 12;
% qaAcq = qaSessions{ss}.acquisitions();
% stPrint(qaAcq,'label');
% qaAnalyses = qaSessions{ss}.analyses();
% stPrint(qaAnalyses,'label');
%% END