In [1]:
with open('000000_001.raw', 'rb') as f:
header_bytes = f.read()
In [7]:
import numpy
data_header_bytes = numpy.frombuffer(header_bytes, dtype=numpy.uint8)
In [8]:
import struct
length = struct.unpack(">q", data_header_bytes[:8].tobytes())[0]
b_size = struct.unpack(">i", data_header_bytes[8:12].tobytes())[0]
print(length)
print(b_size)
1083
8192
In [9]:
int(length)
data_header_bytes[12:]
Out[9]:
array([ 0, 0, 3, 188, 242, 255, 255, 252, 81, 168, 69, 41, 115,
216, 5, 133, 41, 135, 173, 66, 97, 168, 132, 229, 136, 11,
138, 80, 142, 88, 133, 34, 80, 9, 203, 49, 46, 40, 134,
114, 140, 85, 40, 6, 42, 97, 57, 210, 5, 69, 82, 142,
180, 10, 69, 66, 37, 44, 199, 116, 65, 49, 41, 199, 180,
10, 197, 132, 74, 88, 142, 116, 65, 145, 148, 35, 173, 66,
145, 80, 9, 203, 49, 93, 80, 76, 202, 49, 173, 66, 49,
161, 18, 150, 35, 92, 80, 4, 229, 8, 171, 80, 4, 84,
194, 114, 12, 23, 20, 131, 114, 12, 171, 80, 12, 168, 132,
229, 96, 93, 80, 176, 148, 131, 181, 10, 5, 11, 149, 176,
28, 140, 75, 57, 24, 171, 168, 132, 229, 72, 47, 40, 82,
131, 63, 106, 230, 143, 223, 88, 248, 229, 248, 213, 21, 126,
13, 15, 28, 151, 177, 112, 201, 113, 169, 43, 92, 26, 30,
56, 78, 198, 194, 73, 142, 147, 186, 194, 73, 195, 3, 199,
229, 88, 184, 204, 113, 89, 87, 184, 108, 120, 224, 56, 57,
22, 78, 230, 56, 89, 87, 56, 217, 240, 192, 113, 61, 22,
174, 115, 92, 215, 21, 174, 27, 30, 56, 78, 143, 133, 211,
57, 78, 215, 21, 78, 55, 60, 112, 92, 141, 133, 171, 28,
87, 117, 133, 171, 134, 7, 142, 83, 99, 225, 84, 142, 83,
117, 133, 83, 13, 15, 28, 47, 143, 133, 151, 115, 188, 92,
87, 120, 185, 225, 129, 227, 165, 49, 199, 75, 117, 13, 15,
28, 175, 199, 194, 235, 72, 224, 18, 30, 104, 56, 162, 132,
155, 134, 247, 42, 225, 130, 160, 211, 48, 68, 9, 51, 13,
235, 85, 194, 4, 65, 167, 209, 16, 37, 154, 105, 180, 94,
37, 154, 32, 232, 52, 44, 162, 132, 53, 13, 219, 171, 132,
21, 4, 157, 70, 139, 40, 209, 154, 70, 219, 171, 68, 43,
8, 58, 13, 131, 40, 97, 76, 195, 244, 42, 97, 4, 65,
167, 209, 32, 74, 52, 166, 209, 244, 42, 209, 8, 130, 78,
195, 35, 74, 120, 211, 240, 189, 74, 120, 65, 208, 105, 244,
136, 18, 189, 105, 244, 189, 74, 244, 130, 160, 211, 184, 32,
74, 92, 76, 227, 210, 171, 196, 69, 16, 116, 26, 119, 196,
52, 238, 189, 130, 160, 211, 144, 17, 37, 100, 21, 161, 146,
150, 43, 57, 34, 145, 187, 146, 131, 74, 228, 18, 198, 87,
90, 68, 162, 117, 165, 5, 149, 104, 37, 140, 175, 100, 17,
137, 172, 43, 89, 80, 137, 172, 132, 241, 149, 6, 34, 209,
112, 165, 1, 42, 209, 144, 48, 190, 146, 129, 72, 100, 184,
146, 1, 42, 145, 33, 97, 124, 165, 129, 72, 52, 92, 105,
128, 74, 52, 36, 140, 175, 100, 32, 18, 25, 174, 100, 128,
74, 100, 72, 24, 95, 105, 32, 18, 13, 87, 26, 160, 18,
13, 9, 227, 43, 25, 136, 68, 134, 43, 25, 160, 18, 25,
18, 198, 87, 50, 32, 18, 25, 92, 201, 0, 42, 145, 65,
194, 248, 74, 6, 196, 149, 12, 160, 18, 198, 87, 194, 16,
137, 48, 57, 57, 5, 160, 3, 65, 136, 19, 40, 16, 20,
225, 4, 72, 254, 5, 226, 16, 39, 86, 32, 46, 194, 137,
145, 252, 11, 148, 67, 156, 178, 2, 229, 34, 156, 50, 146,
127, 129, 120, 136, 19, 87, 32, 94, 132, 19, 71, 242, 47,
80, 30, 226, 148, 43, 80, 94, 132, 83, 142, 228, 95, 32,
30, 226, 196, 21, 136, 23, 225, 196, 145, 252, 11, 148, 135,
56, 229, 10, 148, 23, 225, 148, 35, 249, 23, 136, 135, 56,
113, 5, 226, 69, 56, 113, 36, 255, 2, 229, 33, 78, 185,
2, 229, 69, 56, 229, 72, 254, 5, 130, 135, 56, 193, 21,
8, 94, 132, 19, 28, 201, 191, 64, 240, 80, 129, 224, 69,
72, 254, 5, 58, 66, 156, 14, 255, 223, 255, 255, 254, 187,
255, 255, 255, 191, 251, 255, 255, 255, 123, 255, 119, 255, 255,
255, 127, 247, 255, 255, 255, 247, 254, 207, 253, 255, 255, 255,
115, 255, 255, 255, 255, 222, 255, 189, 255, 255, 255, 127, 239,
255, 255, 255, 223, 251, 63, 239, 255, 255, 255, 63, 239, 255,
255, 255, 191, 247, 127, 239, 255, 255, 255, 223, 251, 255, 255,
255, 247, 254, 207, 251, 255, 255, 255, 207, 251, 255, 255, 255,
239, 253, 223, 251, 255, 255, 255, 247, 254, 255, 255, 255, 189,
255, 243, 254, 255, 255, 5, 0, 48, 123, 255, 247, 24, 0,
32, 223, 239, 100, 0, 255, 136, 239, 255, 126, 255, 255, 253,
254, 255, 123, 255, 247, 253, 255, 255, 125, 124, 192, 63, 123,
252, 143, 199, 171, 199, 255, 227, 241, 248, 132, 245, 184, 31,
143, 83, 143, 251, 199, 227, 240, 9, 235, 241, 126, 60, 158,
122, 188, 127, 60, 30, 62, 97, 61, 206, 143, 199, 81, 143,
243, 143, 199, 193, 39, 172, 199, 243, 227, 241, 168, 199, 243,
143, 199, 131, 79, 88, 143, 243, 227, 113, 212, 227, 252, 227,
113, 240, 9, 235, 241, 252, 120, 60, 234, 241, 252, 227, 241,
224, 19, 214, 227, 252, 120, 28, 245, 56, 255, 120, 28, 124,
194, 122, 60, 63, 30, 143, 122, 60, 255, 120, 60, 248, 132,
245, 248, 252, 120, 124, 212, 227, 243, 143, 199, 7, 159, 176,
30, 159, 95, 61, 62, 255, 248, 132, 245, 248, 127, 60, 126,
0, 0, 2, 0, 109, 80, 0, 0, 0, 0, 0, 125, 93, 125], dtype=uint8)
In [27]:
import bitshuffle
# bitshuffle.decompress_lz4(data_header_bytes[12:], (1083), numpy.uint8)
byte_array = bitshuffle.decompress_lz4(data_header_bytes[12:], shape=(length,) , dtype=numpy.dtype('uint8'))
In [28]:
byte_array.tobytes().decode()
Out[28]:
'{"htype":"bsr_d-1.1","channels":[{"name":"BoolScalar","type":"bool"},{"name":"BoolWaveform","type":"bool","shape":[2048]},{"name":"Int8Scalar","type":"int8"},{"name":"Int8Waveform","type":"int8","shape":[2048]},{"name":"UInt8Scalar","type":"uint8"},{"name":"UInt8Waveform","type":"uint8","shape":[2048]},{"name":"Int16Scalar","type":"int16"},{"name":"Int16Waveform","type":"int16","shape":[2048]},{"name":"UInt16Scalar","type":"uint16"},{"name":"UInt16Waveform","type":"uint16","shape":[2048]},{"name":"Int32Scalar","type":"int32"},{"name":"Int32Waveform","type":"int32","shape":[2048]},{"name":"UInt32Scalar","type":"uint32"},{"name":"UInt32Waveform","type":"uint32","shape":[2048]},{"name":"Int64Scalar","type":"int64"},{"name":"Int64Waveform","type":"int64","shape":[2048]},{"name":"UInt64Scalar","type":"uint64"},{"name":"UInt64Waveform","type":"uint64","shape":[2048]},{"name":"Float32Scalar","type":"float32"},{"name":"Float32Waveform","type":"float32","shape":[2048]},{"name":"Float64Scalar"},{"name":"Float64Waveform","shape":[2048]},{"name":"StringScalar","type":"string"}]}'
In [29]:
with open('000000_000.raw', 'rb') as f:
header_bytes = f.read()
In [30]:
header_bytes
Out[30]:
b'{"htype":"bsr_m-1.1","hash":"5f62c6a8d0cb2ae4aa6fca597cc5ec48","pulse_id":147196131823,"global_timestamp":{"sec":1471961318,"ns":233131827},"dh_compression":"bitshuffle_lz4"}'
In [ ]:
Content source: paulscherrerinstitute/bsread_python
Similar notebooks: