From 26ac71f695a1c8e31ee4175aaeea95b9bda7fa1e Mon Sep 17 00:00:00 2001 From: Gregor Lenz Date: Wed, 14 Jun 2023 16:52:55 +0200 Subject: [PATCH] raise error if single polarity is used for sensor size but data contains more than one polarity --- test/test_representations.py | 8 ++++++++ tonic/functional/to_frame.py | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/test/test_representations.py b/test/test_representations.py index 4c26fe6a..b7c89373 100644 --- a/test/test_representations.py +++ b/test/test_representations.py @@ -173,6 +173,14 @@ def test_representation_inferred_frame(): assert frames.shape[1:] == sensor_size[::-1] +def test_representation_frame_wrong_sensor_size(): + sensor_size = (20, 10, 2) + orig_events, _ = create_random_input(n_events=30000, sensor_size=sensor_size) + transform = transforms.ToFrame(sensor_size=(20, 10, 1), time_window=25000) + with pytest.raises(ValueError): + frames = transform(orig_events) + + def test_representation_audio_frame(): sensor_size = (200, 1, 2) orig_events, _ = create_random_input( diff --git a/tonic/functional/to_frame.py b/tonic/functional/to_frame.py index 76ec3ed4..cd1bacdf 100644 --- a/tonic/functional/to_frame.py +++ b/tonic/functional/to_frame.py @@ -59,6 +59,10 @@ def to_frame_numpy( # test for single polarity if sensor_size[2] == 1: + if np.unique(events["p"]).size > 1: + raise ValueError( + "Single polarity sensor, but events contain both polarities." + ) events["p"] = 0 if time_window: