Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init_data(self):
dat = [0, 1, 2, 3, 4]
ts = TimeSeries('test_ts', dat, 'volts', timestamps=[0.1, 0.2, 0.3, 0.4])
self.assertIs(ts.data, dat)
self.assertEqual(ts.conversion, 1.0)
self.assertEqual(ts.resolution, 0.0)
self.assertEqual(ts.unit, 'volts')
def test_deprecated_get_data_interface(self):
ts = TimeSeries('test_ts', [0, 1, 2, 3, 4, 5],
'grams', timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
self.pm.add(ts)
with self.assertWarnsRegex(PendingDeprecationWarning, r'get_data_interface will be replaced by get'):
tmp = self.pm.get_data_interface('test_ts')
self.assertIs(tmp, ts)
def test_timestamps_timeseries(self):
ts1 = TimeSeries('test_ts1', [0, 1, 2, 3, 4, 5],
'grams', timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
ts2 = TimeSeries('test_ts2', [10, 11, 12, 13, 14, 15],
'grams', timestamps=ts1)
self.assertEqual(ts2.timestamps, [0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
external_file=['external_file'],
starting_frame=[1, 2, 3],
format='tiff',
timestamps=[1., 2.]
)
is2 = ImageSeries(
name='is2',
data=np.ones((2, 2, 2)),
unit='unit',
external_file=['external_file'],
starting_frame=[1, 2, 3],
format='tiff',
timestamps=[1., 2.]
)
tstamps = np.arange(1.0, 100.0, 0.1, dtype=np.float)
ts = TimeSeries(
name="test_ts",
data=list(range(len(tstamps))),
unit='unit',
timestamps=tstamps
)
cis = CorrectedImageStack(
corrected=is1,
original=is2,
xy_translation=ts
)
self.assertEqual(cis.corrected, is1)
self.assertEqual(cis.original, is2)
self.assertEqual(cis.xy_translation, ts)
with HDF5IO(self.data_filename, 'w', manager=get_manager()) as data_write_io:
data_write_io.write(data_file)
# read data file
with HDF5IO(self.data_filename, 'r', manager=get_manager()) as self.data_read_io:
data_file_obt = self.data_read_io.read()
# write "link file" with timeseries.data that is an external link to the timeseries in "data file"
# also link timeseries.timestamps.data to the timeseries.timestamps in "data file"
with HDF5IO(self.link_filename, 'w', manager=get_manager()) as link_write_io:
link_file = NWBFile(
session_description='a test file',
identifier='link_file',
session_start_time=self.start_time
)
self.link_container = TimeSeries(
name='test_mod_ts',
unit='V',
data=data_file_obt.get_acquisition('data_ts'), # test direct link
timestamps=H5DataIO(
data=data_file_obt.get_acquisition('data_ts').timestamps,
link_data=True # test with setting link data
)
)
link_file.add_acquisition(self.link_container)
link_write_io.write(link_file)
# note that self.link_container contains a link to a dataset that is now closed
# read the link file
self.link_read_io = HDF5IO(self.link_filename, 'r', manager=get_manager())
self.read_nwbfile = self.link_read_io.read()
def test_init_timestampslink_set(self):
ts = TimeSeries('test_ts', list(), 'unit', timestamps=list())
self.assertIsInstance(ts.timestamp_link, set)
self.assertEqual(len(ts.timestamp_link), 0)
def test_no_starting_time(self):
# if no starting_time is given, 0.0 is assumed
ts1 = TimeSeries('test_ts1', rate=0.1)
self.assertEqual(ts1.starting_time, 0.0)
def test_add_data_interface(self):
ts = TimeSeries('test_ts', [0, 1, 2, 3, 4, 5],
'grams', timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
self.pm.add(ts)
self.assertIn(ts.name, self.pm.containers)
self.assertIs(ts, self.pm.containers[ts.name])
def test_get_data_interface(self):
ts = TimeSeries('test_ts', [0, 1, 2, 3, 4, 5],
'grams', timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
self.pm.add(ts)
tmp = self.pm.get('test_ts')
self.assertIs(tmp, ts)
self.assertIs(self.pm['test_ts'], self.pm.get('test_ts'))
def test_deprecated_add_data_interface(self):
ts = TimeSeries('test_ts', [0, 1, 2, 3, 4, 5],
'grams', timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
with self.assertWarnsRegex(PendingDeprecationWarning, r'add_data_interface will be replaced by add'):
self.pm.add_data_interface(ts)
self.assertIn(ts.name, self.pm.containers)
self.assertIs(ts, self.pm.containers[ts.name])