Esempio n. 1
0
def wamd2guano(fname):
    """Convert a Wildlife Acoustics WAMD metadata file to GUANO metadata format"""
    wamd_md = wamd(fname)
    pprint(wamd_md)

    gfile = GuanoFile(fname)
    gfile['GUANO|Version'] = 1.0

    gfile['Timestamp'] = wamd_md.pop('timestamp')
    gfile['Note'] = wamd_md.pop('notes', '')

    gfile['Make'] = 'Wildlife Acoustics'
    gfile['Model'] = wamd_md.pop('model', '')
    gfile['Firmware Version'] = wamd_md.pop('firmware', '')

    gfile['Species Auto ID'] = wamd_md.pop('auto_id', '')
    gfile['Species Manual ID'] = wamd_md.pop('manual_id', '')

    gfile['TE'] = wamd_md.pop('time_expansion', 1)
    gfile['Samplerate'] = gfile.wav_params.framerate * gfile['TE']
    gfile['Length'] = gfile.wav_params.nframes / float(gfile.wav_params.framerate) * gfile['TE']

    if 'gpsfirst' in wamd_md:
        lat, lon, alt = wamd_md.pop('gpsfirst')
        gfile['Loc Position'] = lat, lon
        gfile['Loc Elevation'] = alt

    for k, v in wamd_md.items():
        gfile['WA', k] = v

    print(gfile.to_string())

    gfile.write()
Esempio n. 2
0
def batlogger2guano(fname):
    """Convert an Elekon BatLogger .WAV with sidecar .XML to GUANO metadata"""
    xmlfname = os.path.splitext(fname)[0] + '.xml'
    if not os.path.exists(xmlfname):
        raise ValueError('Unable to find XML metadata file for %s' % fname)
    g = GuanoFile(fname)
    with open(xmlfname, 'rt') as f:
        xml = ElementTree.parse(f)

    g['Timestamp'] = get(xml, 'DateTime', lambda x: datetime.strptime(x, '%d.%m.%Y %H:%M:%S'))
    g['Firmware Version'] = get(xml, 'Firmware')
    g['Make'] = 'Elekon'
    g['Model'] = 'BatLogger'
    g['Serial'] = get(xml, 'SN')
    g['Samplerate'] = get(xml, 'Samplerate', lambda x: int(x.split()[0]))
    g['Length'] = get(xml, 'Duration', lambda x: float(x.split()[0]))
    g['Original Filename'] = get(xml, 'Filename')
    g['Temperature Ext'] = get(xml, 'Temperature', lambda x: float(x.split()[0]))
    g['Loc Position'] = get(xml, 'GPS/Position', lambda x: tuple(map(float, x.split())))
    g['Loc Elevation'] = get(xml, 'GPS/Altitude', lambda x: float(x.split()[0]))

    g['Elekon|BattVoltage'] = get(xml, 'BattVoltage')
    for node in xml.find('Trigger'):
        g['Elekon|Trigger|%s' % node.tag] = node.text
    for node in xml.find('GPS'):
        g['Elekon|GPS|%s' % node.tag] = node.text

    # for k, v in g.items():
    #     print('%s:\t%s' % (k, v))

    print(g.to_string())
    g.write()
    os.remove(xmlfname)

    return g
Esempio n. 3
0
def d500x2guano(fname):
    """Convert a file with raw D500X metadata to use GUANO metadata instead"""
    print('\n', fname)
    md = extract_d500x_metadata(fname)
    if not md:
        print('Skipping non-D500X file: ' + fname, file=sys.stderr)
        return False
    pprint(md)

    gfile = GuanoFile(fname)
    gfile['GUANO|Version'] = 1.0

    gfile['Make'] = 'Pettersson'
    gfile['Model'] = 'D500X'
    gfile['Timestamp'] = md.pop('File Time')
    gfile['Original Filename'] = md.pop('File Name')
    gfile['Samplerate'] = md.pop('Samplerate')
    gfile['Length'] = md.pop('Length')

    if md.get('Profile HP', None) == 'Y':
        gfile['Filter HP'] = 20

    lat, lon = md.pop('LAT', None), md.pop('LON', None)
    if lat and lon:
        gfile['Loc Position'] = dms2decimal(lat), dms2decimal(lon)

    for k, v in md.items():
        gfile['PET', k] = v

    print(gfile.to_string())

    gfile.wav_data = gfile.wav_data[D500X_DATA_SKIP_BYTES:]  # throw out the metadata bytes from 'data' chunk

    unlock(fname)  # D500X "locks" files as unwriteable, we must unlock before we can modify
    gfile.write()
Esempio n. 4
0
def sonobat2guano(fname):
    """Convert a file with Sonobat metadata to GUANO metadata"""
    print('\n', fname)
    sb_md = extract_sonobat_metadata(fname)
    if not sb_md:
        print('Skipping non-Sonobat file: ' + fname, file=sys.stderr)
        return False
    pprint(sb_md)

    gfile = GuanoFile(fname)
    gfile['GUANO|Version'] = 1.0
    if 'timestamp' in sb_md:
        gfile['Timestamp'] = sb_md['timestamp']
    if sb_md.get('te', 1) != 1:
        gfile['TE'] = sb_md['te']
    gfile['Length'] = sb_md['length']
    gfile['Note'] = sb_md['note'].strip().replace('\r\n',
                                                  '\\n').replace('\n', '\\n')
    if sb_md.get('species', None):
        gfile['Species Auto ID'] = sb_md['species']

    if 'd500x' in sb_md:
        for k, v in sb_md['d500x'].items():
            gfile['PET', k] = v

    if 'ar125' in sb_md:
        for k, v in sb_md['ar125'].items():
            gfile['BAT', k] = v

    print(gfile.to_string())

    gfile.write()
Esempio n. 5
0
def dump(fname):
    print()
    print(fname)
    gfile = GuanoFile(fname, strict=False)
    print(gfile.to_string())