def load_shim(self): print("\tLoad grad offsets") self.shim_x.setText(str(parameters.get_grad_offset_x())) self.shim_y.setText(str(parameters.get_grad_offset_y())) self.shim_z.setText(str(parameters.get_grad_offset_z())) offsetX = int(self.shim_x.text()) if offsetX > 0: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | offsetX)) else: gsocket.write( struct.pack('<I', 2 << 28 | 4 << 24 | 1 << 20 | -offsetX)) offsetY = int(self.shim_y.text()) if offsetY > 0: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | offsetY)) else: gsocket.write( struct.pack('<I', 2 << 28 | 4 << 24 | 1 << 20 | -offsetY)) offsetZ = int(self.shim_z.text()) if offsetZ > 0: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | offsetZ)) else: gsocket.write( struct.pack('<I', 2 << 28 | 4 << 24 | 1 << 20 | -offsetZ)) if self.idle: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | 0 << 20)) else: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | 1 << 20)) print("Acquiring data")
def load_shim(self): print("\tLoad grad offsets.") self.gradOffset_x.valueChanged.disconnect() self.gradOffset_y.valueChanged.disconnect() self.gradOffset_z.valueChanged.disconnect() self.gradOffset_z2.valueChanged.disconnect() self.gradOffset_x.setValue(parameters.get_grad_offset_x()) self.gradOffset_y.setValue(parameters.get_grad_offset_y()) self.gradOffset_z.setValue(parameters.get_grad_offset_z()) self.gradOffset_z2.setValue(parameters.get_grad_offset_z2()) self.gradOffset_x.valueChanged.connect( lambda: self.set_grad_offset(self.gradOffset_x)) self.gradOffset_y.valueChanged.connect( lambda: self.set_grad_offset(self.gradOffset_y)) self.gradOffset_z.valueChanged.connect( lambda: self.set_grad_offset(self.gradOffset_z)) self.gradOffset_z2.valueChanged.connect( lambda: self.set_grad_offset(self.gradOffset_z2)) offsetX = self.gradOffset_x.value() if offsetX > 0: gsocket.write(struct.pack('<I', 2 << 28 | 5 << 24 | offsetX)) else: gsocket.write( struct.pack('<I', 2 << 28 | 5 << 24 | 1 << 20 | -offsetX)) offsetY = self.gradOffset_y.value() if offsetY > 0: gsocket.write(struct.pack('<I', 2 << 28 | 5 << 24 | offsetY)) else: gsocket.write( struct.pack('<I', 2 << 28 | 5 << 24 | 1 << 20 | -offsetY)) offsetZ = self.gradOffset_z.value() if offsetZ > 0: gsocket.write(struct.pack('<I', 2 << 28 | 5 << 24 | offsetZ)) else: gsocket.write( struct.pack('<I', 2 << 28 | 5 << 24 | 1 << 20 | -offsetZ)) offsetZ2 = self.gradOffset_z2.value() if offsetZ2 > 0: gsocket.write(struct.pack('<I', 2 << 28 | 5 << 24 | offsetZ2)) else: gsocket.write( struct.pack('<I', 2 << 28 | 5 << 24 | 1 << 20 | -offsetZ2)) if self.idle: gsocket.write(struct.pack('<I', 2 << 28 | 5 << 24 | 0 << 20)) else: gsocket.write(struct.pack('<I', 2 << 28 | 5 << 24 | 1 << 20)) print("Acquiring data.")
def load_shim(self): print("CMD: Loading shim") self.gradOffset_x.valueChanged.disconnect() self.gradOffset_y.valueChanged.disconnect() self.gradOffset_z.valueChanged.disconnect() self.gradOffset_x.setValue(parameters.get_grad_offset_x()) self.gradOffset_y.setValue(parameters.get_grad_offset_y()) self.gradOffset_z.setValue(parameters.get_grad_offset_z()) self.horizontalSlider_x.setValue(parameters.get_grad_offset_x()) self.horizontalSlider_y.setValue(parameters.get_grad_offset_y()) self.horizontalSlider_z.setValue(parameters.get_grad_offset_z()) self.gradOffset_x.valueChanged.connect( lambda: self.set_grad_offset(self.gradOffset_x)) self.gradOffset_y.valueChanged.connect( lambda: self.set_grad_offset(self.gradOffset_y)) self.gradOffset_z.valueChanged.connect( lambda: self.set_grad_offset(self.gradOffset_z)) offsetX = self.gradOffset_x.value() self.horizontalSlider_x.setValue(offsetX) if offsetX > 0: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | offsetX)) else: gsocket.write( struct.pack('<I', 2 << 28 | 4 << 24 | 1 << 20 | -offsetX)) offsetY = self.gradOffset_y.value() self.horizontalSlider_y.setValue(offsetY) if offsetY > 0: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | offsetY)) else: gsocket.write( struct.pack('<I', 2 << 28 | 4 << 24 | 1 << 20 | -offsetY)) offsetZ = self.gradOffset_z.value() self.horizontalSlider_z.setValue(offsetZ) if offsetZ > 0: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | offsetZ)) else: gsocket.write( struct.pack('<I', 2 << 28 | 4 << 24 | 1 << 20 | -offsetZ)) if self.idle: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | 0 << 20)) else: gsocket.write(struct.pack('<I', 2 << 28 | 4 << 24 | 1 << 20)) print("\tAcquiring data")
def __init__(self): super(MRI_2DImag_Widget, self).__init__() self.setupUi(self) self.idle = True # state variable: True-stop, False-start # setup basic GUI self.startButton.clicked.connect(self.start) self.stopButton.clicked.connect(self.stop) self.freqValue.valueChanged.connect(self.set_freq) self.acquireButton.clicked.connect(self.acquire) self.progressBar.setValue(0) # setup gradient offsets related GUI self.loadShimButton.clicked.connect(self.load_shim) self.zeroShimButton.clicked.connect(self.zero_shim) self.shim_x.setText(str(parameters.get_grad_offset_x())) self.shim_y.setText(str(parameters.get_grad_offset_y())) self.shim_z.setText(str(parameters.get_grad_offset_z())) self.shim_x.setReadOnly(True) self.shim_y.setReadOnly(True) self.shim_z.setReadOnly(True) # setup sequence type self.seqType.addItems([ 'Spin Echo', 'Gradient Echo', 'SE (slice)', 'GRE (slice)', 'Turbo Spin Echo', 'EPI', 'EPI (grad_y off)', 'Spiral' ]) self.seqType.currentIndexChanged.connect( self.seq_type_customized_display) self.etlComboBox.addItems(['2', '4', '8', '16', '32']) self.etlLabel.setVisible(False) self.etlComboBox.setVisible(False) self.uploadSeqButton.clicked.connect(self.upload_seq) # setup imaging parameters self.npe.addItems(['4', '8', '16', '32', '64', '128', '256']) self.npe.currentIndexChanged.connect(self.set_readout_size) self.size1.setText(self.npe.currentText()) self.size1.setReadOnly(True) # disable GUI elements at first self.startButton.setEnabled(True) self.stopButton.setEnabled(False) self.uploadSeqButton.setEnabled(False) self.acquireButton.setEnabled(False) self.loadShimButton.setEnabled(False) self.zeroShimButton.setEnabled(False) # setup buffer and offset for incoming data self.size = 50000 # total data received (defined by the server code) self.buffer = bytearray(8 * self.size) self.offset = 0 self.data = np.frombuffer(self.buffer, np.complex64) # setup display # display 1: real time signal self.figure = Figure() self.figure.set_facecolor('none') # top and bottom axes: 2 rows, 1 column self.axes_top = self.figure.add_subplot(2, 1, 1) self.axes_bottom = self.figure.add_subplot(2, 1, 2) self.canvas = FigureCanvas(self.figure) self.plotLayout.addWidget(self.canvas) # create navigation toolbar self.toolbar = NavigationToolbar(self.canvas, self.plotWidget, False) self.plotLayout.addWidget(self.toolbar) # display 2: k-space and image self.figure2 = Figure() self.figure2.set_facecolor('whitesmoke') self.axes_k_amp = self.figure2.add_subplot(3, 1, 1) self.axes_k_pha = self.figure2.add_subplot(3, 1, 2) self.axes_image = self.figure2.add_subplot(3, 1, 3) self.canvas2 = FigureCanvas(self.figure2) self.imageLayout.addWidget(self.canvas2) # create navigation toolbar self.toolbar2 = NavigationToolbar(self.canvas2, self.imageWidget, False) self.imageLayout.addWidget(self.toolbar2) # Acquire image self.full_data = np.matrix(np.zeros(np.size(self.data))) self.fname = "acq_data" self.buffers_received = 0 self.images_received = 0 self.num_pe = 0 self.num_TR = 0 # num_TR = num_pe/etl (echo train length) self.etl = 2 self.etl_idx = 0 self.npe_idx = 0 self.seqType_idx = 0 self.img = [] self.kspace_full = [] # full data self.kspace = [] # for recon self.k_amp = [] # for display self.k_pha = [] # for display self.tse_kspace = [] self.tse_k_amp = [] self.tse_k_pha = [] self.kspace_center = 475 # k center time = 1.9*250: echo time is at 1.9ms after acq start self.crop_factor = 640 # 64 matrix size ~ 640 readout length (need FURTHER CALIBRATION)
def __init__(self): super(MRI_Proj_Widget, self).__init__() self.setupUi(self) self.idle = True # state variable: True-stop, False-start self.if_all_projections = 0 # 0 - one projection, 1 - all three projections self.acq_num = 0 # for recording the 3 projections self.startButton.clicked.connect(self.start) self.stopButton.clicked.connect(self.stop) self.freqValue.valueChanged.connect(self.set_freq) # self.freqCheckBox = QCheckBox('Zoom') # self.checkBoxLayout.addWidget(self.freqCheckBox) self.projAxisValue.addItems(['x', 'y', 'z']) self.projAxisValue.currentIndexChanged.connect(self.set_proj_axis) self.acquireButton.clicked.connect(self.acquire) self.acquireAllButton.clicked.connect(self.acquire_all) # Gradient offsets related self.loadShimButton.clicked.connect(self.load_shim) self.zeroShimButton.clicked.connect(self.zero_shim) self.shim_x.setText(str(parameters.get_grad_offset_x())) self.shim_y.setText(str(parameters.get_grad_offset_y())) self.shim_z.setText(str(parameters.get_grad_offset_z())) self.shim_x.setReadOnly(True) self.shim_y.setReadOnly(True) self.shim_z.setReadOnly(True) # Disable if not start yet self.startButton.setEnabled(True) self.stopButton.setEnabled(False) self.projAxisValue.setEnabled(False) self.acquireButton.setEnabled(False) self.acquireAllButton.setEnabled(False) self.loadShimButton.setEnabled(False) self.zeroShimButton.setEnabled(False) # Setup buffer and offset for incoming data self.size = 50000 # total data received (defined by the server code) self.buffer = bytearray(8 * self.size) self.offset = 0 self.data = np.frombuffer(self.buffer, np.complex64) self.data_x = np.frombuffer(self.buffer, np.complex64) self.data_y = np.frombuffer(self.buffer, np.complex64) self.data_z = np.frombuffer(self.buffer, np.complex64) # print(self.data.size) # Setup plot self.figure = Figure() self.figure.set_facecolor('none') # top and bottom axes: 2 rows, 1 column self.axes_top = self.figure.add_subplot(2, 1, 1) self.axes_bottom = self.figure.add_subplot(2, 1, 2) self.canvas = FigureCanvas(self.figure) self.plotLayout.addWidget(self.canvas) # create navigation toolbar self.toolbar = NavigationToolbar(self.canvas, self.plotWidget, False) # remove subplots action (might be useful in the future) # actions = self.toolbar.actions() # self.toolbar.removeAction(actions[7]) self.plotLayout.addWidget(self.toolbar) # Setup plot for all three projections self.all_proj_figure = Figure() self.all_proj_figure.set_facecolor('none') # top and bottom axes: 3 rows, 1 column self.plot_x = self.all_proj_figure.add_subplot(3, 1, 1) self.plot_y = self.all_proj_figure.add_subplot(3, 1, 2) self.plot_z = self.all_proj_figure.add_subplot(3, 1, 3) # self.all_proj_figure.tight_layout() self.all_proj_figure.subplots_adjust(hspace=0.300) self.all_proj_canvas = FigureCanvas(self.all_proj_figure) self.allProjLayout.addWidget(self.all_proj_canvas) self.all_proj_toolbar = NavigationToolbar(self.all_proj_canvas, self.allProjWidget, False) self.allProjLayout.addWidget(self.all_proj_toolbar)
def __init__(self): super(MRI_3DImag_Widget, self).__init__() self.setupUi(self) self.idle = True # state variable: True-stop, False-start self.startButton.clicked.connect(self.start) self.stopButton.clicked.connect(self.stop) self.freqValue.valueChanged.connect(self.set_freq) self.acquireButton.clicked.connect(self.acquire) # Gradient offsets related self.loadShimButton.clicked.connect(self.load_shim) self.zeroShimButton.clicked.connect(self.zero_shim) self.shim_x.setText(str(parameters.get_grad_offset_x())) self.shim_y.setText(str(parameters.get_grad_offset_y())) self.shim_z.setText(str(parameters.get_grad_offset_z())) self.shim_x.setReadOnly(True) self.shim_y.setReadOnly(True) self.shim_z.setReadOnly(True) # Sequence Type self.seqType.addItems(['Spin Echo', 'Gradient Echo']) # self.seqType.addItems(['Spin Echo', 'Gradient Echo', 'Turbo Spin Echo']) # Imaging parameters self.npe.addItems(['4', '8', '16', '32', '64', '128', '256']) self.npe.currentIndexChanged.connect(self.set_readout_size) self.npe2.addItems(['4', '8', '16', '32']) self.size1.setText(self.npe.currentText()) self.size1.setReadOnly(True) # Disable if not start yet self.startButton.setEnabled(True) self.stopButton.setEnabled(False) self.acquireButton.setEnabled(False) self.loadShimButton.setEnabled(False) self.zeroShimButton.setEnabled(False) # Setup buffer and offset for incoming data self.size = 50000 # total data received (defined by the server code) self.buffer = bytearray(8 * self.size) self.offset = 0 self.data = np.frombuffer(self.buffer, np.complex64) # print(self.data.size) # Setup plot self.figure = Figure() self.figure.set_facecolor('none') # top and bottom axes: 2 rows, 1 column self.axes_top = self.figure.add_subplot(2, 1, 1) self.axes_bottom = self.figure.add_subplot(2, 1, 2) self.canvas = FigureCanvas(self.figure) self.plotLayout.addWidget(self.canvas) # create navigation toolbar self.toolbar = NavigationToolbar(self.canvas, self.plotWidget, False) # remove subplots action (might be useful in the future) # actions = self.toolbar.actions() # self.toolbar.removeAction(actions[7]) self.plotLayout.addWidget(self.toolbar) # Acquire image self.full_data = np.matrix(np.zeros(np.size(self.data))) self.fnameprefix = "acq_data_aspa_se_64_16_" self.fname = "" self.buffers_received = 0 # for npe phase encoding 1 self.slice_received = 0 # for npe2 phase encoding 2 self.num_pe = 0 # self.num_TR self.num_pe2 = 0 self.npe_idx = 0 self.npe2_idx = 0 self.seqType_idx = 0