-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.js
371 lines (291 loc) · 13.8 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
// Get sequence ID
var sequenceId = rth.sequenceId();
// Import display tool
rth.importJS("lib:RthDisplayThreePlaneTools.js");
var displayTools = new RthDisplayThreePlaneTools();
// E1R has the first echo, at the beginning of this stub.
// Following readouts are adjusted according to this one.
var xPixels = SB.readout["<E1R>.xRes"];
// Phase Encode Gradient & Phase Encode Gradient 1 are in-plane
var phaseEncodes = SB.readout["<Phase Encode Gradient>.res"]; // Number of repeats
var zPartitions = SB.readout["<Phase Encode Gradient 2>.res"]; // Number of partitions
var interleaveSteps = SB.readout["<interleave>.numInputs"];
var rectSelected = false;
var slrSelected = 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", "VENUS " + instanceName);
rth.informationInsert(sequenceId, "mri.ScanningSequence", "GR");
rth.informationInsert(sequenceId, "mri.SequenceVariant", "SS, SP, ME");
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", 6);
rth.informationInsert(sequenceId, "mri.SpoilingState","True");
rth.informationInsert(sequenceId, "mri.SpoilingType","COMBINED");
rth.informationInsert(sequenceId, "mri.SpoilingRFPhaseIncrement",110);
rth.informationInsert(sequenceId, "mri.SpoilerGradientArea", SB.readout["<Plateau Trapezoid>.area"]);
rth.informationInsert(sequenceId, "mri.RxAttenuationManual", "False");
// Set SLR by default
// Note that when this is changed, apd file has to be changed for this to make sense.
// So without that, exposing this to UI does not make sense.
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationrect", false));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationslr", 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.excitationslr["<SLR Excitation>.end"];
var rfPeak = SB.excitationslr["<SLR Excitation>.peak"];
// Get minimum TR
var scannerTR = new RthUpdateGetTRCommand(sequenceId, [], []);
rth.addCommand(scannerTR);
var minTR = scannerTR.tr();
var minTRRF = scannerTR.minTRRF();
var minTRGradient = scannerTR.minTRGradient();
var minTRPulses = scannerTR.minTRPulses();
// var startingTR = 20;
RTHLOGGER_WARNING("PHYSICAL Minimum TR: " + minTR);
RTHLOGGER_WARNING("PHYSICAL Minimum TRRF: " + minTRRF);
RTHLOGGER_WARNING("PHYSICAL Minimum TRGrad: " + minTRGrad);
RTHLOGGER_WARNING("PHYSICAL Minimum TRPulses: " + minTRPulses);
//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['<E1R>.readoutCenter'];
//var startingTE = minTE + rth.apdKey("echodelay/duration")/1000; //ms
// Hardcode to 3.5
var startingTE = minTE;
rth.informationInsert(sequenceId,"mri.EchoTime",startingTE);
RTHLOGGER_WARNING("Starting TE: " + startingTE);
var echoTime = startingTE;
function updateSequenceParams(selected){
switch (selected) {
case "rect":
rectSelected = true;
slrSelected = false;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
ExcitationDuration: SB.excitationrect["<Hard RF>.duration"],
FlipAngle:SB.excitationrect["<Hard RF>.tip"],
ExcitationType: "Non-Selective RECT"
}));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationrect", true));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationslr", false));
rfEnd = SB.excitationrect["<Hard RF>.end"];
rfPeak = SB.excitationrect["<Hard RF>.peak"];
// Update this so that the TE is accurate
minTE = rfEnd - rfPeak + SB.readout['<E1R>.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 "slr":
rectSelected = false;
slrSelected = true;
rth.addCommand(new RthUpdateChangeMRIParameterCommand(sequenceId,{
ExcitationDuration: SB.excitationslr["<SLR Excitation>.duration"],
ExcitationTimeBandwidth: SB.excitationslr["<SLR Excitation>.timeBandwidth"],
FlipAngle:SB.excitationslr["<SLR Excitation>.tip"],
ExcitationPassBandRippleDB:SB.excitationslr["<SLR Excitation>.passbandRipple"],
ExcitationStopBandRippleDB:SB.excitationslr["<SLR Excitation>.stopbandRipple"],
ExcitationEnforceRFLimit:SB.excitationslr["<SLR Excitation>.enforceRFLimit"],
ExcitationType: "Non-Selective (water exc) LP-SLR"
}));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationrect", false));
rth.addCommand(new RthUpdateEnableBlockCommand(sequenceId, "excitationslr", true));
var rfEnd = SB.excitationslr["<SLR Excitation>.end"];
var rfPeak = SB.excitationslr["<SLR Excitation>.peak"];
// This is critical
minTE = rfEnd - rfPeak + SB.readout['<E1R>.readoutCenter'];
RTHLOGGER_WARNING("Minimum TE SLR: " + 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["<E1R>.fov"]; // cm
// In-plane and other FOVs are equalized and dealt with on SB.
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
rth.addCommand(new RthUpdateIntParameterCommand(sequenceId, "echodelay", "setDelay", "", echoDelay));
echoTime = te;
}
// 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;
controlWidget.inputWidget_FOV.minimum = startingFOV;
controlWidget.inputWidget_FOV.maximum = startingFOV*2;
controlWidget.inputWidget_FOV.value = startingFOV;
controlWidget.inputWidget_TR.minimum = minTR;
controlWidget.inputWidget_TR.maximum = minTR + 30;
controlWidget.inputWidget_TR.value = minTR;
controlWidget.inputWidget_TE.minimum = minTE;
controlWidget.inputWidget_TE.maximum = 10;
controlWidget.inputWidget_TE.value = minTE + 0.1;
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.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
}));