def _split_data(self, signal, times, events):
        result = db.make_empty(self._si)

        while len(events) > 0 and len(signal) > 0:
            gs = events.TS[0]

            ts_index = np.array(times).searchsorted(gs)

            if ts_index == 0 and times[0] > gs:
                events = events[1:]
                continue

            if ts_index < len(times):
                pos = ts_index + self._shift

                if pos < 1:
                    events = events[1:]
                    continue

                if len(times) >= (pos + self._window_size):
                    window_range = range(pos, pos + self._window_size)
                    wnd = db.Window(self._si, times[window_range], signal[window_range, ], events[0:1])
                    events = events[1:]
                    result = db.combine(result, wnd)
                    continue
                break
            else:
                break
        return result, events
    def test_empty(self):
        c_si = si.Channels(5, 20)
        d = db.make_empty(c_si)

        self.assertEqual(d.shape, (0, 5))
        self.assertEqual(d.TS.shape, (0, ))
        self.assertEqual(d.SI, c_si)
    def prepare(self, input_stream, events, window_size, shift=0, late_time=10):
        if not isinstance(input_stream, db.Channels):
            raise Exception("windowize_by_events processor: data stream must be Channels.")

        if not isinstance(events, db.Event):
            raise Exception("windowize_by_events processor: received events type is not a list object.")

        if input_stream.SI.channels <= 0:
            raise Exception("windowize_by_events processor: invalid channels count.")

        if window_size <= 0:
            raise Exception("windowize_by_events processor: invalid window size.")

        self._events = db.make_empty(events.SI)
        self._window_size = window_size
        self._shift = shift

        max_buffer_size = (math.ceil(late_time * input_stream.SI.samplingRate)) * 2

        self._signal = np_rb.RingBuffer(capacity=max_buffer_size, dtype=(float, (input_stream.SI.channels,)))

        self._times = np_rb.RingBuffer(max_buffer_size, dtype=np.int64)

        self._si = si.Window(input_stream.SI.channels, self._window_size, input_stream.SI.samplingRate)

        return self._si
Пример #4
0
 def prepare_input(si):
     if isinstance(si, resonance.si.Base):
         if si == block.SI:
             return block
         else:
             return db.make_empty(si)
     else:
         return si
Пример #5
0
    def check(self, i_si, blocks):
        def code():
            resonance.createOutput(resonance.input(0), 'out')

        online = run.online([i_si], blocks, code)
        offline = run.offline([i_si], blocks, code)

        if len(blocks) > 0:
            origin = db.combine(*blocks)
        else:
            origin = db.make_empty(i_si)
        self.assertEqual(online['out'], origin)
        self.assertEqual(online['out'], offline['out'])
 def online(self, input):
     return db.combine(
         db.make_empty(self._si), *[
             db.Event(self._si, block.TS[0:1], self._transform(block))
             for block in input
         ])
Пример #7
0
 def combine_blocks(si):
     data = list(filter(lambda x: x.SI == si, blocks))
     if len(data):
         return db.combine(*data)
     else:
         return db.make_empty(si)
Пример #8
0
 def online(self, a, b):
     if len(a) > 0:
         return db.Event(self._si, a.TS, a[0])
     if len(b) > 0:
         return db.Event(self._si, b.TS, b[0])
     return db.make_empty(self._si)