Skip to content

Commit

Permalink
PERF: Speed up bitstring conversions in idex
Browse files Browse the repository at this point in the history
Bitstring was allocating many new objects which added significant
overhead. We can just use Python's native int conversions and
indexing into strings to achieve the same result.
  • Loading branch information
greglucas committed Jan 9, 2024
1 parent a88605f commit 0fa8bf2
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions imap_processing/idex/idex_packet_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,15 @@ def _parse_high_sample_waveform(self, waveform_raw: str):
The very last 4 numbers are bad usually, so remove those
"""
w = bitstring.ConstBitStream(bin=waveform_raw)
ints = []
while w.pos < len(w):
w.read("pad:2") # skip 2
ints += w.readlist(["uint:10"] * 3)
for i in range(0, len(waveform_raw), 32):
# 32 bit chunks, divided up into 2, 10, 10, 10
# skip first two bits
ints += [
int(waveform_raw[i + 2 : i + 12], 2),
int(waveform_raw[i + 12 : i + 22], 2),
int(waveform_raw[i + 22 : i + 32], 2),
]
return ints[:-4] # Remove last 4 numbers

def _parse_low_sample_waveform(self, waveform_raw: str):
Expand All @@ -836,11 +840,12 @@ def _parse_low_sample_waveform(self, waveform_raw: str):
* 8 bits of padding
* 2x12 bits of integer data.
"""
w = bitstring.ConstBitStream(bin=waveform_raw)
ints = []
while w.pos < len(w):
w.read("pad:8") # skip 8
ints += w.readlist(["uint:12"] * 2)
for i in range(0, len(waveform_raw), 32):
ints += [
int(waveform_raw[i + 8 : i + 20], 2),
int(waveform_raw[i + 20 : i + 32], 2),
]
return ints

def _calc_low_sample_resolution(self, num_samples: int):
Expand Down

0 comments on commit 0fa8bf2

Please sign in to comment.