示例#1
0
    def test_chopping(self):
        """ Test that the window function with trailing zeros chops the time series window """
        # Chopping at the start
        window_function_str = """lambda n: lambda x: 0 if x < 2 else 1"""
        node = window_func.WindowFuncNode(
            window_function_str=window_function_str, reduce_window=True)

        windowed_time_series = node.execute(self.test_time_series)

        self.assert_(windowed_time_series.shape[0] +
                     2 == self.test_time_series.shape[0])
        self.assert_(
            numpy.all(
                windowed_time_series.view(numpy.ndarray) ==
                self.test_time_series.view(numpy.ndarray)[2:, :]))

        # Chopping at the end
        window_function_str = """lambda n: lambda x: 0 if x >= n - 2 else 1"""
        node = window_func.WindowFuncNode(
            window_function_str=window_function_str, reduce_window=True)

        windowed_time_series = node.execute(self.test_time_series)

        self.assert_(windowed_time_series.shape[0] +
                     2 == self.test_time_series.shape[0])
        self.assert_(
            numpy.all(
                windowed_time_series.view(numpy.ndarray) ==
                self.test_time_series.view(numpy.ndarray)[:-2, :]))
示例#2
0
 def test_zero_window(self):
     """ Test that the window function [0 0 ... 0 0] raises an InvalidWindowException """
     window_function_str = "lambda n: lambda x: 0"
     node = window_func.WindowFuncNode(window_function_str = window_function_str)
     
     self.assertRaises(window_func.InvalidWindowException,
                       node.execute, self.test_time_series)
示例#3
0
 def test_one_window(self):
     """ Test that the window function [1 1 ... 1 1] does not change the time series """
     window_function_str = "lambda n: lambda x: 1"
     node = window_func.WindowFuncNode(window_function_str = window_function_str)
     
     windowed_time_series = node.execute(self.test_time_series)
     
     self.assert_(numpy.all(windowed_time_series.view(numpy.ndarray) == self.test_time_series.view(numpy.ndarray)))
示例#4
0
 def test_convolving(self):
     """ Test that convolving one with a window returns the window """
     window_function_str = """lambda n: lambda x: (1 - __import__("numpy").cos((x + 1) * __import__("numpy").pi/n))/2"""
     window_function = eval(window_function_str)
     window = numpy.array([window_function(self.test_time_series.shape[0])(i) 
                             for i in range(self.test_time_series.shape[0])])
     
     node = window_func.WindowFuncNode(window_function_str = window_function_str)
     
     windowed_time_series = node.execute(self.test_time_series)
     
     self.assert_(numpy.all(windowed_time_series.view(numpy.ndarray)[:,1] == window))