#! /usr/bin/python import sys import xml.etree.cElementTree as ET et = ET.parse(sys.argv[1]) last = 0; l = [] for e in et.findall('*/*/*/{http://www.topografix.com/GPX/1/1}ele'): alt = float(e.text) if alt < last - 200: # wrong value l.append(e) continue if l: delta = (alt - last)/(len(l) + 1) for e in l: last += delta e.text = '%.1f' % last l = [] last = alt ET.register_namespace('', 'http://www.topografix.com/GPX/1/1') et.write(sys.argv[2], 'UTF-8')