Skip to content

Commit

Permalink
fix smooth recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers committed Jan 6, 2024
1 parent 87de2c5 commit 0a9de69
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions docs/recipes/smoothing.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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`)
- [`Patch.gaussian_filter`](`dascore.Patch.gaussian_filter`)


:::{.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.
:::
Expand Down Expand Up @@ -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");
```

0 comments on commit 0a9de69

Please sign in to comment.