Skip to content

Filter

eitprocessing.plotting.filter.FilterPlotting dataclass

FilterPlotting()

Utility class for plotting the effects of frequency filtering.

plot_results classmethod

plot_results(
    *,
    unfiltered_data: T,
    filtered_data: T,
    ax: Axes | None = None,
    sample_frequency: float | object = MISSING,
    high_pass_frequency: float | None = None,
    low_pass_frequency: float | None = None,
    frequency_bands: list[tuple[float, float]] | None = None,
    xlim_to_max_filter_freq: float | None = 2,
    **kwargs
) -> Axes

Plot frequency filtering results.

This function is designed to work with the captures from a ButterworthFilter or MDNFilter.

The plot shows the power spectra for the unfiltered and filtered data. If a high pass frequency or low pass frequency is provided, vertical lines are drawn at these frequencies. If frequency bands are provided, shaded regions are drawn for these bands.

The provided data can be either numpy arrays, ContinuousData, or EITData, and must be the same for the unfiltered and filtered data. If numpy arrays are used, the sample frequency must be provided. If ContinuousData or EITData are used, the sample frequency is taken from the data itself.

If an Axes instance is provided, the plot is drawn on that Axes. If not, a new figure and axes are created.

Axes scaling

The x-axis and y-axis can be scaled linearly or logarithmically using the xscale and yscale arguments. If not provided, xscale is set to "linear" and yscale is set to "log". If the x-scale is logarithmic, the default limits are used.

If the x-scale is linear, the upper limit is determined by the highest filter frequency or the sample frequency. If xlim_to_max_filter_freq is None, the x-axis ranges from 0 to half the sample frequency. If a value is provided, the x-axis limit is set to the maximum frequency of all filters multiplied by this value. This enables focussing on the filtered frequencies. Custom limits can be set using the returned axes object.

If the y-scale is linear, the default limits are used. If the y-scale is logarithmic, the axes are scaled such that the upper 95% of the data falls within the middle 80% of the axes. This ensures that very small outliers don't disproportionally scale the y-axis.

Warning

Although this function plots with the x-axis in beats per minute (BPM), the frequencies provided to it should be in Hz.

Example:

>>> mdn = MDNFilter(...)
>>> captures = {}
>>> filtered_data = mdn.apply(impedance_data, captures=captures)
>>> ax = FilterResultsPlotting().plot(**captures)

PARAMETER DESCRIPTION
unfiltered_data

The original data before filtering. Can be a numpy array, ContinuousData, or EITData.

TYPE: T

filtered_data

The data after filtering. Must be the same type as unfiltered_data.

TYPE: T

ax

Optional. A matplotlib Axes instance to plot on. If None, a new figure and axes will be created.

TYPE: Axes | None DEFAULT: None

sample_frequency

The sample frequency of the data. Must be provided only if input data are numpy arrays.

TYPE: float | object DEFAULT: MISSING

frequency_bands

Optional. A list of tuples defining frequency bands to highlight in the plot. Each tuple contains (low, high) frequencies in Hz.

TYPE: list[tuple[float, float]] | None DEFAULT: None

high_pass_frequency

Optional. The critical frequency for a high pass filter in Hz.

TYPE: float | None DEFAULT: None

low_pass_frequency

Optional. The critical frequency for a low pass filter in Hz.

TYPE: float | None DEFAULT: None

xlim_to_max_filter_freq

Optional. If provided, the upper x-axis limit will be set to the maximum frequency of all filters, times this value. If None, the x-axis is limited to half the sample frequency.

TYPE: float | None DEFAULT: 2

**kwargs

Extra keyword arguments to pass to the Axes.set() method, such as xlabel, ylabel, title, yscale, and xscale.

DEFAULT: {}

RETURNS DESCRIPTION
Axes

A matplotlib Axes instance with the plot of the frequency filtering results.