Beispiel #1
0
 def test_get_window_times_7(self):
     """
     Negative step length and not partial windows.
     """
     expected = [(UTCDateTime(5), UTCDateTime(20))]
     window = get_window_times(starttime=UTCDateTime(0),
                               endtime=UTCDateTime(20),
                               window_length=15.0,
                               step=-15.0,
                               offset=20.0,
                               include_partial_windows=False)
     assert window == expected
Beispiel #2
0
 def test_get_window_times_5(self):
     """
     Test for partial windows.
     """
     expected = ([(UTCDateTime(0), UTCDateTime(15)),
                  (UTCDateTime(15), UTCDateTime(20))], )
     windows = get_window_times(starttime=UTCDateTime(0),
                                endtime=UTCDateTime(20),
                                window_length=15.0,
                                step=15.0,
                                offset=0.0,
                                include_partial_windows=True),
     assert windows == expected
Beispiel #3
0
    def test_get_window_times_4(self):
        """
        Test for not returning partial windows.
        """
        expected = [(UTCDateTime(0), UTCDateTime(15))]
        windows = get_window_times(starttime=UTCDateTime(0),
                                   endtime=UTCDateTime(20),
                                   window_length=15.0,
                                   step=15.0,
                                   offset=0.0,
                                   include_partial_windows=False)

        assert windows == expected
Beispiel #4
0
 def test_get_window_times_3(self):
     """
     Window times with offset.
     """
     expected = ([(UTCDateTime(8.5), UTCDateTime(13.5)),
                  (UTCDateTime(15), UTCDateTime(20))], )
     windows = get_window_times(starttime=UTCDateTime(0),
                                endtime=UTCDateTime(20),
                                window_length=5.0,
                                step=6.5,
                                offset=8.5,
                                include_partial_windows=False),
     assert expected == windows
Beispiel #5
0
 def test_get_window_times_1(self):
     """
     Basic windows. 4 pieces.
     """
     expected = ([(UTCDateTime(0), UTCDateTime(5)),
                  (UTCDateTime(5), UTCDateTime(10)),
                  (UTCDateTime(10), UTCDateTime(15)),
                  (UTCDateTime(15), UTCDateTime(20))], )
     windows = get_window_times(starttime=UTCDateTime(0),
                                endtime=UTCDateTime(20),
                                window_length=5.0,
                                step=5.0,
                                offset=0.0,
                                include_partial_windows=False),
     assert expected == windows
Beispiel #6
0
 def test_get_window_times_6(self):
     """
     Negative step length has to be used together with an offset.
     """
     expected = [(UTCDateTime(15), UTCDateTime(20)),
                 (UTCDateTime(10), UTCDateTime(15)),
                 (UTCDateTime(5), UTCDateTime(10)),
                 (UTCDateTime(0), UTCDateTime(5))]
     window = get_window_times(starttime=UTCDateTime(0),
                               endtime=UTCDateTime(20),
                               window_length=5.0,
                               step=-5.0,
                               offset=20.0,
                               include_partial_windows=False)
     assert window == expected
Beispiel #7
0
 def test_get_window_times_9(self):
     """
     Smaller step than window.
     """
     expected = ([(UTCDateTime(0), UTCDateTime(1)),
                  (UTCDateTime(0.25), UTCDateTime(1.25)),
                  (UTCDateTime(0.5), UTCDateTime(1.5)),
                  (UTCDateTime(0.75), UTCDateTime(1.75)),
                  (UTCDateTime(1.0), UTCDateTime(2.0))], )
     window = get_window_times(starttime=UTCDateTime(0),
                               endtime=UTCDateTime(2),
                               window_length=1.0,
                               step=0.25,
                               offset=0.0,
                               include_partial_windows=False),
     assert window == expected
Beispiel #8
0
    def test_get_window_times_2(self):
        """
        # Different step size.
        """
        expected = ([
            (UTCDateTime(0), UTCDateTime(5)),
            (UTCDateTime(10), UTCDateTime(15)),
        ], )
        windows = get_window_times(starttime=UTCDateTime(0),
                                   endtime=UTCDateTime(20),
                                   window_length=5.0,
                                   step=10.0,
                                   offset=0.0,
                                   include_partial_windows=False),

        assert expected == windows
Beispiel #9
0
    def test_get_window_times(self):
        """
        Tests for the get_window_times() helper function.
        """
        # Basic windows. 4 pieces.
        self.assertEqual(
            get_window_times(
                starttime=UTCDateTime(0),
                endtime=UTCDateTime(20),
                window_length=5.0,
                step=5.0,
                offset=0.0,
                include_partial_windows=False),
            [
                (UTCDateTime(0), UTCDateTime(5)),
                (UTCDateTime(5), UTCDateTime(10)),
                (UTCDateTime(10), UTCDateTime(15)),
                (UTCDateTime(15), UTCDateTime(20))
            ]
        )

        # Different step size.
        self.assertEqual(
            get_window_times(
                starttime=UTCDateTime(0),
                endtime=UTCDateTime(20),
                window_length=5.0,
                step=10.0,
                offset=0.0,
                include_partial_windows=False),
            [
                (UTCDateTime(0), UTCDateTime(5)),
                (UTCDateTime(10), UTCDateTime(15))
            ]
        )

        # With offset.
        self.assertEqual(
            get_window_times(
                starttime=UTCDateTime(0),
                endtime=UTCDateTime(20),
                window_length=5.0,
                step=6.5,
                offset=8.5,
                include_partial_windows=False),
            [
                (UTCDateTime(8.5), UTCDateTime(13.5)),
                (UTCDateTime(15), UTCDateTime(20))
            ]
        )

        # Don't return partial windows.
        self.assertEqual(
            get_window_times(
                starttime=UTCDateTime(0),
                endtime=UTCDateTime(20),
                window_length=15.0,
                step=15.0,
                offset=0.0,
                include_partial_windows=False),
            [
                (UTCDateTime(0), UTCDateTime(15))
            ]
        )

        # Return partial windows.
        self.assertEqual(
            get_window_times(
                starttime=UTCDateTime(0),
                endtime=UTCDateTime(20),
                window_length=15.0,
                step=15.0,
                offset=0.0,
                include_partial_windows=True),
            [
                (UTCDateTime(0), UTCDateTime(15)),
                (UTCDateTime(15), UTCDateTime(20))
            ]
        )

        # Negative step length has to be used together with an offset.
        self.assertEqual(
            get_window_times(
                starttime=UTCDateTime(0),
                endtime=UTCDateTime(20),
                window_length=5.0,
                step=-5.0,
                offset=20.0,
                include_partial_windows=False),
            [
                (UTCDateTime(15), UTCDateTime(20)),
                (UTCDateTime(10), UTCDateTime(15)),
                (UTCDateTime(5), UTCDateTime(10)),
                (UTCDateTime(0), UTCDateTime(5))
            ]
        )

        # Negative step length and not partial windows.
        self.assertEqual(
            get_window_times(
                starttime=UTCDateTime(0),
                endtime=UTCDateTime(20),
                window_length=15.0,
                step=-15.0,
                offset=20.0,
                include_partial_windows=False),
            [
                (UTCDateTime(5), UTCDateTime(20))
            ]
        )

        # Negative step length with partial windows.
        self.assertEqual(
            get_window_times(
                starttime=UTCDateTime(0),
                endtime=UTCDateTime(20),
                window_length=15.0,
                step=-15.0,
                offset=20.0,
                include_partial_windows=True),
            [
                (UTCDateTime(5), UTCDateTime(20)),
                (UTCDateTime(0), UTCDateTime(5))
            ]
        )

        # Smaller step than window.
        self.assertEqual(
            get_window_times(
                starttime=UTCDateTime(0),
                endtime=UTCDateTime(2),
                window_length=1.0,
                step=0.25,
                offset=0.0,
                include_partial_windows=False),
            [
                (UTCDateTime(0), UTCDateTime(1)),
                (UTCDateTime(0.25), UTCDateTime(1.25)),
                (UTCDateTime(0.5), UTCDateTime(1.5)),
                (UTCDateTime(0.75), UTCDateTime(1.75)),
                (UTCDateTime(1.0), UTCDateTime(2.0))
            ]
        )
    def test_get_window_times(self):
        """
        Tests for the get_window_times() helper function.
        """
        # Basic windows. 4 pieces.
        self.assertEqual(
            get_window_times(starttime=UTCDateTime(0),
                             endtime=UTCDateTime(20),
                             window_length=5.0,
                             step=5.0,
                             offset=0.0,
                             include_partial_windows=False),
            [(UTCDateTime(0), UTCDateTime(5)),
             (UTCDateTime(5), UTCDateTime(10)),
             (UTCDateTime(10), UTCDateTime(15)),
             (UTCDateTime(15), UTCDateTime(20))])

        # Different step size.
        self.assertEqual(
            get_window_times(starttime=UTCDateTime(0),
                             endtime=UTCDateTime(20),
                             window_length=5.0,
                             step=10.0,
                             offset=0.0,
                             include_partial_windows=False),
            [(UTCDateTime(0), UTCDateTime(5)),
             (UTCDateTime(10), UTCDateTime(15))])

        # With offset.
        self.assertEqual(
            get_window_times(starttime=UTCDateTime(0),
                             endtime=UTCDateTime(20),
                             window_length=5.0,
                             step=6.5,
                             offset=8.5,
                             include_partial_windows=False),
            [(UTCDateTime(8.5), UTCDateTime(13.5)),
             (UTCDateTime(15), UTCDateTime(20))])

        # Don't return partial windows.
        self.assertEqual(
            get_window_times(starttime=UTCDateTime(0),
                             endtime=UTCDateTime(20),
                             window_length=15.0,
                             step=15.0,
                             offset=0.0,
                             include_partial_windows=False),
            [(UTCDateTime(0), UTCDateTime(15))])

        # Return partial windows.
        self.assertEqual(
            get_window_times(starttime=UTCDateTime(0),
                             endtime=UTCDateTime(20),
                             window_length=15.0,
                             step=15.0,
                             offset=0.0,
                             include_partial_windows=True),
            [(UTCDateTime(0), UTCDateTime(15)),
             (UTCDateTime(15), UTCDateTime(20))])

        # Negative step length has to be used together with an offset.
        self.assertEqual(
            get_window_times(starttime=UTCDateTime(0),
                             endtime=UTCDateTime(20),
                             window_length=5.0,
                             step=-5.0,
                             offset=20.0,
                             include_partial_windows=False),
            [(UTCDateTime(15), UTCDateTime(20)),
             (UTCDateTime(10), UTCDateTime(15)),
             (UTCDateTime(5), UTCDateTime(10)),
             (UTCDateTime(0), UTCDateTime(5))])

        # Negative step length and not partial windows.
        self.assertEqual(
            get_window_times(starttime=UTCDateTime(0),
                             endtime=UTCDateTime(20),
                             window_length=15.0,
                             step=-15.0,
                             offset=20.0,
                             include_partial_windows=False),
            [(UTCDateTime(5), UTCDateTime(20))])

        # Negative step length with partial windows.
        self.assertEqual(
            get_window_times(starttime=UTCDateTime(0),
                             endtime=UTCDateTime(20),
                             window_length=15.0,
                             step=-15.0,
                             offset=20.0,
                             include_partial_windows=True),
            [(UTCDateTime(5), UTCDateTime(20)),
             (UTCDateTime(0), UTCDateTime(5))])

        # Smaller step than window.
        self.assertEqual(
            get_window_times(starttime=UTCDateTime(0),
                             endtime=UTCDateTime(2),
                             window_length=1.0,
                             step=0.25,
                             offset=0.0,
                             include_partial_windows=False),
            [(UTCDateTime(0), UTCDateTime(1)),
             (UTCDateTime(0.25), UTCDateTime(1.25)),
             (UTCDateTime(0.5), UTCDateTime(1.5)),
             (UTCDateTime(0.75), UTCDateTime(1.75)),
             (UTCDateTime(1.0), UTCDateTime(2.0))])