{
const { x, y } = DATA;
const k = 63;
const ymax = Math.max(...y);
const xmin = 20.0;
const xmax = xmin + 60.0;
const originals = [];
const means = [];
const variances = [];
const amplitudes = [];
const offsets = [];
for (let i=k, n=x.length; i<n-k; ++i) {
if (!(xmin <= x[i] && x[i] <= xmax)) {
continue;
}
const { mean, variance, amplitude, offset } = stats({
x: x.slice(i-k, i+k+1),
y: y.slice(i-k, i+k+1),
});
originals.push({ x: x[i], y: y[i] });
means.push({ x: mean, y: mean - x[i] });
variances.push({ x: mean, y: variance });
amplitudes.push({ x: mean, y: amplitude });
offsets.push({ x: mean, y: amplitude });
}
return await embed({
width,
datasets: {
originals,
means,
variances,
amplitudes,
},
resolve: { scale: { x: 'shared', y: 'independent' } },
layer: [
...EXPECTED_PEAKS.map(({ x }) => ({
data: { values: [{}] },
mark: { type: 'rule', color: '#000000', size: 1, scale: { domainMin: xmin, domainMax: xmax } },
encoding: { x: { type: 'quantitative', datum: x } },
})),
...[
{ data: { name: 'originals' }, color: { value: '#ff0000' } },
{ data: { name: 'means' }, color: { value: '#00ff00' } },
{ data: { name: 'variances' }, color: { value: '#0000ff' } },
{ data: { name: 'amplitudes' }, color: { value: '#ffff00' } },
{ data: { name: 'amplitudes' }, color: { value: '#ff00ff' } },
].map(({ data, color }) => ({
data,
mark: 'line',
encoding: {
x: { field: 'x', type: 'quantitative', scale: { domainMin: xmin, domainMax: xmax } },
y: { field: 'y', type: 'quantitative' },
color,
},
})),
],
})
}