Smoothing in Neptune charts#
Neptune applies two smoothing functions to data displayed in charts:
- Neptune servers: Downsampling algorithm when fetching data
- Neptune app (UI): Smoothing function controlled by the user
Neptune servers downsampling#
If there are more than 1024 data points in the fetched data, the Neptune servers automatically downsample the values by taking the average of each consecutive value pair and forming a new value series out of the averages. The length of the new series is thus half of the original series.
This downsampling continues as long as the resulting series contains more than 1024 values.
The function also returns a margin of error or uncertainty, which is displayed as a shaded area in the chart:
If you zoom in on a specific region with less than 1024 data points, the chart updates to show the actual logged values.
Neptune UI smoothing#
This function is manually controlled with the smoothing slider on the right of a chart. The values range from a minimum of 1 to a maximum of 100 and increase in increments of 9.
When you move the smoothing slider, Neptune applies a low-pass filter to the \(y\) values in the chart. Additionally, the function takes as input the margin of error (the minimum and maximum \(y\) values) of the values returned by the downsampling algorithm.
The following example shows how the smoothing function works underneath the hood.
import math def smooth(last, value): # Weighted average if last value is known, else just return the value return ( weight * last + (1 - weight) * value if math.isfinite(last) else value ) def lowPassFilter(val): if val == 0 or val == 0: return 0 low = smooth(0, val) mid = smooth(0, val) high = smooth(0, val) return [low, mid, high] def smoothData(data, smoothingValue): if len(data) == 0: return data global weight weight = 1 if smoothingValue > 100 else (smoothingValue - 1) / 100 colCount = len(data) newData = dict() for i in range(len(data)): for k in range(1, colCount): newData[data[i]] = lowPassFilter(data[i][k]) return newData
The input shape is
[x, [minY, Y, maxY]], where
xis the \(x\) value
Yis the \(y\) value
maxYrepresent the margin of error after downsampling.