Exemplo n.º 1
0
 def do_start(self, line):
     self.log = False
     self.cube = Icecube()
     self.spec = 0
     self.cube.setIntegrationTime(10)
     t = Thread(target=self.specgen)
     u = Thread(target=self.plot)
     t.start()
     time.sleep(0.1)
     u.start()
Exemplo n.º 2
0
class spectre(cmd.Cmd):
    def do_start(self, line):
        self.log = False
        self.cube = Icecube()
        self.spec = 0
        self.cube.setIntegrationTime(10)
        t = Thread(target=self.specgen)
        u = Thread(target=self.plot)
        t.start()
        time.sleep(0.1)
        u.start()

    def plot(self):
        subprocess.call(["gnuplot", "loop.gnu"])

    def specgen(self):
        while True:
            print "\r{}".format(time.strftime("%D"))
            self.spec = self.cube.getSpectra()
            with open(".temp", "w") as f:
                for i in self.spec:
                    f.write("{}\t{}\n".format(i[0], i[1]))
            if self.log:
                self.n -= 1
                for i in self.spec:
                    g.write("{}\t{}\n".format(i[0], i[1]))
                if self.n == 0:
                    self.log = False
                    self.g.close()

            time.sleep(1)

    def do_EOF(self, line):
        print ("\n Exiting Spectre prompt.")
        self.cube.close()
        return True

    def do_capture(self, n=1):
        self.n = n
        self.log = True
        self.g = open("/mnt/photonics/spectra/{}".format(time.strftime("%Y%m%d_%H%M")), "w")
Exemplo n.º 3
0
def main(n, description,intTime, noPlot):
    c = 0
    foldername = time.strftime("%Y%m%d_%H%M%S")
    uid = pwd.getpwnam("sunyudong").pw_uid
    gid = grp.getgrnam("sunyudong").gr_gid
    if not n == -1:
        os.mkdir(foldername)
        path = foldername
        os.chown(path, uid, gid)
        if not description == None:
            z = open("spectra_log", "a")
            os.chown("spectra_log", uid, gid)
            z.write("{}\t{}\n".format(foldername, description))
        with open("{}/meta.info".format(foldername), 'w') as f:
            f.write("{}\tintTime = {} ms\t{}\n".format(foldername, intTime, description))
        os.chown("{}/meta.info".format(foldername), uid, gid)

    with Icecube() as cube:
        if not n == -1:
            # Write model information into meta.info
            with open("{}/meta.info".format(foldername), 'a') as f:
                f.write("Serial ({}) = {}\n".format(cube.type, cube.getSingleEEPROM(0)))
                f.write("Autonulling Factor = {}".format(cube.autonulling))

            # Write some metadata about corrections
            with open("{}/linearity.corr".format(foldername), 'a') as f:
                f.write("Linearity Correction -> {}th Order Polynomial\n".format(cube.getSingleEEPROM(14)))
                for i in range(6, 14):
                    f.write("{}\t{}\n".format(i - 6, cube.getSingleEEPROM(i)))
            os.chown("{}/linearity.corr".format(foldername), uid, gid)

            with open("{}/wavelength.corr".format(foldername), 'a') as f:
                f.write("Wavelength Correction\n")
                for i in range(1, 5):
                    f.write("{}\t{}\n".format(i - 1, cube.getSingleEEPROM(i)))
            os.chown("{}/wavelength.corr".format(foldername), uid, gid)

        cube.setIntegrationTime(intTime)
        totalSet = False
        while True:
            try:
                # sys.stdout.write("\r{}".format(n))
                if n == 0:
                    print("\nAcquisition Complete")
                    break
                elif n > 0:
                    # http://www.kahfei.com/2011/03/11/print-without-newline-in-python/
                    if not totalSet:
                        count = 0
                        total = n
                        digits = int(np.floor(np.log10(total)) + 1)
                        printString = "[{:>10} degC] Acquiring [{:>"+ str(digits) +"}/{}] Left: {}\033[K\r"
                        totalSet = True

                    count += 1
                    print(printString.format(str(cube.getTemp()), count, total, n - 1), end=' ')
                else:
                    print("[{:>10} degC] Live Plotting\033[K\r".format(str(cube.getTemp())), end=' ')

                spec = cube.getSpectra()

                if not noPlot:
                    Y = [i[1] for i in spec]
                    if c == 0: #init
                        X = [i[0] for i in spec]
                        plt.ion()
                        with plt.style.context('fivethirtyeight'):
                            graph = plt.plot(X,Y)[0]
                            plt.xlabel("Wavelength/nm")
                            plt.ylabel("Pixel intensity")
                        c = 1
                    else:
                        graph.set_ydata(Y)
                        with plt.style.context('fivethirtyeight'):
                            plt.draw()
                            plt.pause(0.01)

                # sleep(0.05)

                if n > 0:
                    with open("{}/data_{}".format(foldername,n) , 'w') as f:
                        for i in spec:
                            f.write("{}\t{}\n".format(i[0], i[1]))
                    os.chown("{}/data_{}".format(foldername,n), uid, gid)
                    n -= 1
                    # print " now {} readings left".format(n)

            except KeyboardInterrupt:
                cube.releaseInterface(0)
                cube.close()
                print("\n --- EXITING --- ")
                sys.exit()
Exemplo n.º 4
0
#!/usr/bin/env python2

import sys, os
base_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.abspath(os.path.join(base_dir, "..", "..", "helpers"))
sys.path.insert(0, root_dir)
from getSpectra import Icecube
import struct
import binascii

with Icecube() as cube:
    # READ EEPROM
    for i in xrange(0, 31):
        print "Reading Byte " + str(i)
        cube.icecube.bulkWrite(1, '\x05' + chr(i))
        data = cube.icecube.bulkRead(1, 17)
        # bytes = [data[i:i+2] for i in xrange(0, len(data), 2)]
        retCount = len(data)
        print(retCount)
        unpacked = struct.unpack('<' + str(retCount) + 'c', data)
        print(unpacked)

    # print(binascii.hexlify(data).decode('ascii'))

    # READ TEMPERATURE
    cube.icecube.bulkWrite(1, '\x6C')
    data = cube.icecube.bulkRead(1, 3)
    if struct.unpack('<c', data[0:1])[0] == b'\x08':
        # Read successful
        ADC = struct.unpack('<h', data[1:])[0]
        print(0.003906 * ADC)