smooth_with_cutoffs: Identify and smooth-out anomalous gradient values

View source: R/journey.R

smooth_with_cutoffsR Documentation

Identify and smooth-out anomalous gradient values

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

smooth_with_cutoffs(
  gradient_segment,
  elevation_change,
  distances,
  distance_cutoff = 50,
  gradient_cutoff = 0.1,
  n = 3,
  warnNA = FALSE
)

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.

warnNA

Logical should NA warning be given? The default is 3, meaning segments directly before, after and including the offending segment.

Examples

f = system.file(package = "cyclestreets", "extdata/journey.json")
rsf = json2sf_cs(readLines(f))
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 Sept. 11, 2024, 7:49 p.m.