From 18c5720c545de96d1624bac30307ff7fb4eaa92a Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Fri, 13 Jul 2018 17:56:47 -0700 Subject: [PATCH] Extract Wave.get(begin, end) from Wave.get_around --- ovgenpy/ovgenpy.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/ovgenpy/ovgenpy.py b/ovgenpy/ovgenpy.py index bc93e3d..ff0b614 100644 --- a/ovgenpy/ovgenpy.py +++ b/ovgenpy/ovgenpy.py @@ -160,13 +160,12 @@ class Wave: data /= self.max_val return data - def get_around(self, sample: int, region_nsamp: int): - end = sample + region_nsamp // 2 - begin = end - region_nsamp - + def get(self, begin: int, end: int): if 0 <= begin and end <= self.nsamp: return self[begin:end] + region_len = end - begin + delta_begin = 0 if begin < 0: delta_begin = 0 - begin @@ -181,17 +180,17 @@ class Wave: assert end + delta_end == self.nsamp # end += delta_end - out = np.zeros(region_nsamp, dtype=FLOAT) + out = np.zeros(region_len, dtype=FLOAT) - # out[0 : region_nsamp]. == self[begin: end] - # out[Δbegin : region_nsamp+Δend] == self[begin + Δbegin: end + Δend] - out[delta_begin : region_nsamp+delta_end] = self[begin+delta_begin : end+delta_end] + # out[0 : region_len]. == self[begin: end] + # out[Δbegin : region_len+Δend] == self[begin + Δbegin: end + Δend] + out[delta_begin : region_len+delta_end] = self[begin+delta_begin : end+delta_end] return out - - - - + def get_around(self, sample: int, region_len: int): + end = sample + region_len // 2 + begin = end - region_len + return self.get(begin, end) def set_trigger(self, trigger: 'Trigger'): self.trigger = trigger