Demedian

class of dascore.proc.basic
inherits from: PatchProcessor, DascoreBaseModel, pydantic.main.BaseModel
source

Demedian(
    *args ,
    dim: str = time,
)-> None

Remove the median along a given dimension of a DASCore patch.

NaN values are ignored when computing the median, consistent with Patch.median. They remain NaN in the output but do not affect any other sample.

Parameters

Parameter Description
patch : The patch to remove the median from.
dim : str Dimension name (e.g., “time”, “distance”).

Example

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 demedian applied patch
patch1 = patch0.demedian(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.
get_metadata Return the axis to remove the median along.
model_copy Copy the model, dropping cached values the update invalidates.
new Create new instance with some attributed updated.
numpy_kernel Return the data with the NaN-ignoring median of each slice removed.
demedian Remove the median along a given dimension of a DASCore patch.
reconcile Return metadata or a patch holding the final data; default as is.
run Run the operation: check, get_metadata, kernel, reconcile, record.