Example #1
0
 def testUnpack(self):
     s = Bits('0b111000111')
     x, y = s.unpack('3, pad:3, 3')
     self.assertEqual((x, y), (7, 7))
     x, y = s.unpack('2, pad:2, bin')
     self.assertEqual((x, y), (3, '00111'))
     x = s.unpack('pad:1, pad:2, pad:3')
     self.assertEqual(x, [])
Example #2
0
 def testUnpack(self):
     s = Bits('0b111000111')
     x, y = s.unpack('3, pad:3, 3')
     self.assertEqual((x, y), (7, 7))
     x, y = s.unpack('2, pad:2, bin')
     self.assertEqual((x, y), (3, '00111'))
     x = s.unpack('pad:1, pad:2, pad:3')
     self.assertEqual(x, [])
Example #3
0
    def read_spk_folder(spk_folder, bin_size=1):
        """
        Loads spike times from all spk files in a given folder.
        The j-th item in the list corresponds to the j-th neuron.
        It is the 1d array of spike times (microsec) for that neuron.

        Parameters
        ----------
        spk_folder : str
            Path containing spk file names
        bin_size : int, optional
            Bin size in milliseconds (default 1)

        Returns
        -------
        spikes : numpy array
            numpy array containing binned spike times
        """
        from bitstring import Bits
        neuron_to_file = []
        time_stamps = []
        bin_size = bin_size or 1
        fns = os.listdir(spk_folder)
        for i, fn in enumerate(fns):
            ext = os.path.splitext(fn)[1]
            if ext in ('.spk', ):  # Blanche spike format
                neuron_to_file.append(fn)
                f = open(os.path.join(spk_folder, fn), 'rb')
                p = Bits(f)
                fmt = str(p.length / 64) + ' * (intle:64)'
                time_stamps.append(p.unpack(fmt))
            spikes = SpkReader.load_from_spikes_times(time_stamps, bin_size=bin_size)
            return Spikes(spikes)
Example #4
0
    def read_spk_files(spk_files, bin_size=1):
        """
        Loads spike times from a list of spk files.
        The j-th item in the list corresponds to the j-th neuron.
        It is the 1d array of spike times (microsec) for that neuron.

        Parameters
        ----------
        spk_files : list of str
            List of strings containing spk file names
        bin_size : int, optional
            Bin size in milliseconds (default 1)

        Returns
        -------
        spikes : numpy array
            numpy array containing binned spike times
        """
        from bitstring import Bits
        neuron_to_file = []
        time_stamps = []
        bin_size = bin_size or 1

        for fn in spk_files:
            neuron_to_file.append(fn)
            f = open(fn, 'rb')
            p = Bits(f)
            fmt = str(p.length / 64) + ' * (intle:64)'
            time_stamps.append(p.unpack(fmt))
        spikes = SpkReader.load_from_spikes_times(time_stamps, bin_size=bin_size)
        return Spikes(spikes)
Example #5
0
    def read_spk_folder(spk_folder, bin_size=1):
        """
        Loads spike times from all spk files in a given folder.
        The j-th item in the list corresponds to the j-th neuron.
        It is the 1d array of spike times (microsec) for that neuron.

        Parameters
        ----------
        spk_folder : str
            Path containing spk file names
        bin_size : int, optional
            Bin size in milliseconds (default 1)

        Returns
        -------
        spikes : numpy array
            numpy array containing binned spike times
        """
        from bitstring import Bits
        neuron_to_file = []
        time_stamps = []
        bin_size = bin_size or 1
        fns = os.listdir(spk_folder)
        for i, fn in enumerate(fns):
            ext = os.path.splitext(fn)[1]
            if ext in ('.spk', ):  # Blanche spike format
                neuron_to_file.append(fn)
                f = open(os.path.join(spk_folder, fn), 'rb')
                p = Bits(f)
                fmt = str(p.length / 64) + ' * (intle:64)'
                time_stamps.append(p.unpack(fmt))
            spikes = SpkReader.load_from_spikes_times(time_stamps,
                                                      bin_size=bin_size)
            return Spikes(spikes)
Example #6
0
    def read_spk_files(spk_files, bin_size=1):
        """
        Loads spike times from a list of spk files.
        The j-th item in the list corresponds to the j-th neuron.
        It is the 1d array of spike times (microsec) for that neuron.

        Parameters
        ----------
        spk_files : list of str
            List of strings containing spk file names
        bin_size : int, optional
            Bin size in milliseconds (default 1)

        Returns
        -------
        spikes : numpy array
            numpy array containing binned spike times
        """
        from bitstring import Bits
        neuron_to_file = []
        time_stamps = []
        bin_size = bin_size or 1

        for fn in spk_files:
            neuron_to_file.append(fn)
            f = open(fn, 'rb')
            p = Bits(f)
            fmt = str(p.length / 64) + ' * (intle:64)'
            time_stamps.append(p.unpack(fmt))
        spikes = SpkReader.load_from_spikes_times(time_stamps,
                                                  bin_size=bin_size)
        return Spikes(spikes)
Example #7
0
File: metro.py Project: 83tb/metro
def readCommand(hexbits):
    bits = Bits(bytes=HexToByte(hexbits))
    # print bits
    alarm, state, data1, data2, checksum = bits.unpack("uint:4, uint:4, uint:8, uint:8, uint:8")

    dic = {"state": state, "alarm": alarm, "data1": data1, "data2": data2, "checksum": checksum}
    return dic
Example #8
0
File: metro.py Project: 83tb/metro
def getStatusByte(byte1):
    """
    Gets Two First Bytes, and returns a dictionary with:
    Command
    SetGroup
    Address
    """

    bits8 = Bits(bytes=byte1)
    status1, status2 = bits8.unpack("uint:4,uint:4")
    return dict(status1=getSt3st0(status1), status2=getSt7st4(status2))
Example #9
0
 def testDouble(self):
     a = array.array('d', [0.0, 1.0, 2.5])
     b = Bits(a)
     self.assertEqual(b.length, 192)
     c, d, e = b.unpack('3*floatne:64')
     self.assertEqual((c, d, e), (0.0, 1.0, 2.5))
Example #10
0
 def testDouble(self):
     a = array.array('d', [0.0, 1.0, 2.5])
     b = Bits(a)
     self.assertEqual(b.length, 192)
     c, d, e = b.unpack('3*floatne:64')
     self.assertEqual((c, d, e), (0.0, 1.0, 2.5))
Example #11
0
File: metro.py Project: 83tb/metro
def validateIncoming(byteStr):
    bits32 = Bits(bytes=byteStr)
    first, second, third, fourth = bits32.unpack("bytes:1,bytes:1,bytes:1,bytes:1")
    check = countCheckSumIncoming(first, second, third)
    assert str(check) == "0x" + str(ByteToHex(fourth)).lower()