diff --git a/docs/recipes/smoothing.qmd b/docs/recipes/smoothing.qmd index 269c380c..45f139d3 100644 --- a/docs/recipes/smoothing.qmd +++ b/docs/recipes/smoothing.qmd @@ -6,7 +6,7 @@ execute: This recipe compares various smoothing strategies. -A few methods useful for smoothing are: +A few patch methods useful for smoothing are: - [`Patch.rolling`](`dascore.Patch.rolling`) - [`Patch.savgol_filter`](`dascore.Patch.savgol_filter`) @@ -14,7 +14,7 @@ A few methods useful for smoothing are: :::{.callout-note} -[`Patch.rolling`](`dascore.Patch.rolling`) is quite powerful and can be used for filtering in a variety of ways. However, as mentioned in the [rolling section of the tutorial](/tutorial/processing.qmd#rolling), [`Patch.rolling`](`dascore.Patch.rolling`) includes `NaN` entries in the output due to edge effects. This can require some additional thought to properly deal with. +[`Patch.rolling`](`dascore.Patch.rolling`) is quite flexible and can be used for many different processing tasks. However, as mentioned in the [rolling section of the tutorial](/tutorial/processing.qmd#rolling), [`Patch.rolling`](`dascore.Patch.rolling`) includes `NaN` entries in the output due to edge effects. This can require some additional thought to properly deal with. The other methods mentioned above generally deal with edge effects differently (governed by the `mode` parameter) and so don't have the same issue. ::: @@ -109,17 +109,31 @@ ax.set_title("savgol time and distance"); ## Gaussian filter -[`Patch.gaussian_filter`](`dascore.Patch.gaussian_filter`) uses [SciPy's gaussian_filter](https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html) to apply a gaussian smoothing kernel to a patch. Note that the keyword arguments here specify standard deviation, and the ` - +[`Patch.gaussian_filter`](`dascore.Patch.gaussian_filter`) uses [SciPy's gaussian_filter](https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html) to apply a gaussian smoothing kernel to a patch. Note that the keyword arguments here specify standard deviation, and the `truncate` keyword determines how many standard deviations are included in the smoothing kernel. ```{python} -smoothed_patch = ( - patch.gaussian_filter( - time=6, - distance=6, - samples=True, - ) +smoothed_patch = patch.gaussian_filter( + time=6, + distance=6, + samples=True, ) ax = smoothed_patch.viz.waterfall() ax.set_title("gaussian time and distance"); ``` + +To visualize the smoothing kernel we can apply the operator to a patch which has all 0 values except a 1 in the center. + +```{python} +data = np.zeros_like(smoothed_patch.data) +data[data.shape[0]//2, data.shape[1]//2] = 1.0 + +delta_patch = patch.update(data=data) + +smoothed_patch = delta_patch.gaussian_filter( + time=.005, + distance=15, +) + +ax = smoothed_patch.viz.waterfall() +ax.set_title("gaussian smoothing kernel"); +```