-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdataread.py
69 lines (62 loc) · 3.14 KB
/
rdataread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
This script will load and display Clarius supported file types.
Author: Reza Zahiri
"""
import numpy as np
# read rf data
def read_rf(filename):
hdr_info = ('id', 'frames', 'lines', 'samples', 'samplesize')
hdr, timestamps, data = {}, None, None
with open(filename, 'rb') as raw_bytes:
# read 4 bytes header
for info in hdr_info:
hdr[info] = int.from_bytes(raw_bytes.read(4), byteorder='little')
# read timestamps and data
timestamps = np.zeros(hdr['frames'], dtype='int64')
sz = hdr['lines'] * hdr['samples'] * hdr['samplesize']
data = np.zeros((hdr['lines'], hdr['samples'], hdr['frames']), dtype='int16')
for frame in range(hdr['frames']):
# read 8 bytes of timestamp
timestamps[frame] = int.from_bytes(raw_bytes.read(8), byteorder='little')
# read each frame
data[:, :, frame] = np.frombuffer(raw_bytes.read(sz), dtype='int16').reshape([hdr['lines'], hdr['samples']])
print('Loaded {d[2]} raw frames of size, {d[0]} x {d[1]} (lines x samples)'.format(d=data.shape))
return hdr, timestamps, data
# read iq data
def read_iq(filename):
hdr_info = ('id', 'frames', 'lines', 'samples', 'samplesize')
hdr, timestamps, data = {}, None, None
with open(filename, 'rb') as raw_bytes:
# read 4 bytes header
for info in hdr_info:
hdr[info] = int.from_bytes(raw_bytes.read(4), byteorder='little')
# read timestamps and data
timestamps = np.zeros(hdr['frames'], dtype='int64')
sz = hdr['lines'] * hdr['samples'] * hdr['samplesize']
data = np.zeros((hdr['lines'], hdr['samples'] * 2, hdr['frames']), dtype='int16')
for frame in range(hdr['frames']):
# read 8 bytes of timestamp
timestamps[frame] = int.from_bytes(raw_bytes.read(8), byteorder='little')
# read each frame
data[:, :, frame] = np.frombuffer(raw_bytes.read(sz), dtype='int16').reshape([hdr['lines'], hdr['samples']*2])
print('Loaded {d[2]} raw frames of size, {d[0]} x {d[1]} (lines x samples)'.format(d=data.shape))
return hdr, timestamps, data
# read env data
def read_env(filename):
hdr_info = ('id', 'frames', 'lines', 'samples', 'samplesize')
hdr, timestamps, data = {}, None, None
with open(filename, 'rb') as raw_bytes:
# read 4 bytes header
for info in hdr_info:
hdr[info] = int.from_bytes(raw_bytes.read(4), byteorder='little')
# read timestamps and data
timestamps = np.zeros(hdr['frames'], dtype='int64')
sz = hdr['lines'] * hdr['samples'] * hdr['samplesize']
data = np.zeros((hdr['lines'], hdr['samples'], hdr['frames']), dtype='uint8')
for frame in range(hdr['frames']):
# read 8 bytes of timestamp
timestamps[frame] = int.from_bytes(raw_bytes.read(8), byteorder='little')
# read each frame
data[:, :, frame] = np.frombuffer(raw_bytes.read(sz), dtype='uint8').reshape([hdr['lines'], hdr['samples']])
print('Loaded {d[2]} raw frames of size, {d[0]} x {d[1]} (lines x samples)'.format(d=data.shape))
return hdr, timestamps, data