本文整理匯總了Python中bitstring.Bits.unpack方法的典型用法代碼示例。如果您正苦於以下問題:Python Bits.unpack方法的具體用法?Python Bits.unpack怎麽用?Python Bits.unpack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bitstring.Bits
的用法示例。
在下文中一共展示了Bits.unpack方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testUnpack
# 需要導入模塊: from bitstring import Bits [as 別名]
# 或者: from bitstring.Bits import unpack [as 別名]
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, [])
示例2: read_spk_folder
# 需要導入模塊: from bitstring import Bits [as 別名]
# 或者: from bitstring.Bits import unpack [as 別名]
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)
示例3: read_spk_files
# 需要導入模塊: from bitstring import Bits [as 別名]
# 或者: from bitstring.Bits import unpack [as 別名]
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)
示例4: readCommand
# 需要導入模塊: from bitstring import Bits [as 別名]
# 或者: from bitstring.Bits import unpack [as 別名]
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
示例5: getStatusByte
# 需要導入模塊: from bitstring import Bits [as 別名]
# 或者: from bitstring.Bits import unpack [as 別名]
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))
示例6: testDouble
# 需要導入模塊: from bitstring import Bits [as 別名]
# 或者: from bitstring.Bits import unpack [as 別名]
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))
示例7: validateIncoming
# 需要導入模塊: from bitstring import Bits [as 別名]
# 或者: from bitstring.Bits import unpack [as 別名]
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()