casys.editing.filter

OCTANT-NG filter classes.

Classes

CompositeFilter(filters)

Apply several individual filters one after the other.

Median(half_window_size[, ...])

Median filter.

Mean(half_window_size[, rejection_threshold])

Bartlett(half_window_size[, rejection_threshold])

Gaussian(half_window_size[, ...])

Gaussian filter.

Hamming(half_window_size[, ...])

Kernel = alpha + beta * cos(x).

Lanczos([half_window_size, ...])

Lanczos filter.

IterativeFilter(filter, nb_iter[, ...])

Apply a filter several times, output also contains a selection indicator.

ResampleFilter(filter)

Apply a filter on data with evenly spaced abscissa (data is resampled before and after filtering if needed)

class casys.editing.filter.Bartlett(half_window_size, rejection_threshold=0)

Bases: ConvolutionFilter

Parameters:
  • half_window_size (float)

  • rejection_threshold (int)

apply(x_in, y_in, **kwargs)
Parameters:
  • x_in (ndarray) – Input abscissa

  • y_in (ndarray) – Input ordinates

  • kwargs

    check_param

    check x_in/y_in parameters

    evenly_spaced_absc

    Are abscissa evenly spaced ? (default=False) If so, a special scipy processing - possibly faster - is applied WARNING : if true, NaN values in y_in are forbidden (use ResampleFilter)

    plot

    plot input and output signals

    preserve_dim

    Preserve dimension after filtering (default=True)

Returns:

Output (filtered) ordinates

property half_window_size: float
property name: str

returns: The filter name

property param_info: str

returns: The extra parameters information

property rejection_threshold: int
class casys.editing.filter.CompositeFilter(filters)

Bases: Filter

Apply several individual filters one after the other.

Parameters:

filters (list | tuple)

apply(x_in, y_in, **kwargs)
Parameters:
  • x_in (ndarray) – Input abscissa

  • y_in (ndarray) – Input ordinates (NaN values may be allowed : depends on selected filters)

  • kwargs

    check_param

    check x_in/y_in parameters

    evenly_spaced_absc

    Are abscissa evenly spaced ? (default=False)

    plot

    plot input and output signals

Returns:

Output (filtered) ordinates

property filters: list[Filter]
property name: str

returns: The filter name

class casys.editing.filter.Gaussian(half_window_size, rejection_threshold=0, sigma=0.5)

Bases: ConvolutionFilter

Gaussian filter.

half_window_size

The window size in one direction, the real size is 2*half_window_size. This value is related to the abscissa step of the x apply(x,y) parameter, its unit is the same as abscissa (seconds for timedelta).

rejection_threshold

Number of minimum valid points in a window below which the output is invalidated.

sigma

Standard deviation coefficient

Parameters:
  • half_window_size (float)

  • rejection_threshold (int)

  • sigma (float)

apply(x_in, y_in, **kwargs)
Parameters:
  • x_in (ndarray) – Input abscissa

  • y_in (ndarray) – Input ordinates

  • kwargs

    check_param

    check x_in/y_in parameters

    evenly_spaced_absc

    Are abscissa evenly spaced ? (default=False) If so, a special scipy processing - possibly faster - is applied WARNING : if true, NaN values in y_in are forbidden (use ResampleFilter)

    plot

    plot input and output signals

    preserve_dim

    Preserve dimension after filtering (default=True)

Returns:

Output (filtered) ordinates

property half_window_size: float
property name: str

returns: The filter name

property param_info: str

returns: The extra parameters information

property rejection_threshold: int
property sigma: float
class casys.editing.filter.Hamming(half_window_size, rejection_threshold=0, alpha=0.54, beta=0.46)

Bases: ConvolutionFilter

Kernel = alpha + beta * cos(x).

Hamming : alpha=0.54, beta=0.46 Hanning : alpha=beta=0.5 https://en.wikipedia.org/wiki/Window_function

Parameters:
property alpha: float
apply(x_in, y_in, **kwargs)
Parameters:
  • x_in (ndarray) – Input abscissa

  • y_in (ndarray) – Input ordinates

  • kwargs

    check_param

    check x_in/y_in parameters

    evenly_spaced_absc

    Are abscissa evenly spaced ? (default=False) If so, a special scipy processing - possibly faster - is applied WARNING : if true, NaN values in y_in are forbidden (use ResampleFilter)

    plot

    plot input and output signals

    preserve_dim

    Preserve dimension after filtering (default=True)

Returns:

Output (filtered) ordinates

property beta: float
property half_window_size: float
property name: str

returns: The filter name

property param_info: str

returns: The extra parameters information

property rejection_threshold: int
class casys.editing.filter.IterativeFilter(filter, nb_iter, std_coeff=1.0, const_coeff=0.0)

Bases: Filter

Apply a filter several times, output also contains a selection indicator.

Parameters:
apply(x_in, y_in, **kwargs)

Apply filter to ordinates.

Parameters:
  • x_in (ndarray) – Input abscissa.

  • y_in (ndarray) – Input ordinates (NaN values allowed).

  • kwargs

    check_param

    check x_in/y_in parameters.

    evenly_spaced_absc

    Are abscissa evenly spaced ? (default=False) If so, a special scipy processing - possibly faster - is applied for median and convolution filters.

    plot

    plot input and output signals.

    threshold

    threshold (default=3.0).

Return type:

ndarray

Returns:

Output (filtered) ordinates.

apply_filter(x_in, y_in, **kwargs)

Apply filter to ordinates and compute the validity mask. (this function was created to be used for IterativeFilter of algo/editing)

Return type:

tuple[ndarray, ndarray]

Returns:

Output (filtered) ordinates and Validity mask (True or False array).

Parameters:
property filter: Filter
property name: str

returns: The filter name

property nb_iter: int
property selection: ndarray | None

returns: The output selection (updated after each “apply” call)

class casys.editing.filter.Lanczos(half_window_size=None, rejection_threshold=0, nb_lobes=1, cutoff=None)

Bases: ConvolutionFilter

Lanczos filter.

https://en.wikipedia.org/wiki/Lanczos_resampling

Parameters:
  • half_window_size (float | None) – The window size in one direction, the real size is 2*half_window_size. This value is related to the abscissa step of the x apply(x,y) parameter, its unit is the same as abscissa (seconds for timedelta).

  • rejection_threshold (int) – Number of minimum valid points in a window below which the output is invalidated.

  • nb_lobes (int) – Number of lobes.

  • cutoff (float | None) – Cutoff frequency.

apply(x_in, y_in, **kwargs)
Parameters:
  • x_in (ndarray) – Input abscissa

  • y_in (ndarray) – Input ordinates

  • kwargs

    check_param

    check x_in/y_in parameters

    evenly_spaced_absc

    Are abscissa evenly spaced ? (default=False) If so, a special scipy processing - possibly faster - is applied WARNING : if true, NaN values in y_in are forbidden (use ResampleFilter)

    plot

    plot input and output signals

    preserve_dim

    Preserve dimension after filtering (default=True)

Returns:

Output (filtered) ordinates

property cutoff
property half_window_size: float
property name: str

returns: The filter name

property nb_lobes
property param_info: str

returns: The extra parameters information

property rejection_threshold: int
class casys.editing.filter.Mean(half_window_size, rejection_threshold=0)

Bases: ConvolutionFilter

Parameters:
  • half_window_size (float)

  • rejection_threshold (int)

apply(x_in, y_in, **kwargs)
Parameters:
  • x_in (ndarray) – Input abscissa

  • y_in (ndarray) – Input ordinates

  • kwargs

    check_param

    check x_in/y_in parameters

    evenly_spaced_absc

    Are abscissa evenly spaced ? (default=False) If so, a special scipy processing - possibly faster - is applied WARNING : if true, NaN values in y_in are forbidden (use ResampleFilter)

    plot

    plot input and output signals

    preserve_dim

    Preserve dimension after filtering (default=True)

Returns:

Output (filtered) ordinates

property half_window_size: float
property name: str

returns: The filter name

property param_info: str

returns: The extra parameters information

property rejection_threshold: int
class casys.editing.filter.Median(half_window_size, rejection_threshold=0, mean_value=0)

Bases: WindowFilter

Median filter.

Parameters:
  • half_window_size (float) – The window size in one direction, the real size is 2*half_window_size. This value is related to the abscissa step of the x apply(x,y) parameter, its unit is the same as abscissa (seconds for timedelta).

  • rejection_threshold (int) – Number of minimum valid points in a window below which the output is invalidated.

  • mean_value (int) – Half window size of mean sorted values window filter This window is applied on the rolling window defined by half_window_size attributes.

apply(x_in, y_in, check_param=False, evenly_spaced_absc=False, plot=False, preserve_dim=True, same_mask=True, **kwargs)

Apply median filter.

Parameters:
  • x_in (ndarray) – Input abscissa

  • y_in (ndarray) – Input ordinates

  • check_param (bool) – check x_in/y_in parameters

  • evenly_spaced_absc (bool) – Are abscissa evenly spaced ? (default=False) If so, a special scipy processing - possibly faster - is applied WARNING : if true, NaN values in y_in are forbidden (use ResampleFilter)

  • plot (bool) – plot input and output signals

  • preserve_dim (bool) – Preserve dimension in the result (default=True)

  • same_mask (bool) – If True (default), the filtered signal will have invalids where the input is invalid.

  • **kwargs – Arbitrary keyword arguments. Ignored by this filter

Return type:

ndarray

Returns:

Output (filtered) ordinates

property half_window_size: float
property mean_value: int
property name: str

returns: The filter name

property rejection_threshold: int
class casys.editing.filter.ResampleFilter(filter)

Bases: Filter

Apply a filter on data with evenly spaced abscissa (data is resampled before and after filtering if needed)

Parameters:

filter (Filter)

apply(x_in, y_in, **kwargs)
Parameters:
  • x_in (ndarray) – Input abscissa

  • y_in (ndarray) – Input ordinates (NaN values allowed)

  • kwargs

    max_step

    Add a constraint to the creation of the evenly spaced abscissa (x_reg) : The effective step if then the highest value < max_step keeping the same bounds (i.e. x_reg[0] = x_in[0] and x_reg[-1] = x_in[-1]). Default value : the median step of x_in

Return type:

ndarray

Returns:

Output (filtered) ordinates

property filter
property name: str

returns: The filter name

property selection: ndarray

returns: The output selection if filter is an IterativeFilter