smooth_with_cutoffs: Identify and smooth-out anomalous gradient values

Description Usage Arguments Examples

View source: R/journey.R

Description

When distance_cutoff and gradient_cutoff thresholds are both broken for route segments, this function treats them as anomalous and sets the offending gradient values to the mean of the n segments closest to (in front of and behind) the offending segment.

Usage

1
2
3
4
5
6
7
8
smooth_with_cutoffs(
  gradient_segment,
  elevation_change,
  distances,
  distance_cutoff = 50,
  gradient_cutoff = 0.1,
  n = 3
)

Arguments

gradient_segment

The gradient for each segment from CycleStreets.net

elevation_change

The difference between the maximum and minimum elevations within each segment

distances

The distance of each segment

distance_cutoff

Distance (m) used to identify anomalous gradients

gradient_cutoff

Gradient (%, e.g. 0.1 being 10%) used to identify anomalous gradients

n

The number of segments to use to smooth anomalous gradents. The default is 3, meaning segments directly before, after and including the offending segment.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
f = system.file(package = "cyclestreets", "extdata/journey.json")
obj = jsonlite::read_json(f, simplifyVector = TRUE)
rsf = json2sf_cs(obj, cols = c("distances"))
rsf$gradient_segment
rsf$elevation_change
rsf$distances
smooth_with_cutoffs(rsf$gradient_segment, rsf$elevation_change, rsf$distances)
smooth_with_cutoffs(rsf$gradient_segment, rsf$elevation_change, rsf$distances, 20, 0.05)
smooth_with_cutoffs(rsf$gradient_segment, rsf$elevation_change, rsf$distances, 200, 0.02)
smooth_with_cutoffs(rsf$gradient_segment, rsf$elevation_change, rsf$distances, 200, 0.02, n = 5)

cyclestreets documentation built on Jan. 13, 2021, 8:09 p.m.