This HTML automatically generated with rman for NEMO
Table of Contents

Name

tabsmooth - smooth columns of a table (Hanning, Savitzky-Golay)

Synopsis

tabsmooth [parameter=value]

Description

tabsmooth convolves selected column(s) of an ASCII table. It does this without paying attention to the actual X coordinate (meaning: a constant step size is assumed). Use tabspline(1NEMO) to interpolate across an irregularly sampled table.

The filter= option is used to select the filter, for example a Hanning, Boxcar, Gaussian and a Savitzky-Golay filter (and some of their derivates) can be selected. A pass-through is also allowed. Some of the filters need additional argument(s), given by pars= and are described below.

Optionally the smoothing kernel can be shown using show=t without the need to read a table.

Parameters

The following parameters are recognized in any order if the keyword is also given:
in=
Input file name.
No default
xcol=
Column(s) to use. Although multiple columns can be used, only those columns are output to stdout.
[1]
filter=
Filter option. The way the options are set will likely change, this is work in progress. Either a number value can be given, or a minimum match to the filter name, as shown in the first column:
   -1   passthrough, the column(s) not modified
   0,h  hanning (1,2,1)
   1    SK2 5pt smooth
   2    SK2 1st derivative with h=1 (sum=0)
   3    SK2 2nd derivative with h=1 (sum=0)
   4    SK4 7pt smooth
   5    SK4 1st derivative  (sum=0)
  11,b  boxcar, needs  pars=width
  12,g  gaussian, needs pars=width[,nsigma=4,old_width=0]
  13,t  trapezoidal, needs pars=width (width=1 is also the hanning)
The smoothing kernels are normalized to 1 to conserve "flux" (defined as the sum of values here), though there will be some flux loss at the edges of a table. The width is given in pixels. If the optional old_width is given, the smoothing kernel is determines from the usual sqrt(new**2-old**2). Note that for the gaussian width is meant to the FWHM = 2.355 * sigma


Default: 0

pars=par1,par2,...
Optional parameters some of the filters need. See filter= for the filters that need parameters.
Default: not used
smooth=
Manually set the smoothing array. By default, the filter= is used to set the smoothing array. Be sure to enter an odd number of array elements, for example a normalized Hanning would be smooth=0.25,0.5,0.25.
Default: not used.
tcol=
Optional column designating the independant variable. Currently the actual value is ignored, but this column will be output before the smoothed column(s).
Default: not used.
show=t|f
If set, it will show the smoothing kernel. No input file is needed in this case.
Default: f
nsmooth=
Number of successive smoothings applied.
Not implemented yet, just a single smoothing is applied.
edge=0|1|2
how to deal with edges. See EDGE below. Only a limited number have been implemented.
Default: 0

Edge

Treatment of smoothing the edge has several options. In general the flux will not be conserved near the edge. Here we compare how this is handled in a few popular packages:

1) Following the EDGE options in the IDL package (see https://www.nv5geospatialsoftware.com/docs/CONVOL.html) we have:

EDGE_CONSTANT
Set the outside edge to a specific value. If 0, that’s EDGE_ZERO, if not we should capture that value. -- not implemented here --
"...CCCC|abcdefg|CCCC..."
EDGE_MIRROR
This is out edge=1.
"gfedcba|abcdefg|gfedcba"
EDGE_REFLECT
reflection. like mirror, but shifted over one.
"gfedcb|abcdefg|fedcba".
EDGE_TRUNCATE
This is the default in gbtidl (edge=2) for the left side. Why the right side needs to inherit the left side is beyond me. Seems like a typo to me.
"..aaa|abcdefg|aaa.."
EDGE_WRAP
wrapping
"abcdefg|abcdefg|abcdefg".
EDGE_ZERO
Our edge=0
"...0000|abcdefg|0000...".

2) Following astropy (see https://docs.astropy.org/en/stable/convolution/index.html) we have:

boundary=’fill’
Default fill value is 0.0 (edge=0)
This is the default in astropy.
boundary=’extend’
Constant extrapolation of the edge value beyond the boundary (edge=2)

Examples

Here we draw 100000 random values from a normal distribution (mean 0, dispersion 1) and smooth them with various filters, and observe what the resulting dispersion is:

tabgen - 100000 1 2 123| tabsmooth - 1 -1 | tabstat - | grep disp 1.0022 tabgen - 100000 1 2 123| tabsmooth - 1 0 | tabstat - | grep disp 0.6128 tabgen - 100000 1 2 123| tabsmooth - 1 1 | tabstat - | grep disp 0.6973 tabgen - 100000 1 2 123| tabsmooth - 1 4 | tabstat - | grep disp 0.7537

Here is the gaussian smoothing kernel, then applied to the previous example using a NEMO @file

$ tabsmooth . filter=g pars=2 show=t
0.000917431
0.0293578
0.234862
0.469725
0.234862
0.0293578
0.000917431

$ tabsmooth . filter=g pars=2 show=t > smg.tab
$ tabgen - 100000 1 2 123| tabsmooth - 1 smooth=@smg.tab | tabstat - | grep disp
disp: 0.577259

$ nemoinp 1:20 | tabmath - - ’ifeq(%1,10,1,0)’ |\
tabsmooth - 2 g 4 tcol=1 | tabnllsqfit - fit=gauss1d
Fitting a+b*exp(-(x-c)^2/(2*d^2)):
a= -9.44068e-06 4.59111e-06
b= 0.234891 1.12118e-05
c= 10 8.96171e-05
d= 1.69874 0.000101174

In the last example a delta-function is convolved with a gaussian of (fwhm) width=4, thus the (sigma) d parameter should fit as 4/2.355 = 1.698

See Also

tabmath(1NEMO) , tabtrend(1NEMO) , tabrows(1NEMO) , tabcols(1NEMO) , tabspline(1NEMO) , ccdsmooth(1NEMO) , table(5NEMO)

Author

Peter Teuben

History


20-dec-2010    V0.1 Created, Q&D    PJT
13-oct-2014    documented smooth=    PJT
28-sep-2023    V0.5 added filter=    PJT
29-sep-2023    V0.6 converted to table V2    PJT
29-nov-2023    V0.7 added tcol=    PJT
21-jun-2023    V0.8 added show= and pars= for filters     PJT


Table of Contents