-
Notifications
You must be signed in to change notification settings - Fork 1
/
recon.js
237 lines (195 loc) · 7.82 KB
/
recon.js
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
================== qMRLab vfa_t1 pulse sequence =
This script is responsible for collecting raw data
and reconstructing images.
Waveforms exported by SpinBench and described by application.apd
determine the initial state of the sequence. For this
application, initial parameters are fetched from:
- [excitation] SincRF + Z (SlabSelect.spv)
- [echodelay] in us, to be exposed to GUI. (Not linked to a file)
- [readout] 3D Cartesian Readout (CartesianReadout3D.spv)
- [spoiler] Area Trapezoid (SpoilerGradient.spv)
For now, base resolution components are hardcoded to be
256X256mm (inplane) and 5mm (slab thickness) for the
3D readout.
TODO: These parameters are to be fetched from controller.
Author: Agah Karakuzu agahkarakuzu@gmail.com
Created: October, 2019.
// =================================================
*/
var sequenceId = rth.sequenceId();
var instanceName = rth.instanceName();
var observer = new RthReconRawObserver();
observer.setSequenceId(sequenceId);
observer.observeValueForKey("acquisition.samples", "samples");
// Disable button after observer is discond
observer.scanDisabled.connect(rth.deactivateScanButton);
function reconBlock(input) {
var that = this;
//this.sort = new RthReconRawToImageSort();
//this.sort.observeKeys(["acquisition.samples","reconstruction.phaseEncodes","reconstruction.partitions"]);
//this.sort.observedKeysChanged.connect(function(keys){
// that.sort.setPhaseEncodes(keys["reconstruction.phaseEncodes"]);
//that.sort.setSamples(keys["acquisition.samples"]);
//that.sort.setSliceEncodes(keys["reconstruction.zPartitions"]);
//that.sort.setAccumulate(keys["reconstruction.phaseEncodes"]*keys["reconstruction.zPartitions"]);
//});
this.sort3d = new RthReconSort();
this.sort3d.setIndexKeys(["acquisition.<Cartesian Readout>.index", "acquisition.<Repeat 1>.index"]);
this.sort3d.setInput(input);
this.sort3d.observeKeys(["mri.RunNumber"]);
this.sort3d.observedKeysChanged.connect(
function(keys) {
that.sort3d.resetAccumulation();
var yEncodes = keys["reconstruction.phaseEncodes"];
var samples = keys["acquisition.samples"];
//var coils = keys["acquisition.channels"];
var zEncodes = keys["reconstruction.zPartitions"];
//this.sort3d.extent = [samples, coils, yEncodes, zEncodes]; // if the input is [samples x coils]
that.sort3d.extent = [samples, yEncodes, zEncodes]; // if the input is [samples]
that.sort3d.accumulate = yEncodes * zEncodes;
}
);
//this.sort = RthReconSort();
//this.sort.setIndexKeys(["acquisition.index"]);
//this.sort.setInput(input);
//this.sort.setUseSliceEncodeKey(false);
//this.sort.setSwapSePe(true);
//this.sort.observeKeys(["acquisition.slice", "acquisition.index"]);
//this.sort.observedKeysChanged.connect(function(keys){
//RTHLOGGER_WARNING("Slice" + keys["acquisition.slice"] + "index" + keys["acquisition.index"]);
//});
//this.sort.observeKeys(["acquisition.<Repeat 1>.index"]);
//this.sort.observedKeysChanged.connect(function(keys){
// RTHLOGGER_WARNING("Slice" + keys["acquisition.<Repeat 1>.index"]);
//});
//this.sort.setExtent([256,256])
//this.sort.setAccumulate(2*256);
this.fft = new RthReconImageFFT();
this.fft.setInput(this.sort3d.output());
this.output = function() {
return this.fft.output();
};
}
// For each `coil we need sort and FFT.
var sos = new RthReconImageSumOfSquares();
var block = [];
function connectCoils(coils){
block = [];
for (var i = 0; i<coils; i++){
block[i] = new reconBlock(observer.output(i));
sos.setInput(i,block[i].output());
}
rth.collectGarbage();
}
observer.coilsChanged.connect(connectCoils);
rth.importJS("lib:RthImageThreePlaneOutput.js");
function ExportBlock(input){
var that = this;
//var imageExport = new RthReconToQmrlab();
// This is a bit annoying, but the only option for now.
this.imageExport = new RthReconImageExport();
this.changeInformation = new RthReconImageChangeInformation();
var reconKeys = new Array();
reconKeys = [
// For now, addTag does not support type string.
"mri.SequenceName",
"mri.ScanningSequence",
"mri.SequenceVariant",
"mri.MRAcquisitionType",
"mri.NumberOfCoils",
"mri.ExcitationTimeBandwidth",
"mri.ExcitationDuration",
"mri.ExcitationType",
"mri.VoxelSpacing",
"mri.EchoTime",
"mri.RepetitionTime",
"mri.FlipAngle1",
"mri.FlipAngle2",
"mri.FlipAngle", // Belonging to the current loop
"mri.SliceThickness",
"reconstruction.phaseEncodes",
"acquisition.samples",
"reconstruction.zPartitions",
"mri.PreAcqDuration",
"geometry.TranslationX",
"geometry.TranslationY",
"geometry.TranslationZ",
"geometry.QuaternionW",
"geometry.QuaternionX",
"geometry.QuaternionY",
"geometry.QuaternionZ",
"geometry.FieldOfViewX",
"geometry.FieldOfViewY",
"geometry.FieldOfViewZ",
"mri.FlipIndex", // Ensured that this one will change per run.
"mri.SubjectBIDS",
"mri.SessionBIDS",
"mri.AcquisitionBIDS",
"equipment.device/manufacturer",
"equipment.device/manufacturerModelName",
"equipment.device/softwareVersions",
"equipment.gradient/dcGain",
"equipment.gradient/xMaximumAmplitude",
"equipment.gradient/xRiseTime",
"equipment.gradient/xDbdtDistance",
"equipment.hostManufacturerModelName",
"equipment.hostSoftwareVersions",
"equipment.magnet/fieldStrength",
"equipment.prescan/cf",
"equipment.prescan/maxB1",
"equipment.prescan/nucleus",
"equipment.prescan/r1",
"equipment.prescan/r2",
"equipment.prescan/refPulseInGauss",
"equipment.prescan/refVoltage",
"equipment.prescan/status",
"equipment.prescan/tg",
"equipment.prescan/xs",
"equipment.prescan/ys",
"equipment.prescan/zs",
"equipment.regulatory/peakSar",
];
for (var i = 0; i<reconKeys.length; i++){
this.imageExport.addInformationKey(reconKeys[i]);
}
this.imageExport.observeKeys([
"mri.SubjectBIDS",
"mri.SessionBIDS",
"mri.AcquisitionBIDS",
"mri.FlipIndex"
]);
this.imageExport.observedKeysChanged.connect(function(keys){
var exportDirectory = "/home/agah/Desktop/AgahHV/";
var flipIndex = keys["mri.FlipIndex"];
var subjectBIDS = "sub-" + keys["mri.SubjectBIDS"];
var sessionBIDS = (keys["mri.SessionBIDS"]) ? "_ses-" + keys["mri.SessionBIDS"] : "";
var acquisitionBIDS = (keys["mri.AcquisitionBIDS"]) ? "_acq-" + keys["mri.AcquisitionBIDS"] : "";
var exportFileName = exportDirectory + subjectBIDS + sessionBIDS + acquisitionBIDS + "_flip-" + flipIndex + "_VFAT1.dat";
that.imageExport.setFileName(exportFileName);
});
//this.imageExport.observeKeys(["mri.RunNumber", // Ensured that this one will change per run.
// "mri.SubjectBIDS",
// "mri.SessionBIDS",
// "mri.AcquisitionBIDS"
//]);
//this.imageExport.observedKeysChanged(function(keys){
// var flipIndex = keys["mri.RunNumber"] + 1;
// var subjectBIDS = "sub-" + keys["mri.SessionBIDS"];
// var sessionBIDS = (keys["mri.SessionBIDS"]!=="") ? "_ses-" + keys["mri.SessionBIDS"] : "";
// var acquisitionBIDS = (keys["mri.AcquisitionBIDS"]!=="") ? "_acq-" + keys["mri.AcquisitionBIDS"] : "";
//});
//var exportDirectory = "/home/agah/Desktop/AgahHV/";
//var exportFileName = exportDirectory + subjectBIDS + sessionBIDS + acquisitionBIDS + "_flip-" + flipIndex + '_VFAT1.dat';
this.imageExport.objectName = "save_image";
this.imageExport.setInput(input);
RTHLOGGER_WARNING("saving...");
//this.imageExport.saveFileSeries(true);
// This is a sink node, hence no output.
}
var splitter = RthReconSplitter();
splitter.objectName = "splitOutput";
splitter.setInput(sos.output());
var threePlane = new RthImageThreePlaneOutput();
threePlane.setInput(splitter.output(0));
var exporter = new ExportBlock(splitter.output(1));