-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol.js
403 lines (318 loc) · 15.5 KB
/
control.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/*
================== qMRLab vfa_t1 pulse sequence =
This is the controller script which is responsible for
passing the variables between the GUI (control.ui) and
RTHawk's sequencing engine.
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)
Author: Agah Karakuzu [email protected]
Created: October, 2019.
// =================================================
*/
// Get sequence ID
var sequenceId = rth.sequenceId();
// Import display tool
rth.importJS("lib:RthDisplayThreePlaneTools.js");
var displayTools = new RthDisplayThreePlaneTools();
// Fetch initial parameters described in CartesianReadout3D.spv
var xPixels = SB.readout["<Cartesian Readout>.xRes"]; // Number of samples, no need for this, acquisition emits this.
var phaseEncodes = SB.readout["<Cartesian Readout>.yRes"]; // Number of repeats
var zPartitions = SB.readout["<Phase Encode Gradient>.res"]; // Number of partitions (has attr fov as well)
var interleaveSteps = SB.readout["<interleave>.numInputs"];
var rectSelected = false;
var sincSelected = true;
// These values are changed in the SB only.
rth.addCommand(new RthUpdateChangeReconstructionParameterCommand(sequenceId, {
phaseEncodes: phaseEncodes,
zPartitions: zPartitions
}));
rth.addCommand(new RthUpdateChangeReconstructionParameterCommand(sequenceId, "<interleave>.numInputs", SB.readout["<interleave>.numInputs"]));
rth.addCommand(new RthUpdateChangeReconstructionParameterCommand(sequenceId, "interleaveSteps", interleaveSteps));
for (var i = 0; i < interleaveSteps; i++) {
rth.addCommand(new RthUpdateChangeReconstructionParameterCommand(sequenceId, "<zPartition" + i + ">.repetitions", SB.readout["<zPartition" + i + ">.repetitions"]));
}
// Get the sequence parameters from the sequencer.
var scannerParameters = new RthUpdateGetParametersCommand(sequenceId);
rth.addCommand(scannerParameters);
var parameterList = scannerParameters.receivedData();
var instanceName = rth.instanceName();
rth.addSeriesDescription(instanceName);
rth.informationInsert(sequenceId, "mri.SequenceName", "qMRLab " + instanceName);
rth.informationInsert(sequenceId, "mri.ScanningSequence", "GR");
rth.informationInsert(sequenceId, "mri.SequenceVariant", "SS, SP");
rth.informationInsert(sequenceId, "mri.ScanOptions", "");
rth.informationInsert(sequenceId, "mri.MRAcquisitionType", "3D");
rth.informationInsert(sequenceId, "mri.NumberOfAverages", 1);
rth.informationInsert(sequenceId, "mri.NumberOfCoils", parameterList[2]);
rth.informationInsert(sequenceId, "mri.EchoTrainLength", 1);
rth.informationInsert(sequenceId, "mri.SpoilingState","True");
rth.informationInsert(sequenceId, "mri.SpoilingType","COMBINED");
rth.informationInsert(sequenceId, "mri.SpoilingRFPhaseIncrement",117);
rth.informationInsert(sequenceId, "mri.SpoilerGradientAmplitude", SB.readout["<Plateau Trapezoid>.maxVal"]);
rth.informationInsert(sequenceId, "mri.SpoilerGradientDuration", SB.readout["<Plateau Trapezoid>.plateauDuration"]);
rth.informationInsert(sequenceId, "mri.RxAttenuationManual", "False");
// Set SINC by default
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationrect", false));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationsinc", true));
// As there is rewinder in SINC, we should take its duration into account
// to determine TE accurately. In other words, end of that block is not
// equal to the end of SINC pulse.
var rfEnd = SB.excitationsinc["<Slice Select Gradient>.end"];
var rfPeak = SB.excitationsinc["<RF>.peak"];
// Get minimum TR
var scannerTR = new RthUpdateGetTRCommand(sequenceId, [], []);
rth.addCommand(scannerTR);
var minTR = scannerTR.tr();
var startingTR = 25;
RTHLOGGER_WARNING("B1AFI Minimum TR: " + minTR);
//var scannerTR0 = new RthUpdateGetTRCommand(sequenceId, [0,0,0,1], []);
//var scannerTR1 = new RthUpdateGetTRCommand(sequenceId, [0,0,0,1], [1]);
//RTHLOGGER_WARNING("HEY Minimum TR0: " + scannerTR0.tr());
//RTHLOGGER_WARNING("HEY Minimum TR1: " + scannerTR1.tr());
// Specify TE delay interval
var minTE = rfEnd - rfPeak + SB.readout['<Cartesian Readout>.readoutCenter'];
//var startingTE = minTE + rth.apdKey("echodelay/duration")/1000; //ms
// Hardcode to 3.5
var startingTE = 3.5;
rth.informationInsert(sequenceId,"mri.EchoTime",startingTE);
RTHLOGGER_WARNING("Starting TE: " + startingTE);
var echoTime = startingTE;
function updateSequenceParams(selected){
switch (selected) {
case "rect":
rectSelected = true;
sincSelected = false;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
ExcitationDuration: SB.excitationrect["<RF>.duration"],
FlipAngle:SB.excitationrect["<RF>.tip"],
ExcitationType: "Non-Selective RECT"
}));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationrect", true));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationsinc", false));
rfEnd = SB.excitationrect["<RF>.end"];
rfPeak = SB.excitationrect["<RF>.peak"];
// Update this so that the TE is accurate
minTE = rfEnd - rfPeak + SB.readout['<Cartesian Readout>.readoutCenter'];
RTHLOGGER_WARNING("Minimum TE RECT: " + minTE);
// Set echodelay to the desired value w.r.t pulse selection.
controlWidget.inputWidget_TE.value = echoTime;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
EchoTime: echoTime
}));
break;
case "sinc":
rectSelected = false;
sincSelected = true;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
ExcitationDuration: SB.excitationsinc["<RF>.duration"],
ExcitationTimeBandwidth: SB.excitationsinc["<RF>.timeBandwidth"],
FlipAngle:SB.excitationsinc["<RF>.tip"],
ExcitationPassBandRippleDB:SB.excitationsinc["<RF>.passbandRipple"],
ExcitationStopBandRippleDB:SB.excitationsinc["<RF>.stopbandRipple"],
ExcitationEnforceRFLimit:SB.excitationsinc["<RF>.enforceRFLimit"],
ExcitationType: "Slab-Selective MF-SLR"
}));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationrect", false));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationsinc", true));
var rfEnd = SB.excitationsinc["<Slice Select Gradient>.end"];
var rfPeak = SB.excitationsinc["<RF>.peak"];
// This is critical
minTE = rfEnd - rfPeak + SB.readout['<Cartesian Readout>.readoutCenter'];
RTHLOGGER_WARNING("Minimum TE SINC: " + minTE);
controlWidget.inputWidget_TE.value = echoTime;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
EchoTime: echoTime
}));
break;
}
}
// Starting FOV also depends on CartesianReadout3D.spv
// In SpinBench, FOV is defined in cm. xFOV = yFOV always.
var startingFOV = SB.readout["<Cartesian Readout>.fov"]; // cm
var startingZFOV = SB.readout["<Phase Encode Gradient>.fov"]; //cm
var startingResolution = startingFOV/xPixels* 10; // mm
// These params are agnostic to the RF selection
// For SS this would correspond to ssg thickness, but in absence it is PEZ FOV.
// In VFA T1 SS 48 but PEZ FOV is 50 (just followed a buffer convention I saw in other apps.)
// TODO: Match these xross apps.
var startingThickness = startingZFOV; // mm
displayTools.setSliceThickness(startingThickness*10);
// To store the current values
var sliceThickness = startingThickness;
var fieldOfView = startingFOV;
var repetitionTime = startingTR;
rth.informationInsert(sequenceId,"mri.VoxelSpacing",[fieldOfView/xPixels*10,fieldOfView/phaseEncodes*10,startingZFOV/zPartitions*10]);
rth.addCommand(new RthUpdateChangeSliceThicknessCommand(sequenceId, startingZFOV/zPartitions*10));
// Change functions
function changeFOV(fov){
if (fov<startingFOV) fov = startingFOV;
var scale = startingFOV/fov;
// Scale gradients (x,y,z) assuming in-plane isometry
rth.addCommand(new RthUpdateScaleGradientsCommand(sequenceId,"readout",scale,scale, 1));
// Waveforms are not affected by the below:
rth.addCommand(new RthUpdateChangeResolutionCommand(sequenceId,startingResolution/scale));
rth.addCommand(new RthUpdateChangeFieldOfViewCommand(sequenceId, fov*10,fov*10,1));
// Annotation
displayTools.setFOV(fov * 10);
//displayTool.setResolution(startingResolution/scale,startingResolution/scale);
// Update
fieldOfView = fov;
}
// This will change TR1, which is set as the global TR.
// SpinBench sets TR2 using JS logic w.r.t N
function changeTR1(tr1) {
rth.addCommand(new RthUpdateIntParameterCommand(sequenceId, "", "setDesiredTR", "", (tr1)*1000));
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId, "RepetitionTime", tr1));
curTR1 = tr1;
}
function changeTE(te)
{
// Give some buffer val
controlWidget.inputWidget_TE.minimum = minTE + 0.1;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId, "EchoTime", te));
// We need to adjust delay time w.r.t desired TE
var echoDelay = (te - minTE) * 1000; // Convert to usec
RTHLOGGER_WARNING("EchoDelay has been set to: " + echoDelay + "For requested TE of: " + te + "usec");
RTHLOGGER_WARNING("Please make sure that the values in SB/Plugin/JavaScript are correct");
RTHLOGGER_WARNING("====================== REQUIRED ================================");
RTHLOGGER_WARNING("TR1Duration in InterleavedCartesian3D.spv should be : " + (25 - echoDelay/1000 - SB.excitationsinc["<Slice Select Gradient>.end"]));
RTHLOGGER_WARNING("TR1Duration in InterleavedCartesian3D.spv should be : " + (50 - echoDelay/1000 - SB.excitationsinc["<Slice Select Gradient>.end"]));
RTHLOGGER_WARNING("====================== CURRENT =================================");
RTHLOGGER_WARNING("Current TR1 duration in spv: " + SB.readout["<New TR>.duration"]);
RTHLOGGER_WARNING("Current TR2 duration in spv: " + SB.readout["<InplaneTR2>.duration"]);
rth.addCommand(new RthUpdateIntParameterCommand(sequenceId, "echodelay", "setDelay", "", echoDelay));
echoTime = te;
}
function changeNFactor(N)
{
curTR2 = curTR1 * N;
//rth.addCommand(new RthUpdateIntParameterCommand(sequenceId, "", "setDesiredTR", "", (curTR1+curTR2) * 1000));
//rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId, "RepetitionTime", curTR1+curTR2));
nFactor = N;
}
// Send metadata to recon
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
NumberOfCoils: parameterList[2]
//PreAcqDuration: SB.readout["<Preacquisitions>.duration"]
}));
function changeRxAtten(val)
{
//RTHLOGGER_WARNING("Setting attenuation to " + val);
// SET RECEIVER ATTENUATION TO A USER DEFINED VALUE
rth.addCommand(new RthUpdateFloatParameterCommand(sequenceId, "readout", "setRxAttenuation", "", val));
}
controlWidget.inputWidget_RxAttenuation.valueChanged.connect(changeRxAtten);
controlWidget.inputWidget_RxAttenuation.minimum = 0;
controlWidget.inputWidget_RxAttenuation.maximum = 20;
var startingN = 2;
controlWidget.inputWidget_TRNfactor.minimum = startingN-1;
controlWidget.inputWidget_TRNfactor.maximum = startingN+2;
controlWidget.inputWidget_TRNfactor.value = startingN;
controlWidget.inputWidget_FOV.minimum = startingFOV;
controlWidget.inputWidget_FOV.maximum = startingFOV*2;
controlWidget.inputWidget_FOV.value = startingFOV;
controlWidget.inputWidget_TR.minimum = 25;
controlWidget.inputWidget_TR.maximum = minTR + 30;
controlWidget.inputWidget_TR.value = 25;
controlWidget.inputWidget_TE.minimum = minTE;
controlWidget.inputWidget_TE.maximum = 10;
controlWidget.inputWidget_TE.value = 3.5;
function sessionClicked(chck){
if (chck){
controlWidget.sessionBIDS.enabled = true;
controlWidget.sessionBIDS.setText("00");
}else{
controlWidget.sessionBIDS.enabled = false;
controlWidget.sessionBIDS.text = "";
controlWidget.sessionBIDS.placeholderText = "_ses-<index>";
}
}
function acqClicked(chck){
if (chck){
controlWidget.acqBIDS.enabled = true;
controlWidget.acqBIDS.setText("freeform");
}else{
controlWidget.acqBIDS.enabled = false;
controlWidget.acqBIDS.text = "";
controlWidget.acqBIDS.placeholderText = "_acq-<label>";
}
}
function rectClicked(chck){
if (chck){
controlWidget.checkBox_SINC.checked = false;
updateSequenceParams("rect");
}
}
function sincClicked(chck){
if (chck){
controlWidget.checkBox_RECT.checked = false;
updateSequenceParams("sinc");
}
}
var acqLabel = "";
function acqTextChanged(txt){
acqLabel = txt;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,"AcquisitionBIDS",acqLabel));
}
var sesIndex = "";
function sesTextChanged(txt){
sesIndex = txt;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,"SessionBIDS",sesIndex));
}
var subIndex = "";
function subTextChanged(txt){
subIndex = txt;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,"SubjectBIDS",subIndex));
}
function attenuationClicked(chck){
if (chck){
controlWidget.inputWidget_RxAttenuation.enabled = true;
controlWidget.inputWidget_RxAttenuation.value = 0;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId, "RxAttenuationManual", "True"));
}else{
RTHLOGGER_WARNING("Rx attenuation has been disabled.");
controlWidget.inputWidget_RxAttenuation.enabled = false;
controlWidget.inputWidget_RxAttenuation.value = 0;
rth.addCommand(new RthUpdateFloatParameterCommand(sequenceId, "readout", "setRxAttenuation", "", 0));
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId, "RxAttenuationManual", "False"));
}
}
// Connect UI elements to the callback functions.
controlWidget.isRxAttenuation.toggled.connect(attenuationClicked);
attenuationClicked(controlWidget.isRxAttenuation.checked)
controlWidget.acqBIDS.textChanged.connect(acqTextChanged);
acqTextChanged(controlWidget.acqBIDS.text);
controlWidget.sessionBIDS.textChanged.connect(sesTextChanged);
sesTextChanged(controlWidget.sessionBIDS.text);
controlWidget.subjectBIDS.textChanged.connect(subTextChanged);
subTextChanged(controlWidget.subjectBIDS.text);
controlWidget.isSessionBIDS.toggled.connect(sessionClicked);
sessionClicked(controlWidget.isSessionBIDS.checked)
controlWidget.isAcqBIDS.toggled.connect(acqClicked);
acqClicked(controlWidget.isAcqBIDS.checked)
controlWidget.inputWidget_FOV.valueChanged.connect(changeFOV);
changeFOV(controlWidget.inputWidget_FOV.value);
controlWidget.inputWidget_TR.valueChanged.connect(changeTR1);
changeTR1(controlWidget.inputWidget_TR.value);
controlWidget.inputWidget_TE.valueChanged.connect(changeTE);
changeTE(controlWidget.inputWidget_TE.value);
controlWidget.inputWidget_TRNfactor.valueChanged.connect(changeNFactor);
changeNFactor(controlWidget.inputWidget_TRNfactor.value);
controlWidget.checkBox_RECT.toggled.connect(rectClicked);
rectClicked(controlWidget.checkBox_RECT.checked)
controlWidget.checkBox_SINC.toggled.connect(sincClicked);
sincClicked(controlWidget.checkBox_SINC.checked)
// ADD LOOP COMMANDS
//var bigAngleCommand = new RthUpdateFloatParameterCommand(sequenceId, "excitation", "scaleRF", "", 1);
// Following sets FlipAngle to 3 when FA1 = 30 and FA2=25
//var smallAngleCommand = new RthUpdateFloatParameterCommand(sequenceId, "excitation", "scaleRF", "", flipAngle2/flipAngle1);
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
SubjectBIDS: controlWidget.subjectBIDS.text,
SessionBIDS: controlWidget.sessionBIDS.text,
AcquisitionBIDS: controlWidget.acqBIDS.text
}));