예제 #1
0
파일: dataHandler.py 프로젝트: schote/ocra
    def acquireProjection(self, idx, ts=20):

        print("Acquire projection along axis: ", idx, "\n")
        socket.write(struct.pack('<I', 7 << 28 | idx))

        while (True):  # Wait until bytes written
            if not socket.waitForBytesWritten():
                break

        while True:  # Read data
            socket.waitForReadyRead()
            datasize = socket.bytesAvailable()
            # print(datasize)
            time.sleep(0.0001)
            if datasize == 8 * self.size:
                print("Readout finished : ", datasize)
                self.buffer[0:8 * self.size] = socket.read(8 * self.size)
                t1 = time.time()  # calculate time for acquisition
                break
            else:
                continue

        print("Start processing readout.")
        self.process_readout(ts)

        self.readout_finished.emit()
예제 #2
0
파일: dataHandler.py 프로젝트: schote/ocra
    def acquire(self, ts=20):
        t0 = time.time()  # calculate time for acquisition
        socket.write(struct.pack('<I', 1 << 28))

        while (True):  # Wait until bytes written
            if not socket.waitForBytesWritten(): break

        while True:  # Read data
            socket.waitForReadyRead()
            datasize = socket.bytesAvailable()
            # print(datasize)
            time.sleep(0.0001)
            if datasize == 8 * self.size:
                print("Readout finished : ", datasize)
                self.buffer[0:8 * self.size] = socket.read(8 * self.size)
                t1 = time.time()  # calculate time for acquisition
                break
            else:
                continue

        print("Start processing readout.")
        self.process_readout(ts)
        print("Start analyzing data.")
        self.analytics()
        print('Finished acquisition in {:.3f} ms'.format((t1 - t0) * 1000.0))
        # Emit signal, when data was read
        self.readout_finished.emit()
예제 #3
0
파일: dataHandler.py 프로젝트: schote/GOMRI
    def acquireImage(self, npe=16, TR=4000, ts=4):

        # Implement new concept:
        # com.start_image(npe)

        socket.write(struct.pack('<I', 6 << 28 | npe << 16 | TR))

        while (True):  # Wait until bytes written
            if not socket.waitForBytesWritten(): break

        t0 = time.time()

        for n in range(npe):
            while True:  # Read data
                socket.waitForReadyRead()
                datasize = socket.bytesAvailable()
                time.sleep(0.0001)
                if datasize == 8 * self.size:
                    print("Readout finished : ", datasize)
                    self.buffer[0:8 * self.size] = socket.read(8 * self.size)
                    break
                else:
                    continue

            self.process_readout(ts)
            self.readout_finished.emit()

        t1 = time.time()
        print('Finished image acquisition in {:.4f} min'.format(
            (t1 - t0) / 60))
예제 #4
0
파일: dataHandler.py 프로젝트: schote/ocra
    def acquireImage(self, npe=16, ts=20):

        socket.write(struct.pack('<I', 6 << 28 | npe))
        while (True):  # Wait until bytes written
            if not socket.waitForBytesWritten():
                break

        for n in range(npe):
            while True:  # Read data
                socket.waitForReadyRead()
                datasize = socket.bytesAvailable()
                time.sleep(0.0001)
                if datasize == 8 * self.size:
                    print("Readout finished : ", datasize)
                    self.buffer[0:8 * self.size] = socket.read(8 * self.size)
                    break
                else:
                    continue

            self.process_readout(ts)
            self.readout_finished.emit()
예제 #5
0
파일: dataHandler.py 프로젝트: schote/ocra
    def T2_measurement(self, values, freq, recovery, **kwargs):
        print('T1 Measurement')

        avgPoint = kwargs.get('avgP', 1)
        avgMeas = kwargs.get('avgM', 1)
        self.idxM = 0
        self.idxP = 0
        self.T2 = []
        self.R2 = []
        self.measurement = []

        self.set_freq(freq)

        while self.idxM < avgMeas:
            print("Measurement : ", self.idxM + 1, "/", avgMeas)
            self.measurement = []

            for self.te in values:
                self.peaks = []
                self.set_SE(self.te)

                while self.idxP < avgPoint:
                    print("Datapoint : ", self.idxP + 1, "/", avgPoint)
                    time.sleep(recovery / 1000)
                    socket.write(struct.pack('<I', 1 << 28))

                    while True:
                        socket.waitForReadyRead()
                        datasize = socket.bytesAvailable()
                        print(datasize)
                        time.sleep(0.1)
                        if datasize == 8 * self.size:
                            print("IR readout finished : ", datasize)
                            self.buffer[0:8 * self.size] = socket.read(
                                8 * self.size)
                            break
                        else:
                            continue

                    print("Start processing SE readout.")
                    self.process_readout()
                    print("Start analyzing SE data.")
                    self.analytics()
                    self.peaks.append(np.max(self.mag_con))

                    self.readout_finished.emit()
                    self.idxP += 1

                self.measurement.append(np.mean(self.peaks))
                self.idxP = 0

            # Calculate T2 value and error
            try:
                p, cov = curve_fit(self.T2_fit,
                                   values,
                                   self.measurement,
                                   bounds=([0, self.measurement[0],
                                            0], [10, 50000, 0.5]))
                # Calculation of T2: M(T2) = 0.37*(func(0)) = 0.37(A+B), T2 = -1/C * ln((M(T2)-A)/B)
                self.T2.append(
                    round(
                        -(1 / p[2]) * np.log(
                            ((0.37 * (p[0] + p[1])) - p[0]) / p[1]), 5))
                self.R2.append(
                    round(
                        1 - (np.sum(
                            (self.measurement - self.T2_fit(values, *p))**2) /
                             (np.sum(
                                 (self.measurement - np.mean(self.measurement))
                                 **2))), 5))
                self.x_fit = np.linspace(0, int(1.2 * values[-1]), 1000)
                self.y_fit = self.T2_fit(self.x_fit, *p)
                self.fit_params = p
                self.t2_finished.emit()
                self.idxM += 1
            except:
                self.T2.append(float('nan'))
                self.R2.append(float('nan'))
                self.x_fit = float('nan')
                self.y_fit = float('nan')
                self.fit_params = float('nan')
                self.t2_finished.emit()
                self.idxM += 1

        return np.nanmean(self.T2), np.nanmean(self.R2)
예제 #6
0
파일: dataHandler.py 프로젝트: schote/ocra
    def T1_measurement(self, values, freq, recovery, **kwargs):
        print('T1 Measurement')

        avgPoint = kwargs.get('avgP', 1)
        avgMeas = kwargs.get('avgM', 1)
        seq_type = kwargs.get('seqType', 1)

        self.idxM = 0
        self.idxP = 0
        self.T1 = []
        self.R2 = []
        self.set_freq(freq)

        while self.idxM < avgMeas:
            print("Measurement : ", self.idxM + 1, "/", avgMeas)
            self.measurement = []

            for self.ti in values:
                self.peaks = []

                if seq_type == 'sir':
                    self.set_SIR(self.ti)
                else:
                    self.set_IR(self.ti)

                while self.idxP < avgPoint:
                    print("Datapoint : ", self.idxP + 1, "/", avgPoint)
                    time.sleep(recovery / 1000)
                    socket.write(struct.pack('<I', 1 << 28))

                    while True:  # Readout data
                        socket.waitForReadyRead()
                        datasize = socket.bytesAvailable()
                        print(datasize)
                        time.sleep(0.1)
                        if datasize == 8 * self.size:
                            print("IR readout finished : ", datasize)
                            self.buffer[0:8 * self.size] = socket.read(
                                8 * self.size)
                            break
                        else:
                            continue

                    print("Start processing IR readout.")
                    self.process_readout()
                    print("Start analyzing IR data.")
                    self.analytics()
                    self.peaks.append(
                        np.max(self.mag_con) *
                        np.sign(self.real_con[np.argmin(self.real_con[0:50])]))
                    #self.peaks.append(self.peak_value*np.sign(self.real_con[np.argmin(self.real_con[0:50])]))
                    self.readout_finished.emit()
                    self.idxP += 1

                self.measurement.append(np.mean(self.peaks))
                self.idxP = 0

            def func(x):
                return p[0] - p[1] * np.exp(-p[2] * x)

            try:
                p, cov = curve_fit(self.T1_fit, values, self.measurement)
                # Calculate T1 value and error
                self.T1.append(
                    round(1.44 * brentq(func, values[0], values[-1]), 2))
                self.R2.append(
                    round(
                        1 - (np.sum(
                            (self.measurement - self.T1_fit(values, *p))**2) /
                             (np.sum(
                                 (self.measurement - np.mean(self.measurement))
                                 **2))), 5))
                self.x_fit = np.linspace(0, int(1.2 * values[-1]), 1000)
                self.y_fit = self.T1_fit(self.x_fit, *p)
                self.fit_params = p
            except:  # in case no fit found
                self.T1.append(float('nan'))
                self.R2.append(float('nan'))
                self.x_fit = float('nan')
                self.y_fit = float('nan')
                self.fit_params = float('nan')
            self.t1_finished.emit()
            self.idxM += 1

        return np.nanmean(self.T1), np.nanmean(self.R2)
예제 #7
0
파일: dataHandler.py 프로젝트: schote/GOMRI
    def T1_measurement(self, values, freq, recovery, **kwargs):
        print('T1 Measurement')

        avgPoint = kwargs.get('avgP', 1)
        avgMeas = kwargs.get('avgM', 1)
        seq_type = kwargs.get('seqType', 1)
        ts = 2

        self.idxM = 0
        self.idxP = 0
        self.T1 = []
        self.R2 = []
        self.set_freq(freq)

        #while self.idxM < avgMeas:
        #print("Measurement : ", self.idxM+1, "/", avgMeas)
        self.measurement = []

        for self.ti in values:
            self.peaks = []

            if seq_type == 'sir':
                self.set_SIR(self.ti)
            else:
                self.set_IR(self.ti)

            while self.idxP < avgPoint:
                print("Datapoint : ", self.idxP + 1, "/", avgPoint)
                time.sleep(recovery / 1000)
                socket.write(struct.pack('<I', 1 << 28))

                while True:  # Readout data
                    socket.waitForReadyRead()
                    datasize = socket.bytesAvailable()
                    print(datasize)
                    time.sleep(0.1)
                    if datasize == 8 * self.size:
                        print("IR readout finished : ", datasize)
                        self.buffer[0:8 * self.size] = socket.read(8 *
                                                                   self.size)
                        break
                    else:
                        continue

                print("Start processing IR readout.")
                self.process_readout(ts)
                print("Start analyzing IR data.")
                self.analytics()
                self.peaks.append(
                    np.max(self.mag_con) *
                    np.sign(self.real_con[np.argmin(self.real_con[0:50])]))
                #self.peaks.append(self.peak_value*np.sign(self.real_con[np.argmin(self.real_con[0:50])]))
                self.readout_finished.emit()
                self.idxP += 1

            self.measurement.append(np.mean(self.peaks))
            self.idxP = 0

        #self.calculateT1fit(values)
        #bounds=([0, self.measurement[0], 0], [100, 50000, 1])
        self.calculateT1fit(values)  #, bounds)

        self.t1_finished.emit()
        #self.idxM += 1

        return np.nanmean(self.T1), np.nanmean(self.R2)
예제 #8
0
    if not socket.waitForBytesWritten(): break

# Test 2D SE acquisition
#socket.write(struct.pack('<I', 6 << 28 | npe))

# Test FID
socket.write(struct.pack('<I', 1 << 28))

while (True):  # Wait until bytes written
    if not socket.waitForBytesWritten(): break

# Perform npe-times readout
for n in range(npe):
    while True:  # Read data
        socket.waitForReadyRead()
        datasize = socket.bytesAvailable()
        time.sleep(0.0001)
        if datasize == 8 * size:
            print("Readout finished : ", datasize)
            buffer[0:8 * size] = socket.read(8 * size)
            break
        else:
            continue

    ax.plot(data[0:2000])

plt.show()
print("Acquisition finished.\n")

time.sleep(1)