Skip to content

Commit

Permalink
Add a script to plot hot pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
aMarcireau committed Sep 25, 2023
1 parent 11d9791 commit 5d6c8eb
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class UsbConfiguration:

See _python/tests_ for different usage examples. `python/tests/display.py` implements a live event viewer with exponential decays caculated by the GPU. It requires vispy and glfw (`pip install vispy glfw`).

Some tests generate plots and require Pillow and Plotly (`pip install pillow plotly`).
Some tests generate plots and require Plotly (`pip install plotly pandas kaleido`).

## Contribute

Expand Down
1 change: 1 addition & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ tests/*.raw
*.so
*.pyd
__pycache__
tests/hot_pixels
95 changes: 95 additions & 0 deletions python/tests/find_hot_pixels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import pathlib

import neuromorphic_drivers as nd
import numpy as np
import plotly.express

nd.print_device_list()

output = pathlib.Path(__file__).resolve().parent / "hot_pixels"
output.mkdir(exist_ok=True)

diff_off_to_counts: dict[int, np.ndarray] = {}
diff_off_to_duration: dict[int, float] = {}

with nd.open(configuration=nd.prophesee_evk4.Configuration()) as device:
diff_off = 60
start_t = 0
next_t = 1000000
state = 0
total = 0
counts = np.zeros(
(device.properties().width, device.properties().height), dtype=np.uint64
)

print("wait for 1 seconds")
for status, packet in device:
if diff_off == 45:
break
if "dvs_events" in packet:
if state == 1:
events = packet["dvs_events"][packet["dvs_events"]["t"] >= start_t]
total += len(events)
np.add.at(counts, (events["x"], events["y"]), 1)
if packet["dvs_events"]["t"][-1] > next_t:
match state:
case 0:
print("start counting")
start_t = packet["dvs_events"]["t"][-1] + 1
next_t += 1000000
total = 0
counts.fill(0)
state = 1
case 1:
duration = packet["dvs_events"]["t"][-1] - start_t
print(
f"{diff_off=}, {total=}, {duration=}, {total / duration * 1e6} events/s"
)
diff_off_to_counts[diff_off] = counts
diff_off_to_duration[diff_off] = float(duration)
counts = np.zeros(
(device.properties().width, device.properties().height),
dtype=np.uint64,
)
next_t += 1000000
state = 0
diff_off -= 1
device.update_configuration(
nd.prophesee_evk4.Configuration(
biases=nd.prophesee_evk4.Biases(
diff_off=diff_off,
)
)
)
print("wait for 1 seconds")


for diff_off, counts in diff_off_to_counts.items():
log_counts = np.log((counts + 1).astype(np.float64)).transpose()
figure = plotly.express.imshow(log_counts, color_continuous_scale="thermal")
figure.update_layout(
width=1280,
height=720,
margin=dict(l=0, r=0, b=0, t=0),
xaxis={"visible": False, "showticklabels": False},
yaxis={"visible": False, "showticklabels": False},
showlegend=False,
)
figure.update_coloraxes(showscale=False)
figure.write_image(output / f"diff_off_{diff_off}_map.png")
sorted_counts = np.sort(counts[counts > 0])[::-1].astype(np.float64) * (
1e6 / diff_off_to_duration[diff_off],
)
print(f"{diff_off=}, maximum={sorted_counts[0]} events/s")
figure = plotly.express.line(
x=np.arange(1, len(sorted_counts) + 1),
y=sorted_counts,
log_y=True,
log_x=True,
)
figure.update_layout(
width=1280,
height=720,
showlegend=False,
)
figure.write_image(output / f"diff_off_{diff_off}_count.png")

0 comments on commit 5d6c8eb

Please sign in to comment.