Skip to content

Commit

Permalink
raise error if single polarity is used for sensor size but data conta…
Browse files Browse the repository at this point in the history
…ins more than one polarity
  • Loading branch information
biphasic committed Jun 14, 2023
1 parent c36b017 commit 26ac71f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/test_representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions tonic/functional/to_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 26ac71f

Please sign in to comment.