Python matplotlib.mlab.stride_windows() Examples

The following are 30 code examples of matplotlib.mlab.stride_windows(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.mlab , or try the search function .
Example #1
Source File: test_mlab.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_apply_window_hanning_2D_stack_windows_axis1_unflatten(self):
        n = 32
        ydata = np.arange(n)
        ydata1 = ydata+5
        ydata2 = ydata+3.3
        ycontrol1 = mlab.apply_window(ydata1, mlab.window_hanning)
        ycontrol2 = mlab.window_hanning(ydata2)
        ydata = np.vstack([ydata1, ydata2])
        ycontrol = np.vstack([ycontrol1, ycontrol2])
        ydata = np.tile(ydata, (20, 1))
        ycontrol = np.tile(ycontrol, (20, 1))
        ydata = ydata.flatten()
        ydata1 = mlab.stride_windows(ydata, 32, noverlap=0, axis=0)
        result = mlab.apply_window(ydata1, mlab.window_hanning, axis=0,
                                   return_window=False)
        assert_allclose(ycontrol.T, result, atol=1e-08) 
Example #2
Source File: test_mlab.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_apply_window_hanning_2D_stack_windows_axis1_unflatten(self):
        n = 32
        ydata = np.arange(n)
        ydata1 = ydata+5
        ydata2 = ydata+3.3
        ycontrol1 = mlab.apply_window(ydata1, mlab.window_hanning)
        ycontrol2 = mlab.window_hanning(ydata2)
        ydata = np.vstack([ydata1, ydata2])
        ycontrol = np.vstack([ycontrol1, ycontrol2])
        ydata = np.tile(ydata, (20, 1))
        ycontrol = np.tile(ycontrol, (20, 1))
        ydata = ydata.flatten()
        ydata1 = mlab.stride_windows(ydata, 32, noverlap=0, axis=0)
        result = mlab.apply_window(ydata1, mlab.window_hanning, axis=0,
                                   return_window=False)
        assert_allclose(ycontrol.T, result, atol=1e-08) 
Example #3
Source File: test_mlab.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_stride_ensure_integer_type(self):
        N = 100
        x = np.empty(N + 20, dtype='>f4')
        x.fill(np.NaN)
        y = x[10:-10]
        y.fill(0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33, noverlap=0.6)
        assert_array_equal(y_strided, 0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33.3, noverlap=0)
        assert_array_equal(y_strided, 0.3)
        # even previous to #3845 could not find any problematic
        # configuration however, let's be sure it's not accidentally
        # introduced
        y_strided = mlab.stride_repeat(y, n=33.815)
        assert_array_equal(y_strided, 0.3) 
Example #4
Source File: test_mlab.py    From ImageFusion with MIT License 6 votes vote down vote up
def test_stride_ensure_integer_type(self):
        N = 100
        x = np.empty(N + 20, dtype='>f4')
        x.fill(np.NaN)
        y = x[10:-10]
        y.fill(0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33, noverlap=0.6)
        assert_array_equal(y_strided, 0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33.3, noverlap=0)
        assert_array_equal(y_strided, 0.3)
        # even previous to #3845 could not find any problematic
        # configuration however, let's be sure it's not accidentally
        # introduced
        y_strided = mlab.stride_repeat(y, n=33.815)
        assert_array_equal(y_strided, 0.3) 
Example #5
Source File: test_mlab.py    From neural-network-animation with MIT License 6 votes vote down vote up
def test_apply_window_hanning_2D_stack_windows_axis1_unflatten(self):
        n = 32
        ydata = np.arange(n)
        ydata1 = ydata+5
        ydata2 = ydata+3.3
        ycontrol1 = mlab.apply_window(ydata1, mlab.window_hanning)
        ycontrol2 = mlab.window_hanning(ydata2)
        ydata = np.vstack([ydata1, ydata2])
        ycontrol = np.vstack([ycontrol1, ycontrol2])
        ydata = np.tile(ydata, (20, 1))
        ycontrol = np.tile(ycontrol, (20, 1))
        ydata = ydata.flatten()
        ydata1 = mlab.stride_windows(ydata, 32, noverlap=0, axis=0)
        result = mlab.apply_window(ydata1, mlab.window_hanning, axis=0,
                                   return_window=False)
        assert_allclose(ycontrol.T, result, atol=1e-08) 
Example #6
Source File: test_mlab.py    From neural-network-animation with MIT License 6 votes vote down vote up
def test_stride_ensure_integer_type(self):
        N = 100
        x = np.empty(N + 20, dtype='>f4')
        x.fill(np.NaN)
        y = x[10:-10]
        y.fill(0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33, noverlap=0.6)
        assert_array_equal(y_strided, 0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33.3, noverlap=0)
        assert_array_equal(y_strided, 0.3)
        # even previous to #3845 could not find any problematic
        # configuration however, let's be sure it's not accidentally
        # introduced
        y_strided = mlab.stride_repeat(y, n=33.815)
        assert_array_equal(y_strided, 0.3) 
Example #7
Source File: test_mlab.py    From ImageFusion with MIT License 6 votes vote down vote up
def test_apply_window_hanning_2D_stack_windows_axis1_unflatten(self):
        n = 32
        ydata = np.arange(n)
        ydata1 = ydata+5
        ydata2 = ydata+3.3
        ycontrol1 = mlab.apply_window(ydata1, mlab.window_hanning)
        ycontrol2 = mlab.window_hanning(ydata2)
        ydata = np.vstack([ydata1, ydata2])
        ycontrol = np.vstack([ycontrol1, ycontrol2])
        ydata = np.tile(ydata, (20, 1))
        ycontrol = np.tile(ycontrol, (20, 1))
        ydata = ydata.flatten()
        ydata1 = mlab.stride_windows(ydata, 32, noverlap=0, axis=0)
        result = mlab.apply_window(ydata1, mlab.window_hanning, axis=0,
                                   return_window=False)
        assert_allclose(ycontrol.T, result, atol=1e-08) 
Example #8
Source File: test_mlab.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def test_stride_ensure_integer_type(self):
        N = 100
        x = np.empty(N + 20, dtype='>f4')
        x.fill(np.NaN)
        y = x[10:-10]
        y.fill(0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33, noverlap=0.6)
        assert_array_equal(y_strided, 0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33.3, noverlap=0)
        assert_array_equal(y_strided, 0.3)
        # even previous to #3845 could not find any problematic
        # configuration however, let's be sure it's not accidentally
        # introduced
        y_strided = mlab.stride_repeat(y, n=33.815)
        assert_array_equal(y_strided, 0.3) 
Example #9
Source File: test_mlab.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_stride_ensure_integer_type(self):
        N = 100
        x = np.empty(N + 20, dtype='>f4')
        x.fill(np.NaN)
        y = x[10:-10]
        y.fill(0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33, noverlap=0.6)
        assert_array_equal(y_strided, 0.3)
        # previous to #3845 lead to corrupt access
        y_strided = mlab.stride_windows(y, n=33.3, noverlap=0)
        assert_array_equal(y_strided, 0.3)
        # even previous to #3845 could not find any problematic
        # configuration however, let's be sure it's not accidentally
        # introduced
        y_strided = mlab.stride_repeat(y, n=33.815)
        assert_array_equal(y_strided, 0.3) 
Example #10
Source File: test_mlab.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def test_apply_window_hanning_2D_stack_windows_axis1_unflatten(self):
        n = 32
        ydata = np.arange(n)
        ydata1 = ydata+5
        ydata2 = ydata+3.3
        ycontrol1 = mlab.apply_window(ydata1, mlab.window_hanning)
        ycontrol2 = mlab.window_hanning(ydata2)
        ydata = np.vstack([ydata1, ydata2])
        ycontrol = np.vstack([ycontrol1, ycontrol2])
        ydata = np.tile(ydata, (20, 1))
        ycontrol = np.tile(ycontrol, (20, 1))
        ydata = ydata.flatten()
        ydata1 = mlab.stride_windows(ydata, 32, noverlap=0, axis=0)
        result = mlab.apply_window(ydata1, mlab.window_hanning, axis=0,
                                   return_window=False)
        assert_allclose(ycontrol.T, result, atol=1e-08) 
Example #11
Source File: test_mlab.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_stride_windows_n32_noverlap0_axis1_unflatten(self):
        n = 32
        x = np.arange(n)[np.newaxis]
        x1 = np.tile(x, (21, 1))
        x2 = x1.flatten()
        y = mlab.stride_windows(x2, n, axis=1)
        assert_equal(y.shape, x1.shape)
        assert_array_equal(y, x1) 
Example #12
Source File: test_mlab.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_stride_windows_n1_noverlap0_axis1(self):
        x = np.arange(10)
        y = mlab.stride_windows(x, 1, axis=1)
        yt = self.calc_window_target(x, 1).T
        assert_equal(yt.shape, y.shape)
        assert_array_equal(yt, y)
        assert_equal(x.shape + (1, ), y.shape)
        assert_true(self.get_base(y) is x) 
Example #13
Source File: test_mlab.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_stride_windows_n5_noverlap0_axis0(self):
        x = np.arange(100)
        y = mlab.stride_windows(x, 5)
        yt = self.calc_window_target(x, 5)
        assert_equal(yt.shape, y.shape)
        assert_array_equal(yt, y)
        assert_equal((5, 20), y.shape)
        assert_true(self.get_base(y) is x) 
Example #14
Source File: test_mlab.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_stride_windows_n5_noverlap0_axis1(self):
        x = np.arange(100)
        y = mlab.stride_windows(x, 5, axis=1)
        yt = self.calc_window_target(x, 5).T
        assert_equal(yt.shape, y.shape)
        assert_array_equal(yt, y)
        assert_equal((20, 5), y.shape)
        assert_true(self.get_base(y) is x) 
Example #15
Source File: test_mlab.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_stride_windows_n15_noverlap2_axis0(self):
        x = np.arange(100)
        y = mlab.stride_windows(x, 15, 2)
        yt = self.calc_window_target(x, 15, 2)
        assert_equal(yt.shape, y.shape)
        assert_array_equal(yt, y)
        assert_equal((15, 7), y.shape)
        assert_true(self.get_base(y) is x) 
Example #16
Source File: test_mlab.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_stride_windows_n13_noverlapn3_axis0(self):
        x = np.arange(100)
        y = mlab.stride_windows(x, 13, -3)
        yt = self.calc_window_target(x, 13, -3)
        assert_equal(yt.shape, y.shape)
        assert_array_equal(yt, y)
        assert_equal((13, 6), y.shape)
        assert_true(self.get_base(y) is x) 
Example #17
Source File: test_mlab.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_stride_windows_noverlap_eq_n_ValueError(self):
        x = np.arange(10)
        assert_raises(ValueError, mlab.stride_windows, x, 2, 2) 
Example #18
Source File: test_mlab.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_stride_windows_n13_noverlapn3_axis1(self):
        x = np.arange(100)
        y = mlab.stride_windows(x, 13, -3, axis=1)
        yt = self.calc_window_target(x, 13, -3).T
        assert_equal(yt.shape, y.shape)
        assert_array_equal(yt, y)
        assert_equal((6, 13), y.shape)
        assert_true(self.get_base(y) is x) 
Example #19
Source File: test_mlab.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_stride_windows_n32_noverlap0_axis0_unflatten(self):
        n = 32
        x = np.arange(n)[np.newaxis]
        x1 = np.tile(x, (21, 1))
        x2 = x1.flatten()
        y = mlab.stride_windows(x2, n)
        assert_equal(y.shape, x1.T.shape)
        assert_array_equal(y, x1.T) 
Example #20
Source File: test_mlab.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_stride_windows_n32_noverlap0_unflatten(self, axis):
        n = 32
        x = np.arange(n)[np.newaxis]
        x1 = np.tile(x, (21, 1))
        x2 = x1.flatten()
        y = mlab.stride_windows(x2, n, axis=axis)

        if axis == 0:
            x1 = x1.T
        assert y.shape == x1.shape
        assert_array_equal(y, x1) 
Example #21
Source File: test_mlab.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_stride_windows(self, n, noverlap, axis):
        x = np.arange(100)
        y = mlab.stride_windows(x, n, noverlap=noverlap, axis=axis)

        expected_shape = [0, 0]
        expected_shape[axis] = n
        expected_shape[1 - axis] = 100 // (n - noverlap)
        yt = self.calc_window_target(x, n, noverlap=noverlap, axis=axis)

        assert yt.shape == y.shape
        assert_array_equal(yt, y)
        assert tuple(expected_shape) == y.shape
        assert self.get_base(y) is x 
Example #22
Source File: test_mlab.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_stride_windows_invalid_params(self, n, noverlap):
        x = np.arange(10)
        with pytest.raises(ValueError):
            mlab.stride_windows(x, n, noverlap) 
Example #23
Source File: test_mlab.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_stride_windows_invalid_input_shape(self, shape):
        x = np.arange(np.prod(shape)).reshape(shape)
        with pytest.raises(ValueError):
            mlab.stride_windows(x, 5) 
Example #24
Source File: test_mlab.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_stride_windows_invalid_input_shape(self, shape):
        x = np.arange(np.prod(shape)).reshape(shape)
        with pytest.raises(ValueError):
            mlab.stride_windows(x, 5) 
Example #25
Source File: test_mlab.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_stride_windows_invalid_params(self, n, noverlap):
        x = np.arange(10)
        with pytest.raises(ValueError):
            mlab.stride_windows(x, n, noverlap) 
Example #26
Source File: test_mlab.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_stride_windows(self, n, noverlap, axis):
        x = np.arange(100)
        y = mlab.stride_windows(x, n, noverlap=noverlap, axis=axis)

        expected_shape = [0, 0]
        expected_shape[axis] = n
        expected_shape[1 - axis] = 100 // (n - noverlap)
        yt = self.calc_window_target(x, n, noverlap=noverlap, axis=axis)

        assert yt.shape == y.shape
        assert_array_equal(yt, y)
        assert tuple(expected_shape) == y.shape
        assert self.get_base(y) is x 
Example #27
Source File: test_mlab.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_stride_windows_n32_noverlap0_unflatten(self, axis):
        n = 32
        x = np.arange(n)[np.newaxis]
        x1 = np.tile(x, (21, 1))
        x2 = x1.flatten()
        y = mlab.stride_windows(x2, n, axis=axis)

        if axis == 0:
            x1 = x1.T
        assert y.shape == x1.shape
        assert_array_equal(y, x1) 
Example #28
Source File: test_mlab.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_stride_windows_n32_noverlap0_axis0_unflatten(self):
        n = 32
        x = np.arange(n)[np.newaxis]
        x1 = np.tile(x, (21, 1))
        x2 = x1.flatten()
        y = mlab.stride_windows(x2, n)
        assert_equal(y.shape, x1.T.shape)
        assert_array_equal(y, x1.T) 
Example #29
Source File: test_mlab.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_stride_windows_0D_ValueError(self):
        x = np.array(0)
        assert_raises(ValueError, mlab.stride_windows, x, 5) 
Example #30
Source File: test_mlab.py    From neural-network-animation with MIT License 5 votes vote down vote up
def test_stride_windows_noverlap_gt_n_ValueError(self):
        x = np.arange(10)
        assert_raises(ValueError, mlab.stride_windows, x, 2, 3)