def update_temp():
    thermo = tc.Thermocouple()
    plt.figure()
    plt.xlabel("Time [s]")
    plt.ylabel("Temperature [K]")
    i = 0
    try:
        while True:
            #        clear()
            temp = np.float(thermo.toKelvin(get_temp()))
            print("{0:0.2f} K".format(temp))
            plt.plot(i, temp, 'b+')
            plt.pause(1)
            i += 1
    #        i = input("Enter text (or Enter to quit): ")
    #        if not i:
    #            break
    except KeyboardInterrupt:
        pass

    return
Esempio n. 2
0
font = {'family': 'normal', 'size': 15}

matplotlib.rc('font', **font)

filepath = "../database/nitrogen_Bfield_261017/0.214_290_180K.txt"

alpha = -5.0
beta = 0.5276
current = 0.001  #Amps
bfield = -((np.float(filepath.split("/")[-1].split("_")[0]) * 1000 - alpha) /
           beta) / 1000
ebfield = 0.024 / beta

d = s.data.load(filepath)

thermo = tc.Thermocouple()

#hall = d['v1'] #Hall voltage
hall1 = d['v1'] - 0.024  #Hall voltage
hall2 = d['v2'] - 0.024  #Hall voltage
hall = hall2 - hall1
#hall = d['v2'] - 0.024 #Hall voltage
temperature = thermo.toKelvin(d['v8'])


def hall_coeff(hall, bfield, ebfield):
    ehall = 0.0009 / 100  #% accuracy
    current = 0.001  #Amps
    d, ed = np.load("../database/d_sample.npy")

    Rh = np.zeros(len(hall))
def retreive_all(time=1,
                 iterations=0,
                 sleep=False,
                 filename=None,
                 foldername=None):  #give it a time interval

    if filename is None:
        print("\nIf B-Field is < 0, start with 'n' instead of '-'!\n")
        filename = raw_input("Save to (filename)?:  ")
        filename += ".txt"
    else:
        filename += ".txt"
        print("Saving to {}".format(filename))

    if foldername is None:
        #print("\nIf B-Field is < 0, start with 'n' instead of '-'!\n")
        #print("\nUsual filename: <BFIELD_STRENGHT>_<ANGLE_ON_SAMPLE>_<START_TEMP>\n")
        foldername = raw_input("\nNew folder name?:  ")
    else:
        print("\nCreating folder {}".format(foldername))

    try:
        os.mkdir("../database/{}/".format(foldername))
    except OSError:
        print("Folder already exists! Continuing...")
        pass

    d = s.data.databox()
    labels = ["v{}".format(i + 1) for i in range(8)]
    labels.append("time")
    #    for i in range(iterations):
    #        d["v{}".format(i+1)] = []
    #    print(labels)
    #d['time'] = []
    d.ckeys = labels

    #times = []#np.zeros(iterations)
    #voltages = []#np.zeros(iterations)
    init_time = t.time()

    #    d.h
    if iterations == 0:
        i = 0  #For the counter to work!
        plt.figure()
        plt.xlabel("Time [s]")
        plt.ylabel("Temperature [K]")

        previous_temperature = 0
        previous_time = 0

        try:
            while True:
                print("\nRetreiving value {}...".format(i + 1))
                #        voltages[i] = get_allVoltages()
                temp_volts = np.array(get_allVoltages())
                time = t.time() - init_time
                temp_volts = np.append(temp_volts, np.round(time, decimals=2))
                thermo = tc.Thermocouple()
                temperature = np.float(thermo.toKelvin(temp_volts[7]))
                plt.plot(time, temperature, 'b+')
                print("SLOPE: {0:0.3f} K/s".format(
                    (temperature - previous_temperature) /
                    (time - previous_time)))
                print("TEMPERATURE: {0:0.2f} K".format(temperature))
                #        for i in range(len(temp_volts)):
                #            d['v{}'.format(i+1)].append_data_point(temp_volts[i])
                d.append_data_point(temp_volts)
                previous_temperature = temperature
                previous_time = time
                plt.pause(1)

                #Time might be a problem, since voltages are not measured simultaneously
                #        times[i] = t.time()-init_time #time since started the experiment
                #        d['time'].append_data_point(t.time()-init_time)
                #            print(get_hall())
                #        print("{:0.2e} [V]    {:0.2f} [s]".format(halls[i], times[i]))
                if sleep:
                    if i > 100:
                        t.sleep(
                            time
                        )  #This creates a pause in the loop after a few iterations
                if temperature >= 380:  #This stops the loop if we exceed a given temperature
                    print(
                        "Exceeded maximal temperature!\nMax Temp: {0:0.2f} K\nCurrent Temp: {1:0.2f} K"
                        .format(380, temperature))
                    break
#                if temp_volts[-1] > 7200:
                if temp_volts[-1] > 14400:
                    #                    print("Exceeded maximal run time (2hr)!. Stopping...")
                    print("Exceeded maximal run time (4hr)!. Stopping...")
                    break
                i += 1  #For counting measures
        #This interrupts data taking and goes to save the file automatically
        #instead of crashing

        #USAGE: Ctrl-C
        except KeyboardInterrupt:
            print("Terminating...")
            pass
    else:
        for i in range(iterations):
            print("\nRetreiving value {}...".format(i + 1))
            #        voltages[i] = get_allVoltages()
            #        voltages[i] = get_allVoltages()        except KeyboardInterrupt:
            print("Terminating...")
            pass
            temp_volts = np.array(get_allVoltages())
            temp_volts = np.append(temp_volts,
                                   np.round(t.time() - init_time, decimals=2))
            thermo = tc.Thermocouple()
            print("TEMPERATURE: {} K".format(thermo.toKelvin(temp_volts[7])))
            #        for i in range(len(temp_volts)):
            #            d['v{}'.format(i+1)].append_data_point(temp_volts[i])
            d.append_data_point(temp_volts)
            #Time might be a problem, since voltages are not measured simultaneously
            #        times[i] = t.time()-init_time #time since started the experiment
            #        d['time'].append_data_point(t.time()-init_time)
            print(get_hall())
            #        print("{:0.2e} [V]    {:0.2f} [s]".format(halls[i], times[i]))
            #            if sleep:
            #                if i<20
            t.sleep(time)  #


#    print(voltages)
#    v1 = voltages[0::8]
#    v2 = voltages[1::8]
#    v3 = voltages[2::8]
#    v4 = voltages[3::8]
#    v5 = voltages[4::8]
#    v6 = voltages[5::8]
#    v7 = voltages[6::8]
#    v8 = voltages[7::8]
#    thermo = tc.Thermocouple
#    temp = np.zeros(np.shape(v8))
#    for i in range(len(v8)):
#        temp[i] = thermo.toKelvin(v8[i])
#    print(v1)
#    voltages = [v1,v2,v3,v4,v5,v6,v7,temp]
#    print(voltages)
#
#        foldername
#    for i in range(len(voltages)):
#        d.append_column(np.array(voltages[i]), labels[i])
#    d.append_column(times)

    print("Saving file to ../database/{}/{}".format(foldername, filename))
    d.save_file("../database/{}/{}".format(foldername, filename))
    #d.save_file("../database/{}".format(filename))

    return  #voltages, times
Esempio n. 4
0
import thermocouple

if __name__ == '__main__':
    thermo = thermocouple.Thermocouple()

    thermo.start()