def test_equality(self):
        c_si = si.Channels(5, 20)

        time = 100
        data = np.arange(25)
        origin = db.Channels(c_si, timeoption2ts(c_si, time), data)

        same = db.Channels(c_si, timeoption2ts(c_si, time), data)
        self.assertEqual(origin, same)

        different_size = db.Channels(c_si, timeoption2ts(c_si, time),
                                     data.repeat(2))
        self.assertNotEqual(origin, different_size)

        different_time = db.Channels(c_si, timeoption2ts(c_si, time * 2), data)
        self.assertNotEqual(origin, different_time)

        c_si2 = si.Channels(5, 21)
        different_si = db.Channels(c_si2, timeoption2ts(c_si2, time), data)
        self.assertNotEqual(origin, different_si)

        offset = 10
        same_by_calc = db.Channels(c_si, timeoption2ts(c_si, time),
                                   data + offset)
        self.assertNotEqual(origin, same_by_calc)
        same_by_calc -= offset
        self.assertEqual(origin, same_by_calc)
    def test_is_similar(self):
        si1 = si.Channels(1, 20, id=1)
        si2 = si.Channels(1, 20, id=2)

        db1 = db.Channels(si1, 300, [1])
        db2 = db.Channels(si2, 300, [1])

        self.assertNotEqual(db1, db2)
        self.assertTrue(db1.is_similar(db2))
    def test_merge_si_override(self):
        si1 = si.Channels(1, 20, id=1)
        si2 = si.Channels(1, 20, id=2)
        si3 = si.Channels(1, 20, id=3)
        A = db.Channels(si1, timeoption2ts(si1, 205), [1])
        B = db.Channels(si2, timeoption2ts(si2, 206), [2])

        merged = db.combine(A, B, si=si3)
        expected = db.Channels(si3, timeoption2ts(si3, 206), [1, 2])

        self.assertEqual(merged, expected)
    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: db.Channels, outputChannels, transform):
        if not isinstance(input, db.Channels):
            raise Exception("input must be channels")

        self._si = si.Channels(channels=outputChannels, samplingRate=input.SI.samplingRate)
        self._transform = transform
        return self._si
Exemplo n.º 6
0
    def test_transformation_calls_something(self):
        s = si.Channels(2, 20)
        d = db.Channels(s, 300, np.arange(1, 27))
        t = pipe.spatial(d, np.array([[1, 0], [0, -1]]))

        self.assertIsInstance(t, db.Channels)
        self.assertEqual(t.shape, (13, 2))
    def test_si_comparisons(self):
        si1 = si.Channels(1, 20)
        si2 = si.Channels(2, 20)
        self.assertNotEqual(si1, si2)

        si3 = si.Channels(1, 21)
        self.assertNotEqual(si1, si3)

        si4 = si.Channels(1, 20)
        self.assertEqual(si1, si4)

        si5 = si.Channels(1, 20, id=3)
        self.assertNotEqual(si1, si5)

        self.assertTrue(si1.is_similar(si1))
        self.assertFalse(si1.is_similar(si2))
        self.assertFalse(si1.is_similar(si3))
        self.assertTrue(si1.is_similar(si4))
        self.assertTrue(si1.is_similar(si5))
    def test_timestamp_subset(self):
        c_si = si.Channels(1, 20)
        data = db.Channels(c_si, 2e9, np.arange(0, 25))
        sub_data = data[1:3, :]
        expected = db.Channels(c_si, 9e8, np.arange(1, 3))
        self.assertEqual(expected, sub_data)

        sub_data = data[[2]]
        expected = db.Channels(c_si, 9e8, [2])
        self.assertEqual(expected, sub_data)
Exemplo n.º 9
0
    def prepare(self, channels: db.Channels, ba_filter):
        if not isinstance(channels, db.Channels):
            raise Exception("input must be channels")

        self._si = si.Channels(channels=channels.SI.channels,
                               samplingRate=channels.SI.samplingRate)
        self._b, self._a = ba_filter
        self._zi = np.zeros((len(self._b) - 1, channels.SI.channels),
                            dtype=np.float)
        return self._si
    def test_merge(self):
        c_si = si.Channels(5, 20)

        A = db.Channels(c_si, timeoption2ts(c_si, 205), np.arange(1, 26))
        B = db.Channels(c_si, timeoption2ts(c_si, 215), np.arange(26, 76))
        C = db.Channels(c_si, timeoption2ts(c_si, 224), np.arange(76, 121))

        M = db.combine(A, B, C)
        O = db.Channels(c_si, timeoption2ts(c_si, 224), np.arange(1, 121))

        self.assertEqual(O, M)
Exemplo n.º 11
0
    def test_channels(self):
        c_si = si.Channels(5, 20)
        blocks = []
        self.check(c_si, blocks)

        blocks = [
            db.Channels(c_si, timeoption2ts(c_si, 124), np.arange(75, 120)),
            db.Channels(c_si, timeoption2ts(c_si, 105), np.arange(0, 25)),
            db.Channels(c_si, timeoption2ts(c_si, 115), np.arange(25, 75)),
        ]
        self.check(c_si, blocks)
def on_prepare(code, inputs):
    global test_report
    if len(test_report) != 0:
        test_report = []
        raise Exception("Sequence started wrong")

    test_report.append(("onPrepare", (inputs, code)))

    global si_channels
    si_channels = si.OutputStream(id=1,
                                  name="channels-out",
                                  source=si.Channels(channels=3,
                                                     samplingRate=21.0))
    global si_events
    si_events = si.OutputStream(id=2, name="event-out", source=si.Event())

    resonate.add_to_queue("createOutputStream", si_channels)
    resonate.add_to_queue("createOutputStream", si_events)
def on_stop():
    print("Stops")

    test_report.append(('onStop'))

    ch_si = si.Channels(3, 21, 1, "channels")
    ev_si = si.Event(2, "event")

    expected_report = [
        ("onPrepare",
         ([si.Channels(3, 21.0, 1, "channels"),
           si.Event(2, "event")], "")), ("onStart"),
        ("onDataBlock",
         db.Channels(ch_si, 946729805250000000, [
             [0.29475517441090415, -0.29475517441090415, 0.29475517441090415],
             [0.56332005806362195, -0.56332005806362195, 0.56332005806362195],
             [0.7818314824680298, -0.7818314824680298, 0.7818314824680298],
             [0.93087374864420414, -0.93087374864420414, 0.93087374864420414],
             [0.99720379718118013, -0.99720379718118013, 0.99720379718118013],
             [0.97492791218182362, -0.97492791218182362, 0.97492791218182362],
             [0.86602540378443871, -0.86602540378443871, 0.86602540378443871],
             [0.68017273777091969, -0.68017273777091969, 0.68017273777091969],
             [0.43388373911755823, -0.43388373911755823, 0.43388373911755823],
             [0.14904226617617472, -0.14904226617617472, 0.14904226617617472],
             [-0.14904226617617447, 0.14904226617617447, -0.14904226617617447],
             [-0.43388373911755801, 0.43388373911755801, -0.43388373911755801],
             [-0.68017273777091947, 0.68017273777091947, -0.68017273777091947],
             [-0.86602540378443837, 0.86602540378443837, -0.86602540378443837],
             [-0.97492791218182362, 0.97492791218182362, -0.97492791218182362],
             [-0.99720379718118024, 0.99720379718118024, -0.99720379718118024],
             [-0.93087374864420447, 0.93087374864420447, -0.93087374864420447],
             [-0.78183148246802991, 0.78183148246802991, -0.78183148246802991],
             [-0.56332005806362195, 0.56332005806362195, -0.56332005806362195],
             [-0.29475517441090471, 0.29475517441090471, -0.29475517441090471],
             [
                 -2.4492935982947064e-16, 2.4492935982947064e-16,
                 -2.4492935982947064e-16
             ],
             [0.29475517441090426, -0.29475517441090426, 0.29475517441090426],
             [0.56332005806362229, -0.56332005806362229, 0.56332005806362229],
             [0.78183148246802958, -0.78183148246802958, 0.78183148246802958],
             [0.93087374864420425, -0.93087374864420425, 0.93087374864420425],
             [0.99720379718118013, -0.99720379718118013, 0.99720379718118013],
             [0.97492791218182373, -0.97492791218182373, 0.97492791218182373],
             [0.86602540378443915, -0.86602540378443915, 0.86602540378443915],
             [0.68017273777091924, -0.68017273777091924, 0.68017273777091924],
             [0.43388373911755845, -0.43388373911755845, 0.43388373911755845],
             [0.14904226617617364, -0.14904226617617364, 0.14904226617617364],
             [-0.14904226617617292, 0.14904226617617292, -0.14904226617617292],
             [-0.43388373911755779, 0.43388373911755779, -0.43388373911755779],
             [-0.68017273777091869, 0.68017273777091869, -0.68017273777091869],
             [-0.86602540378443871, 0.86602540378443871, -0.86602540378443871],
             [-0.97492791218182351, 0.97492791218182351, -0.97492791218182351],
             [-0.99720379718118024, 0.99720379718118024, -0.99720379718118024],
             [-0.93087374864420425, 0.93087374864420425, -0.93087374864420425],
             [-0.78183148246803014, 0.78183148246803014, -0.78183148246803014],
             [-0.56332005806362295, 0.56332005806362295, -0.56332005806362295],
             [-0.29475517441090582, 0.29475517441090582, -0.29475517441090582],
             [
                 -4.8985871965894128e-16, 4.8985871965894128e-16,
                 -4.8985871965894128e-16
             ],
             [0.29475517441090315, -0.29475517441090315, 0.29475517441090315],
             [0.56332005806362206, -0.56332005806362206, 0.56332005806362206],
             [0.78183148246802947, -0.78183148246802947, 0.78183148246802947],
             [0.93087374864420447, -0.93087374864420447, 0.93087374864420447],
             [0.99720379718118013, -0.99720379718118013, 0.99720379718118013],
             [0.97492791218182373, -0.97492791218182373, 0.97492791218182373],
             [0.86602540378443837, -0.86602540378443837, 0.86602540378443837],
             [0.68017273777091936, -0.68017273777091936, 0.68017273777091936],
             [0.43388373911756023, -0.43388373911756023, 0.43388373911756023],
             [0.14904226617617389, -0.14904226617617389, 0.14904226617617389],
             [-0.14904226617617267, 0.14904226617617267, -0.14904226617617267],
             [-0.43388373911755757, 0.43388373911755757, -0.43388373911755757],
             [-0.6801727377709198, 0.6801727377709198, -0.6801727377709198],
             [-0.86602540378443771, 0.86602540378443771, -0.86602540378443771],
             [-0.97492791218182351, 0.97492791218182351, -0.97492791218182351],
             [-0.99720379718118013, 0.99720379718118013, -0.99720379718118013],
             [-0.93087374864420491, 0.93087374864420491, -0.93087374864420491],
             [-0.78183148246803025, 0.78183148246803025, -0.78183148246803025],
             [-0.56332005806362462, 0.56332005806362462, -0.56332005806362462],
             [-0.29475517441090265, 0.29475517441090265, -0.29475517441090265],
             [
                 -7.3478807948841188e-16, 7.3478807948841188e-16,
                 -7.3478807948841188e-16
             ]
         ])), ("onDataBlock", db.Event(ev_si, 946729905250000000, "test")),
        ("onStop")
    ]

    if expected_report != test_report:
        print("failed")
        print(test_report.__repr__())
        print("but")
        print(expected_report.__repr__())
        # raise Exception("Test didn't pass")

    print("passed")
    def test_single_channel(self):
        c_si = si.Channels(1, 20)
        single = db.Channels(c_si, 1e9, [1, 2, 3])

        self.assertEqual((3, 1), single.shape)
        self.assertEqual([[1], [2], [3]], single)
Exemplo n.º 15
0
 def setUp(self):
     self._si = si.Channels(2, 20)
     self._db = db.Channels(self._si, 300, np.arange(1, 27))
     self._code = '''