Demean
Demean(
*args ,
dim: str = time,
)-> None
Remove the mean along a given dimension of a DASCore patch.
NaN values are ignored when computing the mean, consistent with Patch.mean. They remain NaN in the output but do not affect any other sample.
Parameters
| Parameter | Description |
|---|---|
| patch : | The patch to remove the mean from. |
| dim : str | Dimension name (e.g., “time”, “distance”). |
import matplotlib.pyplot as plt import dascore as dc import numpy as np
patch = dc.get_example_patch(‘example_event_2’) nx,nt = patch.data.shape
Add some periodic common-mode noise
x = np.linspace(0, 6 * np.pi, nt) y = np.sin(x) * patch.data.max() / 30 Y = y[np.newaxis, :] * np.ones((nx,nt), dtype=float) patch0 = patch + Y
Prepare figure
fig, axs = plt.subplots(1, 3, figsize=(20,8), layout=‘constrained’)
Show patch with common-mode noise
ax0 = patch0.viz.waterfall(ax = axs[0], show=False) _ = ax0.set_title(‘Original with common-mode noise’);
Show demean applied patch
patch1 = patch0.demean(dim=‘distance’) ax1 = patch1.viz.waterfall(ax = axs[1], show=False) _ = ax1.set_title(‘Removed common-mode noise’);
Show difference
ax2 = (patch0-patch1).viz.waterfall(ax = axs[2], show=False) _ = ax2.set_title(‘Difference’);
plt.show() # doctest: +SKIP plt.close(fig)
Methods
| Name | Description |
|---|---|
| check | Refuse a patch which does not carry what the operation needs. |
| derive | Return the result’s metadata, as a patch without data. |
| kernel | Return the data with the mean of each slice taken out. |
| new | Create new instance with some attributed updated. |
| demean | Remove the mean along a given dimension of a DASCore patch. |
| plan | Return the axis to remove the mean along. |
| reconcile | Return the result’s metadata once the data are known; default as is. |
| run | Run the operation: check, derive, plan, kernel, reconcile, record. |