def aedat4ToAbstract(input_file): UI().objectUI.showMessage("Starting to read aedat4 file", "w") decoder = aedat.Decoder(input_file) event_list = [] UI().objectUI.showMessage( "Starting to read the data (no progress bar available)", "w") for packet in decoder: if 'events' in packet: for ev in packet['events']: event_list.append( Event(ev[1], ev[2], ev[3], nsecsToSecs(ev[0]))) UI().objectUI.showMessage("Finishing reading the aedat4 file", "c") return event_list
import aedat decoder = aedat.Decoder('/path/to/file.aedat') """ decoder is a packet iterator with an additional method id_to_stream id_to_stream returns a dictionary with the following structure: { <int>: { 'type': <str>, } } type is one of 'events', 'frame', 'imus', 'triggers' if type is 'events' or 'frame', its parent dictionary has the following structure: { 'type': <str>, 'width': <int>, 'height': <int>, } """ print(decoder.id_to_stream()) for packet in decoder: """ packet is a dictionary with the following structure: { 'stream_id': <int>, } packet also has exactly one of the following fields: 'events', 'frame', 'imus', 'triggers' """ print(packet['stream_id'], end=': ')
def read_file(file_name, file_name_dat_aps=None, verbose=False): """parse a file from a neuromorphic camera and return events supported file formats are .aedat, .dat, .es and .csv """ if file_name.endswith('.aedat4'): decoder = aedat.Decoder(file_name) target_id = None width = None height = None for stream_id, stream in decoder.id_to_stream().items(): if stream['type'] == 'events' and (target_id is None or stream_id < target_id): target_id = stream_id if target_id is None: raise Exception('there are no events in the AEDAT file') parsed_file = { 'type': 'dvs', 'width': width, 'height': height, 'events': np.concatenate( tuple(packet['events'] for packet in decoder if packet['stream_id'] == target_id)), } elif file_name.endswith( '.dat') and '_aps' in file_name and file_name_dat_aps == None: parsed_file = loris_extension.read_dat_aps(file_name) elif file_name.endswith( '.dat' ) and file_name_dat_aps != None and file_name_dat_aps.endswith('.dat'): parsed_file = loris_extension.read_dat_td_aps(file_name, file_name_dat_aps) elif file_name.endswith('.dat') and file_name_dat_aps == None: parsed_file = loris_extension.read_dat_td(file_name) elif file_name.endswith('.es'): parsed_file = loris_extension.read_event_stream(file_name) elif file_name.endswith('.csv'): parsed_file = csv.parse_file(file_name) else: print("I don't know what kind of format you want to read. " + "Please specify a valid file name ending such as .aedat4 etc") return None if parsed_file['type'] == 'dvs': parsed_file['events'] = parsed_file['events'].view( dtype=[(('ts', 't'), '<u8'), ('x', '<u2'), ('y', '<u2'), (('p', 'is_increase'), '?')]) elif parsed_file['type'] == 'atis': parsed_file['events'] = parsed_file['events'].view( dtype=[(('ts', 't'), '<u8'), ('x', '<u2'), ('y', '<u2'), ('is_threshold_crossing', '?'), (('p', 'polarity'), '?')]) parsed_file['events'] = parsed_file['events'].view(type=np.rec.recarray) if verbose and file_name_dat_aps == None: print("Read " + str(len(parsed_file['events'])) + " events of type " + parsed_file['type'] + " from " + os.path.split(file_name)[-1]) elif verbose: print("Read " + str(len(parsed_file['events'])) + " events from combined files with dvs and atis events.") return parsed_file
import aedat import pathlib dirname = pathlib.Path(__file__).resolve().parent decoder = aedat.Decoder(dirname / 'test_data.aedat4') assert len(decoder.id_to_stream().keys()) == 4 assert decoder.id_to_stream()[0]['type'] == 'events' assert decoder.id_to_stream()[0]['width'] == 346 assert decoder.id_to_stream()[0]['height'] == 260 assert decoder.id_to_stream()[1]['type'] == 'frame' assert decoder.id_to_stream()[1]['width'] == 346 assert decoder.id_to_stream()[1]['height'] == 260 assert decoder.id_to_stream()[2]['type'] == 'imus' assert decoder.id_to_stream()[3]['type'] == 'triggers' counts = [0, 0, 0, 0] sizes = [0, 0, 0, 0] for packet in decoder: counts[packet['stream_id']] += 1 if 'events' in packet: sizes[0] += packet['events'].nbytes elif 'frame' in packet: sizes[1] += packet['frame']['pixels'].nbytes elif 'imus' in packet: sizes[2] += packet['imus'].nbytes elif 'triggers' in packet: sizes[3] += packet['triggers'].nbytes assert counts[0] == 236 assert counts[1] == 59 assert counts[2] == 236 assert counts[3] == 177