Exemplo n.º 1
0
    def init_flipangle(self):
        # Setup values and axis
        self.init_vars()
        self.at_results = []
        self.ax1.clear()
        self.ax2.clear()
        self.ax3.clear()
        self.progressBar.setValue(0)
        self.flipangle_save_btn.setEnabled(False)
        self.flipangle_flag = True

        # Read input parameters and
        params.flipStart = self.atStart_input.value()
        params.flipEnd = self.atEnd_input.value()
        params.flipStep = self.atSteps_input.value()
        params.flipTimeout = self.atTimeout_input.value()
        logger.add('FLA')

        self.data.set_freq(params.freq)
        self.at_values = np.around(
            np.linspace(params.flipStart, params.flipEnd, params.flipStep) *
            4) / 4
        print("Attenuation values : ", self.at_values)

        # Disable controls and start
        self.disable_controls()
        self.flipangle_run()
Exemplo n.º 2
0
    def measureT1(self):
        print("Start T1")

        # Setup and update parameters
        self.dataAvailableFlag = False
        self.ax1.clear()
        self.ax1.set_ylabel('acquired RX signals [mV]')
        self.ax1.set_xlabel('time [ms]')
        self.ax2.clear()
        self.ax2.set_ylabel('RX signal peak [mV]')
        self.ax2.set_xlabel('time of inversion (TI) [ms]')
        self.controls.setEnabled(False)
        self.plotNav_widget.setVisible(False)
        self.time_ax = []
        self.acq_data = []
        self.datapoints_ti = []
        self.datapoints_peaks = []

        self.update_params()
        params.saveFile()

        # Calculate all TI values from input
        self.TI_values = np.rint(
            np.logspace(np.log10(params.t1Start), np.log10(params.t1End),
                        params.t1Step))
        print(self.TI_values)

        # Determine averaging variables
        avgPoint = 1
        avgMeas = 1
        #if self.measAvg_enable.isChecked(): avgMeas = self.measAvg_input.value()
        if self.dataAvg_enable.isChecked():
            avgPoint = self.dataAvg_input.value()
        self.n_acq = params.t1Step * avgMeas * avgPoint
        self.acq_count = 0

        # Set fixed output values:
        self.freq_output.setText(str(round(params.freq, 5)))
        self.at_output.setText(str(params.at))
        duration = round(
            (params.t1Recovery + sum(self.TI_values)) * self.n_acq / 1000, 2)
        self.dur_output.setText(str(duration))

        self.call_update.emit()

        # Call T1 function from dataHandler
        t1, r2 = self.data.T1_measurement(self.TI_values, params.freq, params.t1Recovery,\
            avgP = avgPoint, avgM = avgMeas, seqType = self.seq)
        print("AVGP: {}, AVGM: {}".format(avgPoint, avgMeas))
        logger.add('T1',
                   res=t1,
                   err=r2,
                   val=self.TI_values,
                   seq=self.seq,
                   avgP=avgPoint)  #, avgM = avgMeas)

        #if avgMeas > 1: self.interactive_plot()
        self.controls.setEnabled(True)
        self.dataAvailableFlag = True
Exemplo n.º 3
0
    def acq_handler(self): # Function to handle current acquisition mode -- called whenever signal received
        print("Handling acquisition event.")

        # Set CC output parameters
        self.load_params()
        self.set_output(params.freq, params.at, self.data.center_freq,\
            self.data.peak_value, self.data.fwhm_value, self.data.snr)

        if self.seq_selector.currentIndex()==0: logger.add('ACQ', seq='FID',\
            peak=self.data.peak_value, fwhm=self.data.fwhm_value, snr=self.data.snr)
        elif self.seq_selector.currentIndex()==1: logger.add('ACQ', seq='SE',\
            peak=self.data.peak_value, fwhm=self.data.fwhm_value, snr=self.data.snr)
        elif self.seq_selector.currentIndex()==2: logger.add('ACQ', seq='IR',\
            peak=self.data.peak_value, fwhm=self.data.fwhm_value, snr=self.data.snr)
        elif self.seq_selector.currentIndex()==3: logger.add('ACQ', seq='SIR',\
            peak=self.data.peak_value, fwhm=self.data.fwhm_value, snr=self.data.snr)
        else: print("No log entry, unknown sequence.")

        # Make log entry

        if self.manualAvg_enable.isChecked(): # Handel averaging and manual trigger
            self.fft_mag_avg = np.add(self.fft_mag_avg, self.data.fft_mag)
            self.t_mag_avg = np.add(self.t_mag_avg, self.data.mag_t)
            self.t_real_avg = np.add(self.t_real_avg, self.data.real_t)
            self.t_imag_avg = np.add(self.t_imag_avg, self.data.imag_t)
            self.two_ax_plot()
            time.sleep(self.timeout)
            self.freqsweep_run()
            return

        if self.autocenter_flag == True: # Handel autocenter acquisition
            self.peaks.append(self.data.peak_value)
            if self.data.peak_value > self.peakValue and self.acqCount>0:
                # Change peak and center frequency value
                self.peakValue = self.data.peak_value
                self.centerValue = self.data.center_freq
                self.autocenter_output.setText(str(round(self.centerValue,4)))
            self.autocenter_plot() # calls 2-axis plot as well
            self.progressBar.setValue(self.acqCount/len(self.freqSpace)*100)
            self.call_update.emit()

            time.sleep(params.autoTimeout/1000)
            self.freqsweep_run()

        if self.flipangle_flag == True: # Handel flipangle tool acquisition
            if self.acqCount > 0:
                self.at_results.append(round(self.data.peak_value, 2))
            self.flipangle_plot() # calls 2-axis plot as well
            self.progressBar.setValue(self.acqCount/len(self.at_values)*100)
            self.call_update.emit()

            time.sleep(params.flipTimeout/1000)
            self.flipangle_run()

        else: self.two_ax_plot(); # Calls two axis plot for manual trigger
Exemplo n.º 4
0
    def measureT2(self):
        print("Start T2")

        # Setup and update parameters
        self.ax1.clear(); self.ax1.set_ylabel('acquired RX signals [mV]'); self.ax1.set_xlabel('time [ms]')
        self.ax2.clear(); self.ax2.set_ylabel('RX signal peak [mV]'); self.ax2.set_xlabel('echo time (TE) [ms]')
        self.controls.setEnabled(False)
        self.plotNav_widget.setVisible(False)
        self.time_ax = []; self.acq_data = []
        self.datapoints_te = []; self.datapoints_peaks = []

        self.update_params()
        params.saveFile()

        # Calculate all TE values from input
        self.TE_values = np.rint(np.logspace(np.log10(params.t2Start), np.log10(params.t2End), params.t2Step))
        print(self.TE_values)

        # Determine averaging variables
        avgPoint = 1; avgMeas = 1
        if self.measAvg_enable.isChecked(): avgMeas = self.measAvg_input.value()
        if self.dataAvg_enable.isChecked(): avgPoint = self.dataAvg_input.value()
        self.n_acq = params.t2Step*avgMeas*avgPoint
        self.acq_count = 0

        # Set fixed output values:
        self.freq_output.setText(str(round(params.freq, 5)))
        self.at_output.setText(str(params.at))
        duration = round((params.t2Recovery + sum(self.TE_values))*self.n_acq/1000,2)
        self.dur_output.setText(str(duration))

        self.call_update.emit()

        # Call T2 function from dataHandler
        t2, r2 = self.data.T2_measurement(self.TE_values, params.freq, params.t2Recovery,\
            avgP = avgPoint, avgM = avgMeas)
        logger.add('T2', res=t2, err=r2, val=self.TE_values, avgP = avgPoint, avgM = avgMeas)

        # Setup results and call interactive plot tool if necessary
        self.t2_output.setText(str(round(t2,2)))
        self.r2_output.setText(str(round(r2,4)))

        if avgMeas > 1: self.interactive_plot()
        self.controls.setEnabled(True)
Exemplo n.º 5
0
    def init_autocenter(self):
        # Setup values and axis
        self.init_vars()
        self.ax1.clear(); self.ax2.clear(); self.ax3.clear();
        self.progressBar.setValue(0)
        self.autocenter_flag = True
        self.peaks = []

        # Read input values
        params.autoSpan = self.freqSpan_input.value()
        params.autoStep = self.freqSteps_input.value()
        params.autoTimeout = self.freqTimeout_input.value()
        logger.add('AUC')

        self.freqSpace = np.linspace(params.freq-params.autoSpan/2, params.freq+params.autoSpan/2,\
            params.autoStep)

        print("Frequency space : ", self.freqSpace)

        # Disable controls and start
        self.disable_controls()
        self.freqsweep_run()
Exemplo n.º 6
0
    def protocol_exec(self):
        '''
        # Implement switch-case for protocol execution
        def measurement(): # Measure T1 or T2
            start = int(self.protocol.item(0,1).text())
            stop = int(self.protocol.item(0,3).text())
            steps = int(self.protocol.item(0,5).text())
            tVals = np.rint(np.logspace(np.log10(start), np.log10(stop), steps))
            recovery = int(self.protocol.item(0,7).text())
            self.fitPlottedFlag = False

            if int(self.protocol.item(0,9).text()) < 1 or \
                int(self.protocol.item(0,11).text()) < 1:
                avgm = 1; avgp = 1
            else:
                avgm = int(self.protocol.item(0,9).text())
                avgp = int(self.protocol.item(0,11).text())

            self.clear_fig()
            self.call_update.emit()
            if self.cmd == self.cmdElements[0]:
                t1, t1_Rsq = self.data.T1_measurement(tVals, params.freq, recovery, avgM=avgm, avgP=avgp)
                logger.add('T1', res=t1, err=t1_Rsq, val=tVals, seq='SIR', avgM=avgm, avgP=avgp)
                self.protocolCC.update_output_params(t1Res=t1, t1Err=t1_Rsq)
            else:
                t2, t2_Rsq = self.data.T2_measurement(tVals, params.freq, recovery, avgM=avgm, avgP=avgp)
                logger.add('T2', res=t2, err=t2_Rsq, val=tVals, avgM=avgm, avgP=avgp)
                self.protocolCC.update_output_params(t2Res=t2, t2Err=t2_Rsq)
        def pause(): # Pause execution
            print('Pause.')
            ptime = int(self.protocol.item(0,1).text())
            logger.add('PAUSE', dur=ptime)
            self.popup.show()
            self.popup.set(ptime, 'Pause protocol execution for {} seconds.'.format(ptime), progress=True)
            break
        def temperature(): # Set temperature
            print('Wait for temperature set.')
            logger.add('TEMP')
            self.popup.show()
            self.popup.set(-1, 'Set the chiller temperature and confirm!', btnTxt='Confirm')
            break
        def sample(): # Exchange sample
            print('Wait for sample exchange.')
            logger.add('CHNG')
            self.popup.show()
            self.popup.set(-1, 'Change the sample and confirmed!', btnTxt='Confirm')
            break
        def calibration(): # Calibrate the system
            self.protocolCC.update()
            print("Calibrate Frequency.")
            self.sys_calibrate()
            if self.data.peak_value < 50:
                self.popup.show()
                self.popup.set(-1, 'Calibration was not successful!\n Please calibrate manually.', btnTxt='Ok')
                logger.add('CAL', status=False)
                self.enable_prot()
                break
            else: logger.add('CAL')
        '''
        while self.cmdList != []:  # while cmd list is not empty
            self.cmd = self.cmdList[0]  # Get actual command
            self.protocolCC.update_output_params(
                step=str(self.stepsCount + 1 - len(self.cmdList)) + '/' +
                str(self.stepsCount))
            self.protocolCC.execProgress.setValue(sum(self.progVals\
                [0:self.stepsCount-len(self.cmdList)])*100/sum(self.progVals))

            # T1 or T2 measurement
            if self.cmd == self.cmdElements[0] or self.cmd == self.cmdElements[
                    1]:

                start = int(float(self.protocol.item(0, 1).text()))
                stop = int(float(self.protocol.item(0, 3).text()))
                steps = int(float(self.protocol.item(0, 5).text()))
                tVals = np.rint(
                    np.logspace(np.log10(start), np.log10(stop), steps))

                recovery = int(float(self.protocol.item(0, 7).text()))

                self.fitPlottedFlag = False

                if int(float(self.protocol.item(0,9).text())) < 1 or \
                    int(float(self.protocol.item(0,11).text())) < 1:
                    avgm = 1
                    avgp = 1
                else:
                    avgm = int(float(self.protocol.item(0, 9).text()))
                    avgp = int(float(self.protocol.item(0, 11).text()))

                self.clear_fig()
                self.call_update.emit()

                if self.cmd == self.cmdElements[0]:
                    t1, t1_Rsq = self.data.T1_measurement(tVals,
                                                          params.freq,
                                                          recovery,
                                                          avgM=avgm,
                                                          avgP=avgp)
                    logger.add('T1',
                               res=t1,
                               err=t1_Rsq,
                               val=tVals,
                               seq='SIR',
                               avgM=avgm,
                               avgP=avgp)
                    self.protocolCC.update_output_params(t1Res=t1,
                                                         t1Err=t1_Rsq)
                else:
                    t2, t2_Rsq = self.data.T2_measurement(tVals,
                                                          params.freq,
                                                          recovery,
                                                          avgM=avgm,
                                                          avgP=avgp)
                    logger.add('T2',
                               res=t2,
                               err=t2_Rsq,
                               val=tVals,
                               avgM=avgm,
                               avgP=avgp)
                    self.protocolCC.update_output_params(t2Res=t2,
                                                         t2Err=t2_Rsq)

            # Pause, Temperature, Change Sample
            else:  # Not T1 or T2
                self.popup = protocol_popup(parent=self)
                self.popup.event_finished.connect(self.continue_protocol_exec)
                # Pause
                if self.cmd == self.cmdElements[2]:
                    print('Pause.')
                    pause = int(float(self.protocol.item(0, 1).text()))
                    logger.add('PAUSE', dur=pause)
                    self.popup.show()
                    self.popup.set(
                        pause,
                        'Pause protocol execution for {} seconds.'.format(
                            pause),
                        progress=True)
                    break
                # Change Temperature
                elif self.cmd == self.cmdElements[3]:
                    print('Wait for temperature set.')
                    logger.add('TEMP')
                    self.popup.show()
                    self.popup.set(-1,
                                   'Set the chiller temperature and confirm!',
                                   btnTxt='Confirm')
                    break
                # Sample Exchange
                elif self.cmd == self.cmdElements[4]:
                    print('Wait for sample exchange.')
                    logger.add('CHNG')
                    self.popup.show()
                    self.popup.set(-1,
                                   'Change the sample and confirmed!',
                                   btnTxt='Confirm')
                    break
                # Frequency Calibration
                elif self.cmd == self.cmdElements[5]:
                    self.protocolCC.update()
                    print("Calibrate Frequency.")
                    self.sys_calibrate()
                    if self.data.peak_value < 50:
                        self.popup.show()
                        self.popup.set(
                            -1,
                            'Calibration was not successful!\n Please calibrate manually.',
                            btnTxt='Ok')
                        logger.add('CAL', status=False)
                        self.enable_prot()
                        break
                    else:
                        logger.add('CAL')
            '''
            if not self.cmd == self.cmdElements[0] and not self.cmdElements[1]:
                self.popup = protocol_popup(parent=self)
                self.popup.event_finished.connect(self.continue_protocol_exec)

            tasks = {
                0: measurement,
                1: measurement,
                2: pause,
                3: temperature,
                4: sample,
                5: calibration
            }

            tasks[self.cmd]()
            '''

            # Remove executed command
            self.protocol.removeRow(0)
            del self.cmdList[0]
            self.call_update.emit()

        # Protocol execution finished
        if self.cmdList == []:
            self.protocolCC.execProgress.setValue(sum(self.progVals\
                [0:self.stepsCount-len(self.cmdList)])*100/sum(self.progVals))
            self.enable_prot()
            print("Finished protocol execution. \n")