Ejemplo n.º 1
0
    def test_resample(self):
        raster = 1.33
        sigs = [
            Signal(
                samples=np.arange(1000, dtype='f8'),
                timestamps=np.concatenate(
                    [np.arange(500), np.arange(1000, 1500)]),
                name=f'Signal_{i}',
            ) for i in range(20)
        ]

        mdf = MDF()
        mdf.append(sigs)
        mdf = mdf.resample(raster=raster)

        target_timestamps = np.arange(0, 1500, 1.33)
        target_samples = np.concatenate([
            np.arange(0, 500, 1.33),
            np.linspace(499.00215568862274, 499.9976646706587, 376),
            np.arange(500.1600000000001, 1000, 1.33)
        ])

        for i, sig in enumerate(mdf.iter_channels(skip_master=True)):
            self.assertTrue(np.array_equal(sig.timestamps, target_timestamps))
            self.assertTrue(np.allclose(sig.samples, target_samples))
Ejemplo n.º 2
0
    def test_resample_raster_0(self):
        sigs = [
            Signal(
                samples=np.ones(1000) * i,
                timestamps=np.arange(1000),
                name=f'Signal_{i}',
            ) for i in range(20)
        ]

        mdf = MDF()
        mdf.append(sigs)
        mdf.configure(read_fragment_size=1)
        with self.assertRaises(AssertionError):
            mdf = mdf.resample(raster=0)
Ejemplo n.º 3
0
    def test_resample_raster_0(self):
        sigs = [
            Signal(
                samples=np.ones(1000) * i,
                timestamps=np.arange(1000),
                name=f'Signal_{i}',
            ) for i in range(20)
        ]

        mdf = MDF()
        mdf.append(sigs)
        mdf.configure(read_fragment_size=1)
        mdf = mdf.resample(raster=0)

        for i, sig in enumerate(mdf.iter_channels(skip_master=True)):
            self.assertTrue(np.array_equal(sig.samples, sigs[i].samples))
            self.assertTrue(np.array_equal(sig.timestamps, sigs[i].timestamps))