from metavision_ml.preprocessing import histo
import numpy as np
from metavision_core.event_io import RawReader
import matplotlib.pyplot as plt
from tqdm import tqdm
file = input('Enter the path to the input file: ').strip()
rates = []
dt = int(1e6) # 1s
record = RawReader(file)
# record.seek_time(1e6) # skip first second if needed
events = record.load_delta_t(dt)
events['t'] -= events[0]['t'] # important! almost all preprocessing use relative time!
height, width = record.get_size()
tbins = np.arange(100, 1000, 100) # Time bins from 100us to 1ms
for tb in tqdm(tbins):
volume = np.zeros((dt // tb, 2, height, width), dtype=np.float32)
histo(events, volume, tb)
# combine the two polarities
im = volume.sum(axis=1) # sum the two polarities
# average the time bins
im = im.mean(axis=0) # average the time bins
# flatten the image
im = im.flatten() # 1D array
# Calculate the event rate
rates.append(np.count_nonzero(im) / im.size)
del volume # free memory