|
5 | 5 | import time
|
6 | 6 | import struct
|
7 | 7 | import re
|
8 |
| - |
9 |
| -from numpy import average as np_avg |
| 8 | +import math |
10 | 9 |
|
11 | 10 |
|
12 | 11 | class PPKError(Exception):
|
@@ -234,7 +233,7 @@ def measure_average(self, time_s, discard_jitter_count=500):
|
234 | 233 | ts, avg_buf = ppk_helper.get_average_buffs()[0]
|
235 | 234 | timestamped_buf = [(ts + self.AVERAGE_TIME_US * i, avg_buf[i])
|
236 | 235 | for i in range(discard_jitter_count, len(avg_buf))]
|
237 |
| - return (np_avg(avg_buf[discard_jitter_count:]), timestamped_buf) |
| 236 | + return (self.favg(avg_buf[discard_jitter_count:]), timestamped_buf) |
238 | 237 |
|
239 | 238 | def measure_triggers(self, window_time_us, level_ua, count=1):
|
240 | 239 | """Collect count trigger buffers."""
|
@@ -277,7 +276,7 @@ def _measure_triggers(self, count=1):
|
277 | 276 | for ts, trig_buf in ppk_helper.get_trigger_buffs(*self._resistors):
|
278 | 277 | timestamped_buf = [(ts + self.ADC_SAMPLING_TIME_US * i, trig_buf[i])
|
279 | 278 | for i in range(0, len(trig_buf))]
|
280 |
| - result.append((np_avg(trig_buf), timestamped_buf)) |
| 279 | + result.append((self.favg(trig_buf), timestamped_buf)) |
281 | 280 | return result
|
282 | 281 |
|
283 | 282 | def _enable_ext_trigger_in(self):
|
@@ -371,6 +370,12 @@ def _log(self, logstring, **kwargs):
|
371 | 370 | if self.logprint:
|
372 | 371 | print(logstring, **kwargs)
|
373 | 372 |
|
| 373 | + @staticmethod |
| 374 | + def favg(float_seq): |
| 375 | + """Return the average of a sequence of floats.""" |
| 376 | + sum = math.fsum(float_seq) |
| 377 | + return sum / len(float_seq) |
| 378 | + |
374 | 379 | @staticmethod
|
375 | 380 | def _parse_metadata(metadata_str):
|
376 | 381 | """Use a Regular Expression to parse a metadata packet."""
|
|
0 commit comments