예제 #1
0
def larmor(self, fid_SE=1,  # 0=FID, 1=SE
                lo_freq=0.5, 
                step=0.1,  # MHz
                bw2=0.2):  # BW/2 of search (MHz)

    freqPeak=lo_freq
    peak_f = 0
#    peakIdx=0

    n = (2*bw2/step)+1
    f = np.linspace(freqPeak-bw2, freqPeak+bw2, n) 
    for ff in f:
        
        if fid_SE==0:
            self.rxd, self.msgs=fid(lo_freq=ff)  # use fid or spin_echo
        else:
            self.rxd, self.msgs=spin_echo(lo_freq=ff)
        
        dataobject:DataManager=DataManager(self.rxd, ff, len(self.rxd))
        f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters(self)
        
        if (f_signalValue > peak_f):
            peak_f=f_signalValue
#                peak_t=t_signalValue
#                peakIdx=f_signalIdx
            freqPeak=f_signalFrequency
        

    return(freqPeak, peak_f)
예제 #2
0
    def button_clicked(self):

        #        if self.button.isChecked():
        self.parent.clearPlotviewLayout()
        im = self.kspace
        im2 = np.moveaxis(im, 0, -1)
        im3 = np.reshape(
            im2,
            (self.sequence.n_sl * self.sequence.n_ph * self.sequence.n_rd))
        self.sequence.ns = self.sequence.ns[1:] + self.sequence.ns[:1]

        self.dataobject: DataManager = DataManager(im3, self.sequence.lo_freq,
                                                   len(im3), self.sequence.ns,
                                                   self.sequence.BW)

        self.button.setChecked(False)

        self.plot_3Dresult()
예제 #3
0
if __name__ == "__main__":

    lo_freq = 3.041
    N_amp = 10
    BW = 31

    rxd = flipAngle(N_amp=N_amp, lo_freq=lo_freq, BW=BW)
    values = rxd
    samples = np.int32(len(values) / N_amp)
    i = 0
    s = 0
    peakValsf = []
    while i < N_amp:
        d_cropped = values[s:s + samples]

        dataobject: DataManager = DataManager(d_cropped, lo_freq,
                                              len(d_cropped), [], BW)
        f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters(
        )
        peakValsf.append(f_signalValue)

        s = s + samples
        i = i + 1

#    plt.plot(dataobject.f_fftMagnitude)
#    plt.show()

    plt.plot(peakValsf)
    plt.show()
예제 #4
0
    def save_data(self):

        dataobject: DataManager = DataManager(
            self.data_avg, self.sequence.lo_freq, len(self.data_avg),
            [self.sequence.n_rd, self.sequence.n_ph, self.sequence.n_sl],
            self.sequence.BW)
        dict1 = vars(defaultsessions[self.session])
        dict2 = vars(self.sequence)
        dict = self.merge_two_dicts(dict1, dict2)
        dt = datetime.now()
        dt_string = dt.strftime("%d-%m-%Y_%H:%M")
        dt2 = date.today()
        dt2_string = dt2.strftime("%d-%m-%Y")
        dict["rawdata"] = self.rxd
        dict["fft"] = dataobject.f_fftData
        if not os.path.exists('experiments/acquisitions/%s' % (dt2_string)):
            os.makedirs('experiments/acquisitions/%s' % (dt2_string))

        if not os.path.exists('experiments/acquisitions/%s/%s' %
                              (dt2_string, dt_string)):
            os.makedirs('experiments/acquisitions/%s/%s' %
                        (dt2_string, dt_string))

        if not os.path.exists(
                '/media/physiomri/TOSHIBA\ EXT/experiments/acquisitions/%s' %
            (dt2_string)):
            os.makedirs('/media/physiomri/TOSHIBA\ EXT/%s' % (dt2_string))

        if not os.path.exists(
                '/media/physiomri/TOSHIBA\ EXT/experiments/acquisitions/%s/%s'
                % (dt2_string, dt_string)):
            os.makedirs('/media/physiomri/TOSHIBA\ EXT/%s/%s' %
                        (dt2_string, dt_string))

        savemat(
            "experiments/acquisitions/%s/%s/%s.mat" %
            (dt2_string, dt_string, self.sequence), dict)
        savemat(
            "/media/physiomri/TOSHIBA\ EXT/%s/%s/%s.mat" %
            (dt2_string, dt_string, self.sequence), dict)

        self.messages("Data saved")

        #        if hasattr(self.dataobject, 'f_fft2Magnitude'):
        #            nifti_file=nib.Nifti1Image(self.dataobject.f_fft2Magnitude, affine=np.eye(4))
        #            nib.save(nifti_file, 'experiments/acquisitions/%s/%s/%s.%s.nii'% (dt2_string, dt_string, dict["seq"],dt_string))

        if hasattr(self.parent, 'f_plotview'):
            exporter1 = pyqtgraph.exporters.ImageExporter(
                self.f_plotview.scene())
            exporter1.export("experiments/acquisitions/%s/%s/Freq%s.png" %
                             (dt2_string, dt_string, self.sequence))
        if hasattr(self.parent, 't_plotview'):
            exporter2 = pyqtgraph.exporters.ImageExporter(
                self.t_plotview.scene())
            exporter2.export("experiments/acquisitions/%s/%s/Temp%s.png" %
                             (dt2_string, dt_string, self.sequence))

        from controller.WorkerXNAT import Worker

        if self.xnat_active == 'TRUE':
            # Step 2: Create a QThread object
            self.thread = QThread()
            # Step 3: Create a worker object
            self.worker = Worker()
            # Step 4: Move worker to the thread
            self.worker.moveToThread(self.thread)
            # Step 5: Connect signals and slots
            self.thread.started.connect(
                partial(
                    self.worker.run, 'experiments/acquisitions/%s/%s' %
                    (dt2_string, dt_string)))
            self.worker.finished.connect(self.thread.quit)
            self.worker.finished.connect(self.worker.deleteLater)
            self.thread.finished.connect(self.thread.deleteLater)

            # Step 6: Start the thread
            self.thread.start()
예제 #5
0
    def startCalibAcq(self):

        self.layout.setParent(None)
        self.parent.clearPlotviewLayout()
        self.calibfunction = defaultcalibfunctions[
            self.calibfunctionslist.getCurrentCalibfunction()]

        if self.calibfunction.cfn == 'Rabi Flops':
            self.rxd, self.msgs = rabi_flops(self.calibfunction)
            values = self.rxd
            samples = np.int32(len(values) / self.calibfunction.N)
            i = 0
            s = 0
            peakValsf = []
            peakValst = []
            while i < self.calibfunction.N:
                d_cropped = values[s:s + samples]

                dataobject: DataManager = DataManager(
                    d_cropped, self.calibfunction.lo_freq, len(d_cropped), [],
                    self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters(
                )
                peakValsf.append(f_signalValue)
                peakValst.append(dataobject.t_magnitude[0])

                s = s + samples
                i = i + 1

            f_plotview = SpectrumPlot(
                dataobject.f_axis, dataobject.f_fftMagnitude, [], [],
                'Frequency (kHz)', "Amplitude",
                "%s Spectrum (last pulse)" % (self.calibfunction.cfn))
            t_plotview = SpectrumPlot(
                np.linspace(self.calibfunction.rf_pi2_duration0,
                            self.calibfunction.rf_pi2_durationEnd,
                            self.calibfunction.N), peakValst, [], [],
                'Excitation duration (us)', "pi2 pulse duration",
                "%s" % (self.calibfunction.cfn))
            self.parent.plotview_layout.addWidget(t_plotview)
            self.parent.plotview_layout.addWidget(f_plotview)

        elif self.calibfunction.cfn == 'Inversion Recovery':
            self.rxd, self.msgs = inversionRecovery(self.calibfunction)
            values = self.rxd
            samples = np.int32(len(values) / self.calibfunction.N)
            i = 0
            s = 0
            peakValsf = []
            peakValst = []
            while i < self.calibfunction.N:
                d_cropped = values[s:s + samples]

                dataobject: DataManager = DataManager(
                    d_cropped, self.calibfunction.lo_freq, len(d_cropped), [],
                    self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters(
                )
                peakValsf.append(f_signalValue)
                peakValst.append(dataobject.t_magnitude[0])

                s = s + samples
                i = i + 1

            f_plotview = SpectrumPlot(
                dataobject.f_axis, dataobject.f_fftMagnitude, [], [],
                'Frequency (kHz)', "Amplitude",
                "%s Spectrum (last pulse)" % (self.calibfunction.cfn))
            t_plotview = SpectrumPlot(
                np.linspace(
                    self.calibfunction.echo_duration / 2 -
                    self.calibfunction.rf_duration * 1e-3,
                    self.calibfunction.echo_duration / 2 -
                    self.calibfunction.rf_duration * 1e-3 +
                    self.calibfunction.N * self.calibfunction.step -
                    self.calibfunction.step, self.calibfunction.N), peakValst,
                [], [], 'Time between pulses (ms)', "Amplitude",
                "%s" % (self.calibfunction.cfn))
            self.parent.plotview_layout.addWidget(t_plotview)
            self.parent.plotview_layout.addWidget(f_plotview)

        elif self.calibfunction.cfn == 'Shimming':
            self.rxd, self.msgs = shimming(self.calibfunction, 'x')
            values_x = self.rxd
            self.rxd, self.msgs = shimming(self.calibfunction, 'y')
            values_y = self.rxd
            self.rxd, self.msgs = shimming(self.calibfunction, 'z')
            values_z = self.rxd

            samples = np.int32(len(values_x) / self.calibfunction.N)

            i = 0
            s = 0
            self.peakValsf_x = []
            self.fwhmf_x = []
            self.peakValsf_y = []
            self.fwhmf_y = []
            self.peakValsf_z = []
            self.fwhmf_z = []
            while i < self.calibfunction.N:
                #############################

                d_cropped_x = values_x[s:s + samples]
                d_cropped_y = values_y[s:s + samples]
                d_cropped_z = values_z[s:s + samples]

                #############################

                dataobject_x: DataManager = DataManager(
                    d_cropped_x, self.calibfunction.lo_freq, len(d_cropped_x),
                    [], self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject_x.get_peakparameters(
                )
                self.peakValsf_x.append(f_signalValue)
                fwhm, fwhm_hz, fwhm_ppm = dataobject_x.get_fwhm()
                self.fwhmf_x.append(fwhm_hz)

                #############################

                dataobject_y: DataManager = DataManager(
                    d_cropped_y, self.calibfunction.lo_freq, len(d_cropped_y),
                    [], self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject_y.get_peakparameters(
                )
                self.peakValsf_y.append(f_signalValue)
                fwhm, fwhm_hz, fwhm_ppm = dataobject_y.get_fwhm()
                self.fwhmf_y.append(fwhm_hz)

                #############################

                dataobject_z: DataManager = DataManager(
                    d_cropped_z, self.calibfunction.lo_freq, len(d_cropped_z),
                    [], self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject_z.get_peakparameters(
                )
                self.peakValsf_z.append(f_signalValue)
                fwhm, fwhm_hz, fwhm_ppm = dataobject_z.get_fwhm()
                self.fwhmf_z.append(fwhm_hz)

                ##############################

                s = s + samples
                i = i + 1

            self.plot_shim(axis='x')

        elif self.calibfunction.cfn == 'Larmor Frequency':
            repetitions = np.int32(self.calibfunction.step /
                                   self.calibfunction.resolution)
            while i < repetitions:
                self.peakVals, self.freqs = larmorFreq(self.calibfunction)
                t_plotview = SpectrumPlot(self.freqs, self.peakVals, [], [],
                                          'Larmor Frequency variation (MHz)',
                                          "Amplitude (mV)",
                                          "%s" % (self.calibfunction.cfn))
                self.parent.plotview_layout.addWidget(t_plotview)
                self.calibfunction.step = self.calibfunction.step / 2
                f_signalValue: float = round(np.max(self.peakVals), 4)
                f_signalIdx: int = np.argmax(self.f_signalValue)
                self.calibfunction.lo_freq = self.freqs[f_signalIdx]
                i = i + 1

        elif self.calibfunction.cfn == 'Amplitude':
            self.rxd, self.msgs, self.amps = flipAngle(self.calibfunction)
            values = self.rxd
            samples = np.int32(len(values) / self.calibfunction.N)
            i = 0
            s = 0
            peakValsf = []
            while i < self.calibfunction.N:
                d_cropped = values[s:s + samples]

                dataobject: DataManager = DataManager(
                    d_cropped, self.calibfunction.lo_freq, len(d_cropped), [],
                    self.calibfunction.BW)
                f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters(
                )
                peakValsf.append(f_signalValue)

                s = s + samples
                i = i + 1

#            t_plotview = SpectrumPlot(np.linspace(-self.calibfunction.N/2*self.calibfunction.step, self.calibfunction.N/2*self.calibfunction.step, self.calibfunction.N), peakValsf, [],[],'Flip Angle value', "Amplitude (mV)", "%s" %(self.calibfunction.cfn))
            t_plotview = SpectrumPlot(self.amps, peakValsf, [], [],
                                      'Flip Angle value', "Amplitude (mV)",
                                      "%s" % (self.calibfunction.cfn))
            self.parent.plotview_layout.addWidget(t_plotview)
예제 #6
0
def larmor(lo_freq=3.023, # MHz
             rf_amp=0.62, # 1 = full-scale
             rf_pi2_duration=50,
             N_larmor=5,  # Number of points
             step=1e-3,  # Step in Khz
             rx_wait = 100,   #us
             BW=31,  # us, 3.333us, 300 kHz rate
             readout_duration=5000,
             echo_duration=4,   #ms
             ):

           

    rx_period = 1/(BW*1e-3)
    echo_duration = echo_duration*1e3

    rf_pi_duration = 2*rf_pi2_duration
    BW = 1e-3   
       
    ## All times are in the context of a single TR, starting at time 0
    init_gpa = False
   
    tx_gate_pre = 2 # us, time to start the TX gate before the RF pulse begins
    tx_gate_post = 1 # us, time to keep the TX gate on after the RF pulse ends
    tstart = 0   
    pi2_phase = 1 # x
    pi_phase = 1j # y
    
    i=0
    peakValsf = []
    freqs = np.linspace(lo_freq-N_larmor/2*step, lo_freq+N_larmor/2*step, N_larmor)
    
    while i<N_larmor:
    
        expt = ex.Experiment(lo_freq=freqs[i], rx_t=rx_period, init_gpa=init_gpa, gpa_fhdo_offset_time=(1 / 0.2 / 3.1))
    
        rf_tend = tstart+echo_duration+rf_pi_duration/2 # us
        rx_tstart = rf_tend+rx_wait # us
        rx_tend = rx_tstart + readout_duration  # us
        expt.add_flodict({
            # second tx0 pulse purely for loopback debugging
            'tx0': (np.array([tstart + (echo_duration - rf_pi2_duration)/2, tstart + (echo_duration + rf_pi2_duration)/2,
                         tstart + echo_duration - rf_pi_duration/2, rf_tend]), np.array([pi2_phase*rf_amp, 0, pi_phase*rf_amp, 0])),
            'rx0_en': ( np.array([rx_tstart, rx_tend]),  np.array([1, 0]) ),
            'tx_gate': (np.array([tstart + (echo_duration - rf_pi2_duration)/2- tx_gate_pre, tstart + (echo_duration + rf_pi2_duration)/2 + tx_gate_post,
                         tstart + echo_duration - rf_pi_duration/2- tx_gate_pre, rf_tend+ tx_gate_post]), np.array([1, 0, 1, 0])),
            'rx_gate': ( np.array([rx_tstart, rx_tend]), np.array([1, 0]) )
        })
    
        rxd, msg = expt.run()    
        dataobject:DataManager=DataManager(rxd['rx0'], freqs[i], len(rxd['rx0']), [], BW)
        f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters()
        peakValsf.append(f_signalValue)
        
        expt.__del__()

        print(i)
        i = i+1
        
    
    
    return(peakValsf)
예제 #7
0
    def startAcquisition(self):

        if hasattr(self.parent, 'clearPlotviewLayout'):
            self.parent.clearPlotviewLayout()

        self.sequence = defaultsequences[
            self.sequencelist.getCurrentSequence()]
        self.sequence.oversampling_factor = 6

        plotSeq = 0
        if self.sequence.seq == 'RARE':
            print('Start sequence')
            self.rxd, self.msgs, self.data_avg, self.sequence.BW = rare(
                self.sequence, plotSeq)
            print('End sequence')
        elif self.sequence.seq == 'HASTE':
            print('Start sequence')
            self.rxd, self.msgs, self.data_avg, self.sequence.BW = haste(
                self.sequence, plotSeq)
            print('End sequence')
        elif self.sequence.seq == 'GRE3D':
            print('Start sequence')
            self.rxd, self.msgs, self.data_avg, self.sequence.BW = gre3d(
                self.sequence, plotSeq)
            print('End sequence')

        [self.sequence.n_rd, self.sequence.n_ph,
         self.sequence.n_sl] = self.sequence.nPoints
        self.dataobject: DataManager = DataManager(self.data_avg,
                                                   self.sequence.larmorFreq,
                                                   len(self.data_avg),
                                                   self.sequence.nPoints,
                                                   self.sequence.BW)
        self.sequence.ns = self.sequence.nPoints

        if not hasattr(self.parent, 'batch'):
            if (self.sequence.n_ph == 1 and self.sequence.n_sl == 1):
                f_plotview = SpectrumPlot(
                    self.dataobject.f_axis,
                    self.dataobject.f_fftMagnitude,
                    [],
                    [],
                    "Frequency (kHz)",
                    "Amplitude",
                    "%s Spectrum" % (self.sequence.seq),
                )
                t_plotview = SpectrumPlot(
                    self.dataobject.t_axis,
                    self.dataobject.t_magnitude,
                    self.dataobject.t_real,
                    self.dataobject.t_imag,
                    'Time (ms)',
                    "Amplitude (mV)",
                    "%s Raw data" % (self.sequence.seq),
                )
                self.parent.plotview_layout.addWidget(t_plotview)
                self.parent.plotview_layout.addWidget(f_plotview)
                self.parent.f_plotview = f_plotview
                self.parent.t_plotview = t_plotview
                [f_signalValue, t_signalValue, f_signalIdx,
                 f_signalFrequency] = self.dataobject.get_peakparameters()
                print('Peak Value = %0.3f' % (f_signalValue))

    #            snr=self.dataobject.get_snr()
    #            print('SNR:%0.3f' %(snr))

    #        elif(self.sequence.seq=='CPMG'):
    #            self.plot_cpmg()

            else:

                self.plot_3Dresult()

        self.parent.rxd = self.rxd
        self.parent.data_avg = self.data_avg
        self.parent.sequence = self.sequence
        print(self.msgs)
        #self.parent.save_data()
        self.save_data()
예제 #8
0
def larmorFreq(self):

    lo_freq=self.lo_freq # MHz
    rf_amp=self.rf_amp # 1 = full-scale
    N=self.N 
    step=self.step  
    rf_pi2_duration = self.rf_pi2_duration
    echo_duration = self.echo_duration*1e3
    BW=self.BW  # us, 3.333us, 300 kHz rate
    rx_wait=self.rx_wait*1e3
    readout_duration=self.readout_duration*1e3
    nScans=self.nScans
              

    rx_period = 1/(BW*1e-3)
    step = step*1e-3

    rf_pi_duration = 2*rf_pi2_duration
#    BW = BW*1e3   
       
    ## All times are in the context of a single TR, starting at time 0
    init_gpa = False
   
    tx_gate_pre = 2 # us, time to start the TX gate before the RF pulse begins
    tx_gate_post = 1 # us, time to keep the TX gate on after the RF pulse ends
    tstart = 0   
    pi2_phase = 1 # x
    pi_phase = 1j # y
    
    i=0
    peakValsf = []
    freqs = np.linspace(lo_freq-N/2*step, lo_freq+N/2*step, N)
    
    while i<N:
    
        expt = ex.Experiment(lo_freq=freqs[i], rx_t=rx_period, init_gpa=init_gpa, gpa_fhdo_offset_time=(1 / 0.2 / 3.1))
    
        rf_tend = tstart+echo_duration+rf_pi_duration/2 # us
        rx_tstart = rf_tend+rx_wait # us
        rx_tend = rx_tstart + readout_duration  # us
        expt.add_flodict({
            # second tx0 pulse purely for loopback debugging
            'tx0': (np.array([tstart + (echo_duration - rf_pi2_duration)/2, tstart + (echo_duration + rf_pi2_duration)/2,
                         tstart + echo_duration - rf_pi_duration/2, rf_tend]), np.array([pi2_phase*rf_amp, 0, pi_phase*rf_amp, 0])),
            'rx0_en': ( np.array([rx_tstart, rx_tend]),  np.array([1, 0]) ),
            'tx_gate': (np.array([tstart + (echo_duration - rf_pi2_duration)/2- tx_gate_pre, tstart + (echo_duration + rf_pi2_duration)/2 + tx_gate_post,
                         tstart + echo_duration - rf_pi_duration/2- tx_gate_pre, rf_tend+ tx_gate_post]), np.array([1, 0, 1, 0])),
            'rx_gate': ( np.array([rx_tstart, rx_tend]), np.array([1, 0]) )
        })
    
        rxd, msg = expt.run() 
      
        for nS in range(nScans):
            print('nScan=%s'%(nS))
            rxd, msgs = expt.run()
            if nS ==0:
                n_rxd = rxd['rx0']
            else:
                n_rxd = np.concatenate((n_rxd, rxd['rx0']), axis=0)
    
        n_rxd = np.reshape(n_rxd, (nScans, len(rxd['rx0'])))
        n_rxd = np.average(n_rxd, axis=0) 
    
        dataobject:DataManager=DataManager(n_rxd, freqs[i], len(n_rxd), [], BW)
        f_signalValue, t_signalValue, f_signalIdx, f_signalFrequency = dataobject.get_peakparameters()
        peakValsf.append(f_signalValue)
        
        expt.__del__()

        print(i)
        i = i+1
        
    
    return(peakValsf, freqs)