Пример #1
0
 def test_is_valid(self):
     tsr = TimeSeriesReference(
         0, 10,
         TimeSeries(name='test' + str(0),
                    description='test',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     self.assertTrue(tsr.isvalid())
Пример #2
0
 def test_get_length1_invalid_data(self):
     """Get data from a TimeSeriesReferenceVectorData with one element and invalid data"""
     temp = TimeSeriesReferenceVectorData()
     value = TimeSeriesReference(
         -1, -1,
         TimeSeries(name='test',
                    description='test',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     temp.append(value)
     # test index slicing
     re = temp[0]
     self.assertTrue(
         isinstance(
             re, TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE))
     self.assertTupleEqual(
         re, TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_NONE_TYPE)
     # test array slicing and list slicing
     selection = [slice(None), [
         0,
     ]]
     for s in selection:
         re = temp[s]
         self.assertTrue(isinstance(re, list))
         self.assertTrue(len(re), 1)
         self.assertTrue(
             isinstance(
                 re[0],
                 TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE))
         self.assertTupleEqual(
             re[0],
             TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_NONE_TYPE)
Пример #3
0
 def test_data_property_invalid_reference(self):
     tsr = TimeSeriesReference(
         -1, -1,
         TimeSeries(name='test0',
                    description='test0',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     self.assertIsNone(tsr.data)
Пример #4
0
 def test_data_property(self):
     tsr = TimeSeriesReference(
         5, 4,
         TimeSeries(name='test0',
                    description='test0',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     np.testing.assert_array_equal(tsr.data, np.array([5., 6., 7., 8.]))
Пример #5
0
 def test_data_property_bad_reference(self):
     tsr = TimeSeriesReference(
         0, 12,
         TimeSeries(name='test0',
                    description='test0',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     with self.assertRaisesWith(
             IndexError,
             "'idx_start + count' out of range for timeseries 'test0'"):
         tsr.data
Пример #6
0
 def test_timestamps_property(self):
     # Timestamps from starting_time and rate
     tsr = TimeSeriesReference(
         5, 4,
         TimeSeries(name='test0',
                    description='test0',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     np.testing.assert_array_equal(tsr.timestamps,
                                   np.array([5.5, 5.6, 5.7, 5.8]))
     # Timestamps from timestamps directly
     tsr = TimeSeriesReference(
         5, 4,
         TimeSeries(name='test0',
                    description='test0',
                    data=np.arange(10),
                    unit='unit',
                    timestamps=np.arange(10).astype(float)))
     np.testing.assert_array_equal(tsr.timestamps,
                                   np.array([5., 6., 7., 8.]))
Пример #7
0
 def test_get_length1_valid_data(self):
     """Get data from a TimeSeriesReferenceVectorData with one element and valid data"""
     temp = TimeSeriesReferenceVectorData()
     value = TimeSeriesReference(
         0, 5,
         TimeSeries(name='test',
                    description='test',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     temp.append(value)
     self.assertTupleEqual(temp[0], value)
     self.assertListEqual(temp[:], [
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(*value),
     ])
Пример #8
0
 def test_get_length5_valid_data(self):
     """Get data from a TimeSeriesReferenceVectorData with 5 elements"""
     temp = TimeSeriesReferenceVectorData()
     num_values = 5
     values = [
         TimeSeriesReference(
             0, 5,
             TimeSeries(name='test' + str(i),
                        description='test',
                        data=np.arange(10),
                        unit='unit',
                        starting_time=5.0,
                        rate=0.1)) for i in range(num_values)
     ]
     for v in values:
         temp.append(v)
     # Test single element selection
     for i in range(num_values):
         # test index slicing
         re = temp[i]
         self.assertTupleEqual(re, values[i])
         # test slicing
         re = temp[i:i + 1]
         self.assertTupleEqual(
             re[0],
             TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
                 *values[i]))
     # Test multi element selection
     re = temp[0:2]
     self.assertTupleEqual(
         re[0],
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
             *values[0]))
     self.assertTupleEqual(
         re[1],
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
             *values[1]))
Пример #9
0
 def test_is_valid_bad_index(self):
     # Error: negative start_index but positive count
     tsr = TimeSeriesReference(
         -1, 10,
         TimeSeries(name='test0',
                    description='test0',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     with self.assertRaisesWith(
             IndexError,
             "'idx_start' -1 out of range for timeseries 'test0'"):
         tsr.isvalid()
     # Error: start_index too large
     tsr = TimeSeriesReference(
         10, 0,
         TimeSeries(name='test0',
                    description='test0',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     with self.assertRaisesWith(
             IndexError,
             "'idx_start' 10 out of range for timeseries 'test0'"):
         tsr.isvalid()
     # Error: positive start_index but negative count
     tsr = TimeSeriesReference(
         0, -3,
         TimeSeries(name='test0',
                    description='test0',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     with self.assertRaisesWith(
             IndexError, "'count' -3 invalid. 'count' must be positive"):
         tsr.isvalid()
     # Error:  start_index + count too large
     tsr = TimeSeriesReference(
         3, 10,
         TimeSeries(name='test0',
                    description='test0',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     with self.assertRaisesWith(
             IndexError,
             "'idx_start + count' out of range for timeseries 'test0'"):
         tsr.isvalid()
Пример #10
0
 def test_check_types(self):
     # invalid selection but with correct types
     tsr = TimeSeriesReference(
         -1, -1,
         TimeSeries(name='test' + str(0),
                    description='test',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     self.assertTrue(tsr.check_types())
     # invalid types, use float instead of int for both idx_start and count
     tsr = TimeSeriesReference(
         1.0, 5.0,
         TimeSeries(name='test' + str(0),
                    description='test',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     with self.assertRaisesWith(
             TypeError, "idx_start must be an integer not <class 'float'>"):
         tsr.check_types()
     # invalid types, use float instead of int for idx_start only
     tsr = TimeSeriesReference(
         1.0, 5,
         TimeSeries(name='test' + str(0),
                    description='test',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     with self.assertRaisesWith(
             TypeError, "idx_start must be an integer not <class 'float'>"):
         tsr.check_types()
     # invalid types, use float instead of int for count only
     tsr = TimeSeriesReference(
         1, 5.0,
         TimeSeries(name='test' + str(0),
                    description='test',
                    data=np.arange(10),
                    unit='unit',
                    starting_time=5.0,
                    rate=0.1))
     with self.assertRaisesWith(TypeError,
                                "count must be an integer <class 'float'>"):
         tsr.check_types()
     # invalid type for TimeSeries but valid idx_start and count
     tsr = TimeSeriesReference(1, 5, None)
     with self.assertRaisesWith(
             TypeError,
             "timeseries must be of type TimeSeries. <class 'NoneType'>"):
         tsr.check_types()
Пример #11
0
 def test_get_length5_with_invalid_data(self):
     """Get data from a TimeSeriesReferenceVectorData with 5 elements"""
     temp = TimeSeriesReferenceVectorData()
     num_values = 5
     values = [
         TimeSeriesReference(
             0, 5,
             TimeSeries(name='test' + str(i + 1),
                        description='test',
                        data=np.arange(10),
                        unit='unit',
                        starting_time=5.0,
                        rate=0.1)) for i in range(num_values - 2)
     ]
     values = ([
         TimeSeriesReference(
             -1, -1,
             TimeSeries(name='test' + str(0),
                        description='test',
                        data=np.arange(10),
                        unit='unit',
                        starting_time=5.0,
                        rate=0.1)),
     ] + values + [
         TimeSeriesReference(
             -1, -1,
             TimeSeries(name='test' + str(5),
                        description='test',
                        data=np.arange(10),
                        unit='unit',
                        starting_time=5.0,
                        rate=0.1)),
     ])
     for v in values:
         temp.append(v)
     # Test single element selection
     for i in range(num_values):
         # test index slicing
         re = temp[i]
         if i in [0, 4]:
             self.assertTrue(
                 isinstance(
                     re, TimeSeriesReferenceVectorData.
                     TIME_SERIES_REFERENCE_TUPLE))
             self.assertTupleEqual(
                 re, TimeSeriesReferenceVectorData.
                 TIME_SERIES_REFERENCE_NONE_TYPE)
         else:
             self.assertTupleEqual(re, values[i])
         # test slicing
         re = temp[i:i + 1]
         if i in [0, 4]:
             self.assertTrue(
                 isinstance(
                     re[0], TimeSeriesReferenceVectorData.
                     TIME_SERIES_REFERENCE_TUPLE))
             self.assertTupleEqual(
                 re[0], TimeSeriesReferenceVectorData.
                 TIME_SERIES_REFERENCE_NONE_TYPE)
         else:
             self.assertTupleEqual(
                 re[0],
                 TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
                     *values[i]))
     # Test multi element selection
     re = temp[0:2]
     self.assertTupleEqual(
         re[0],
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_NONE_TYPE)
     self.assertTupleEqual(
         re[1],
         TimeSeriesReferenceVectorData.TIME_SERIES_REFERENCE_TUPLE(
             *values[1]))