Skip to content

Commit 42c8b9c

Browse files
committed
[test_tag] tests for event slices that return no data or reach too far
1 parent e8e5521 commit 42c8b9c

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

nixio/test/test_tag.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -579,26 +579,53 @@ def test_tagged_range_dim(self):
579579
# +0.1 should round up (ceil) the start position
580580
# +0.1 * 2 should round down (floor) the stop position and works the same for both inclusive and
581581
# exclusive
582-
tag.position = [pos+0.1]
583-
tag.extent = [ext+0.1]
584-
start = pos+1
585-
stop = pos+ext+1
582+
tag.position = [pos + 0.1]
583+
tag.extent = [ext + 0.1]
584+
start = pos + 1
585+
stop = pos + ext + 1
586586
np.testing.assert_array_almost_equal(tag.tagged_data(0), da[start:stop])
587587
np.testing.assert_array_almost_equal(tag.tagged_data(0, nix.SliceMode.Exclusive), da[start:stop])
588588
np.testing.assert_array_almost_equal(tag.tagged_data(0, nix.SliceMode.Inclusive), da[start:stop])
589589

590-
if pos+ext+2 < len(da):
590+
if pos + ext + 2 < len(da):
591591
# +0.9 should round up (ceil) the start position
592592
# +0.9 * 2 should round down (floor) the stop position and works the same for both inclusive and
593593
# exclusive
594-
tag.position = [pos+0.9]
595-
tag.extent = [ext+0.9]
596-
start = pos+1
597-
stop = pos+ext+2
594+
tag.position = [pos + 0.9]
595+
tag.extent = [ext + 0.9]
596+
start = pos + 1
597+
stop = pos + ext + 2
598598
np.testing.assert_array_almost_equal(tag.tagged_data(0), da[start:stop])
599599
np.testing.assert_array_almost_equal(tag.tagged_data(0, nix.SliceMode.Exclusive), da[start:stop])
600600
np.testing.assert_array_almost_equal(tag.tagged_data(0, nix.SliceMode.Inclusive), da[start:stop])
601601

602+
time_vector = np.arange(0.0, 10., 0.001)
603+
indices = np.random.rand(len(time_vector))
604+
event_data = time_vector[(indices < 0.1)]
605+
event_data = event_data[(event_data < 4) | (event_data > 7)]
606+
607+
event_da = self.block.create_data_array("event_data", "nix.events", data=event_data, unit="s")
608+
event_da.append_range_dimension_using_self()
609+
selection = event_da.get_slice([4.5], [1.0], nix.DataSliceMode.Data)[:]
610+
611+
tt = self.block.create_tag("no_event_segment", "nix.segment", 4.5)
612+
tt.extent = 1.0
613+
tt.references.append(event_da)
614+
slice = tt.tagged_data(0)
615+
self.assertFalse(slice.valid)
616+
617+
tt2 = self.block.create_tag("beyond data", "nix.segment", 12.0)
618+
tt2.extent = 3.0
619+
tt2.references.append(event_da)
620+
slice = tt2.tagged_data(0)
621+
self.assertFalse(slice.valid)
622+
623+
tt3 = self.block.create_tag("reachingbeyonddata", "nix.segment", 8.5)
624+
tt3.extent = [3.0]
625+
tt3.references.append(event_da)
626+
slice = tt3.tagged_data(0)
627+
self.assertTrue(slice.valid)
628+
602629
def test_tagged_sampled_dim(self):
603630
"""
604631
Simple test where the slice can be calculated directly from the position and extent and compared to the original

0 commit comments

Comments
 (0)