Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing rubberband baseline case #29

Open
rguliev opened this issue Dec 5, 2024 · 1 comment
Open

Failing rubberband baseline case #29

rguliev opened this issue Dec 5, 2024 · 1 comment

Comments

@rguliev
Copy link

rguliev commented Dec 5, 2024

Description

I got a case, where 'rubberband' baseline fails.
However, I tried a simpler implementation from here and it worked.

Your Setup

  • Operating System: Windows 11
  • Python version: 3.12.4
  • pybaselines version: 1.1.0

Example Code

rubberband_example.csv

import numpy as np
import pybaselines

# Load the data
xy = np.genfromtxt("rubberband_example.csv")
x = xy[:,0]
y = xy[:,1]

# Try the baseline (raises an error)
# IndexError: arrays used as indices must be of integer (or boolean) type
bl = pybaselines.Baseline(x_data=x)
bl.rubberband(y)[0]

Working example:

import scipy
import numpy as np

def rubberband(x: np.array, y: np.array) -> np.ndarray:
    """
    Based on code from Stack Exchange (Author: Roman Kiselev)
    Source: https://dsp.stackexchange.com/a/30723/69444 (CC BY-SA 3.0)
    """
    v = scipy.spatial.ConvexHull(np.array([x, y]).T).vertices
    v = np.roll(v, -v.argmin())
    v = v[: (v.argmax() + 1)]
    bl = np.interp(x, x[v], y[v])

    return bl

rubberband(x,y)

Error Message

  File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pybaselines\_algorithm_setup.py:266 in inner
    baseline, params = func(self, y, *args, **kwargs)

  File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pybaselines\classification.py:905 in rubberband
    mask[np.unique(total_vertices)] = True

IndexError: arrays used as indices must be of integer (or boolean) type
@derb12
Copy link
Owner

derb12 commented Dec 5, 2024

Thanks for the bug report! This was caused by an incorrect handling of indices within rubberband. I fixed it on the development branch and will try to publish a new release to pypi in a week for two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants