Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging two files, but preferring data from one of those files, and interpolating the other #1260

Open
spacelama opened this issue Feb 10, 2024 · 2 comments

Comments

@spacelama
Copy link

Say you are riding with two GPS trackers - one that's quite accurate, and records temperature, cadence, but not heart rate. And the other that's not so great on locational accuracy, but records heartrate (bonus points for coping with the fact that it locks onto a location faster than the other one and isn't as likely to completely drop out). I'd like to combine these two files, preferring data over no data, but accurate data over inaccurate data. The timestamp is accurate in both, so you should just be able to interpolate the non lat,lon,time values from the second file into the first file to result in the merged file (and keeping lat,lon from the second file when it's not present in the first file).

Simply merging the files and keeping all data points does not work because each data point is likely to have only one of (time,inaccurate location,heart rate) or (time, accurate location, temperature, cadence). And your track will bounce back and forth between those two types of data, yielding quite the mess. I tested this with an invocation that looked like:
gpsbabel -t -i gpx -f Evening_Ride-20240208.gpx -i gpx -f Evening_Ride-20240208-2.gpx -x track,merge,title="COMBINED LOG" -o gpx -F Evening_Ride-20240208-combined.gpx and confirmed it was not really usable without lots of manual gpspruneing (and then you're throwing away data that was still present in the file that was ignored in any given segment).

I think I can contrive up an interpolation of both files at 1 second accuracy, and brute force the two files together ignoring those columns I want to discard from the second file, but that will involve large temporary files and a loss of accuracy if the initial files have sample points more often than once a second.

A general filter to do this would be much more useful, since it seems to be a common requirement, eg: https://help.openstreetmap.org/questions/54463/merge-gpx-tracks-without-losing-data

@robertlipe
Copy link
Collaborator

robertlipe commented Feb 10, 2024 via email

@tsteven4
Copy link
Collaborator

In the example you cite one method would be to augment the track with accurate position data with heart rate data from the other track.
Some sound methods to do this are:

  1. use a zero order hold on the heart rate track and resample it at the times in the position track. Effectively this means to use the most recently available heart rate data for each point in the position track.
  2. use a first order hold on the hear rate track and resample it at the times in the position track. Effectively this is just a linear interpolation of the adjacent heart rate points at each point in the position track.
  3. resample the heart rate data using the resample filter, and then to 1. or 2. Note the resample filter does not currently work with heart rate, but could be made to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants