Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

# patterns module

Generic Numba-compiled functions for working with patterns.

## discrete_interp_nb function

    discrete_interp_nb(
        arr,
        i,
        source_size,
        target_size
    )

Get the value at a specific position in a target size using discrete interpolation.

## fit_pattern_nb function

    fit_pattern_nb(
        arr,
        pattern,
        interp_mode=3,
        rescale_mode=0,
        vmin=nan,
        vmax=nan,
        pmin=nan,
        pmax=nan,
        invert=False,
        error_type=0,
        max_error=nan,
        max_error_interp_mode=None
    )

Fit pattern.

Returns the resized and rescaled pattern and max error.

## interp_nb function

    interp_nb(
        arr,
        i,
        source_size,
        target_size,
        interp_mode
    )

Get the value at a specific position in a target size using an interpolation mode.

See InterpMode.

## interp_resize_1d_nb function

    interp_resize_1d_nb(
        arr,
        target_size,
        interp_mode
    )

Resize an array using interp_nb().

## linear_interp_nb function

    linear_interp_nb(
        arr,
        i,
        source_size,
        target_size
    )

Get the value at a specific position in a target size using linear interpolation.

## mixed_interp_nb function

    mixed_interp_nb(
        arr,
        i,
        source_size,
        target_size
    )

Get the value at a specific position in a target size using mixed interpolation.

Mixed interpolation is based on the discrete interpolation, while filling resulting NaN values using the linear interpolation. This way, the vertical scale of the pattern array is respected.

## nearest_interp_nb function

    nearest_interp_nb(
        arr,
        i,
        source_size,
        target_size
    )

Get the value at a specific position in a target size using nearest-neighbor interpolation.

## pattern_similarity_nb function

    pattern_similarity_nb(
        arr,
        pattern,
        interp_mode=3,
        rescale_mode=0,
        vmin=nan,
        vmax=nan,
        pmin=nan,
        pmax=nan,
        invert=False,
        error_type=0,
        distance_measure=0,
        max_error=nan,
        max_error_interp_mode=None,
        max_error_as_maxdist=False,
        max_error_strict=False,
        min_pct_change=nan,
        max_pct_change=nan,
        min_similarity=nan,
        minp=None
    )

Get the similarity between an array and a pattern array.

At each position in the array, the value in `arr` is first mapped into the range of `pattern`. Then, the absolute distance between the actual and expected value is calculated (= error). This error is then divided by the maximum error at this position to get a relative value between 0 and 1. Finally, all relative errors are added together and subtracted from 1 to get the similarity measure.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings