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: