# Path: snntoolbox/datasets/aedat/ImportAedatBasicSourceName.py
# def import_aedat_basic_source_name(inp):
#     """
# 
#     Parameters
#     ----------
#     inp:
#         A device name.
# 
#     Returns
#     -------
#     :
#         The key device name associated with ``input``.
# 
#     """
# 
#     devices = {
#         'file': 'File',
#         'network': 'Network',
#         'dvs128': 'Dvs128',
#         'tmpdiff128': 'Dvs128',
#         'davis240a': 'Davis240A',
#         'sbret10': 'Davis240A',
#         'davis240b': 'Davis240B',
#         'sbret20': 'Davis240B',
#         'davis240c': 'Davis240C',
#         'sbret21': 'Davis240C',
#         'davis128mono': 'Davis128Mono',
#         'davis128rgb': 'Davis128Rgb',
#         'davis128': 'Davis128Rgb',
#         'davis208mono': 'Davis208Mono',
#         'davis208rgbw': 'Davis208Mono',
#         'pixelparade': 'Davis208Rgbw',
#         'sensdavis192': 'Davis208Rgbw',
#         'davis208': 'Davis208Rgbw',
#         'davis346amono': 'Davis346AMono',
#         'davis346argb': 'Davis346ARgb',
#         'davis346': 'Davis346ARgb',
#         'davis346bmono': 'Davis346BMono',
#         'davis346brgb': 'Davis346BRgb',
#         'davis346b': 'Davis346BRgb',
#         'davis346cbsi': 'Davis346CBsi',
#         'davis346bsi': 'Davis346CBsi',
#         'davis640mono': 'Davis640Mono',
#         'davis640rgb': 'Davis640Rgb',
#         'davis640': 'Davis640Rgb',
#         'davishet640mono': 'DavisHet640Mono',
#         'davishet640rgbw': 'DavisHet640Rgbw',
#         'cdavis640': 'DavisHet640Rgbw',
#         'cdavis640rgbw': 'DavisHet640Rgbw',
#         'das1': 'Das1',
#         'cochleaams1c': 'CochleaAms1c'}
# 
#     return devices.get(inp.lower()[:-2], 'Dvs128')  # Cut off '\r'


from snntoolbox.datasets.aedat.ImportAedatBasicSourceName import \
    import_aedat_basic_source_name
    info['fileHandle'].seek(0)

    # From version 3.1 there is an unambiguous division between header and
    # data: A line like this: '#!END-HEADER\r\n'
    # However, for all older files there's no guarantee that the first
    # character in the data would not be '#'. We ignore this - we look in the
    # next unread position and if it is not # we exit.

    info['xml'] = {}

    # Assume the format version is 1 unless a header of the version number is
    # found
    info['formatVersion'] = 1

    # Read the first character
    is_comment = '#' in str(info['fileHandle'].read(1))
    while is_comment:

        # Read the rest of the line
        line = info['fileHandle'].readline().decode('utf-8')
        # File format
        if line[: 8] == '!AER-DAT':
            info['formatVersion'] = int(line[8: -4])

        # Pick out the source
        # Version 2.0 encodes it like this:
        if line[: 9] == ' AEChip: ':
            # Ignore everything the class path and only use what follows the
            # final dot
            start_prefix = line.rfind('.')

# Path: snntoolbox/datasets/aedat/ImportAedatBasicSourceName.py
# def import_aedat_basic_source_name(inp):
#     """
# 
#     Parameters
#     ----------
#     inp:
#         A device name.
# 
#     Returns
#     -------
#     :
#         The key device name associated with ``input``.
# 
#     """
# 
#     devices = {
#         'file': 'File',
#         'network': 'Network',
#         'dvs128': 'Dvs128',
#         'tmpdiff128': 'Dvs128',
#         'davis240a': 'Davis240A',
#         'sbret10': 'Davis240A',
#         'davis240b': 'Davis240B',
#         'sbret20': 'Davis240B',
#         'davis240c': 'Davis240C',
#         'sbret21': 'Davis240C',
#         'davis128mono': 'Davis128Mono',
#         'davis128rgb': 'Davis128Rgb',
#         'davis128': 'Davis128Rgb',
#         'davis208mono': 'Davis208Mono',
#         'davis208rgbw': 'Davis208Mono',
#         'pixelparade': 'Davis208Rgbw',
#         'sensdavis192': 'Davis208Rgbw',
#         'davis208': 'Davis208Rgbw',
#         'davis346amono': 'Davis346AMono',
#         'davis346argb': 'Davis346ARgb',
#         'davis346': 'Davis346ARgb',
#         'davis346bmono': 'Davis346BMono',
#         'davis346brgb': 'Davis346BRgb',
#         'davis346b': 'Davis346BRgb',
#         'davis346cbsi': 'Davis346CBsi',
#         'davis346bsi': 'Davis346CBsi',
#         'davis640mono': 'Davis640Mono',
#         'davis640rgb': 'Davis640Rgb',
#         'davis640': 'Davis640Rgb',
#         'davishet640mono': 'DavisHet640Mono',
#         'davishet640rgbw': 'DavisHet640Rgbw',
#         'cdavis640': 'DavisHet640Rgbw',
#         'cdavis640rgbw': 'DavisHet640Rgbw',
#         'das1': 'Das1',
#         'cochleaams1c': 'CochleaAms1c'}
# 
#     return devices.get(inp.lower()[:-2], 'Dvs128')  # Cut off '\r'


# Path: snntoolbox/datasets/aedat/ImportAedatHeaders.py
from snntoolbox.datasets.aedat.ImportAedatBasicSourceName import \
    import_aedat_basic_source_name

    info['fileHandle'].seek(0)

    # From version 3.1 there is an unambiguous division between header and
    # data: A line like this: '#!END-HEADER\r\n'
    # However, for all older files there's no guarantee that the first
    # character in the data would not be '#'. We ignore this - we look in the
    # next unread position and if it is not # we exit.

    info['xml'] = {}

    # Assume the format version is 1 unless a header of the version number is
    # found
    info['formatVersion'] = 1

    # Read the first character
    is_comment = '#' in str(info['fileHandle'].read(1))
    while is_comment:

        # Read the rest of the line
        line = info['fileHandle'].readline().decode('utf-8')
        # File format
        if line[: 8] == '!AER-DAT':
            info['formatVersion'] = int(line[8: -4])

        # Pick out the source
        # Version 2.0 encodes it like this:
        if line[: 9] == ' AEChip: ':
            # Ignore everything the class path and only use what follows the
            # final dot
            start_prefix = line.rfind('.')

            info['sourceFromFile'] = import_aedat_basic_source_name(