Clearly, I’m doing something wrong: For the same file, www.maplorer.com says +3011m, ridewithgps.com says +3637 m, and my script says… 10,510m
import gpxpy
import gpxpy.gpx
import array
gpx_file = open('myfile.gpx', 'r',encoding='utf-8')
gpx = gpxpy.parse(gpx_file)
arr = []
for track in gpx.tracks:
if not track.name:
track.name = "Empty name"
print("Track ",track.name)
for segment in track.segments:
EL=0
#put all trkpt in array
for point in segment.points:
arr.append(int(point.elevation))
for idx, x in enumerate(arr[1:]):
#Only include positive elevation
if x >= arr[idx-1]:
elevation = x - arr[idx-1]
EL += elevation
print(f"Total ascent: {EL}")
E.g. they talk about applying thresholds to reduce spurious elevation gains that are really just “noise”. I don’t think you are doing that in your script, but maybe the tools you are comparing to are?
GPSVisualizer certainly does apply tresholds, and I guess RideWithGPS does too since the figures are very close, and much closer to raw computation.
Pre-running the following command 1) on a file that had its altitude data replaced with those from DEM, and 2) ignoring track points that are no higher than 5m from the previous point… I get a positive elevation of 5,162m so closer to what GPSV and RwGPS give (~+3k against a raw elevation of +10k).
For those interested, here’s my updated script:
import gpxpy
import gpxpy.gpx
import array
#only include track points that are at least 5m higher than the previous point
EL_THRESHOLD = 5
INPUTFILE = 'input.gpx'
gpx_file = open(INPUTFILE, 'r',encoding='utf-8')
gpx = gpxpy.parse(gpx_file)
arr = []
for track in gpx.tracks:
if not track.name:
track.name = "Empty name"
print("Track ",track.name)
for segment in track.segments:
EL=0
#put all trkpt in array
for point in segment.points:
arr.append(int(point.elevation))
print("Number of track points: ", len(arr))
for idx, x in enumerate(arr[1:]):
elevation = x - arr[idx-1]
if elevation >= EL_THRESHOLD:
EL += elevation
print(f"Total ascent: {EL}")