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
    def test_merge(self):
        # window test
        w_si = si.Window(3, 7, 250)

        data_a = np.arange(1, 22).reshape((7, 3))
        data_b = np.arange(22, 43).reshape((7, 3))
        data_c = np.arange(43, 64).reshape((7, 3))

        time_a = 3
        time_b = 6
        time_c = 35

        A = db.Window(w_si, time_a, data_a, '1')
        B = db.Window(w_si, time_b, data_b, '2')
        C = db.Window(w_si, time_c, data_c, '3')

        M = db.combine(A, B, C)

        self.assertEqual(M[0], data_a)
        self.assertEqual(M[1], data_b)
        self.assertEqual(M[2], data_c)

        self.assertTrue(np.array_equal(M.TS, [time_a, time_b, time_c]))
        # self.assertNotEqual(db.SingleWindow(3, np.arange(1, 21)), np.arange(21, 41))
        self.assertTrue(np.array_equal(M.metadata, ['1', '2', '3']))

        self.assertEqual(M[0].metadata, '1')
    def test_empty(self):
        w_si = si.Window(5, 20, 250)

        emptyWindows = [db.Window.make_empty(w_si), db.Window.make_empty(w_si)]

        result2 = db.combine(*emptyWindows)

        self.assertEqual(result2, db.Window.make_empty(w_si))
    def test_window_timestamp_attribute(self):
        w_si = si.Window(3, 7, 250)

        time_a = 3

        data_a = np.arange(1, 22).reshape((7, 3))

        A = db.Window(w_si, time_a, data_a)
        B = copy.deepcopy(A)

        self.assertEqual(A, B)
    def test_window_construct_from_other(self):
        time = 3
        channels = 2
        samples = 20
        sampling_rate = 250

        w_si = si.Window(channels, samples, sampling_rate)

        time = 3
        data_a = np.arange(1, 41, dtype=np.float64).reshape(samples, channels)
        data_b = np.arange(42, 82, dtype=np.float64).reshape(samples, channels)

        new_window = db.Window(w_si, time, [data_a])
Ejemplo n.º 6
0
    def prepare(self, input_stream, begin_offset, end_offset):
        if not isinstance(input_stream, db.Window):
            raise Exception(
                "BaseLine processor: received data block is not a window.")

        if input_stream.SI.samples < begin_offset:
            raise Exception(
                "BaseLine processor: offset value should not exceed the length of the window."
            )

        if (input_stream.SI.samples <
                end_offset) or (begin_offset < -input_stream.SI.samples):
            raise Exception(
                "BaseLine processor: the number of samples for averaging should not exceed the length of "
                "the window.")

        self._si = si.Window(channels=input_stream.SI.channels,
                             samples=input_stream.SI.samples,
                             samplingRate=input_stream.SI.samplingRate)
        self._averaging_window = slice(begin_offset, end_offset + 1)

        return self._si