MedianFilter

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

MedianFilter(
    *args ,
    samples: Any = False,
    mode: Any = reflect,
    cval: Any = 0.0,
    **kwargs ,
)-> None

Apply 2-D median filter.

Parameters

Parameter Description
patch The patch to filter
samples If True, the values in kwargs and step represent samples along a
dimension. Must be integers. Otherwise, values are assumed to have
same units as the specified dimension, or have units attached.
mode The mode for handling edges.
cval The constant value for when mode == constant.
**kwargs Used to specify the shape of the median filter in each dimension.
See examples for more info.

Examples

import dascore
from dascore.units import m, s
pa = dascore.get_example_patch()
 # 1. Apply median filter only over time dimension with 0.10 sec window
filtered_pa_1 = pa.median_filter(time=0.1)
 # 2. Apply median filter over both time and distance
 # using a 0.1 second time window and 2 m distance window
filtered_pa_2 = pa.median_filter(time=0.1 * s, distance=2 * m)
 # 3. Apply median filter with 3 time samples and 4 distance samples
filtered_pa = pa.median_filter(
    time=3, distance=4, samples=True,
)
Note

See scipy.ndimage.median_filter for more info on implementation and arguments.

Values specified with kwargs should be small, for example < 10 samples otherwise this can take a long time and use lots of memory.

Keywords

filtering, median, smoothing, denoising

Methods

Name Description
check Refuse a patch which does not carry what the operation needs.
get_metadata Return the window along every axis, and the axes it spans.
model_copy Copy the model, dropping cached values the update invalidates.
new Create new instance with some attributed updated.
numpy_kernel Return the median of the window around each sample.
median_filter Apply 2-D median filter.
reconcile Return metadata or a patch holding the final data; default as is.
run Run the operation: check, get_metadata, kernel, reconcile, record.