Skip to content

nk.signal_recompose() is broken #1200

Description

@yanbingyu07

I am trying testing the signal decompose/recompose functions with the example from the home page, as shown below:

import neurokit2 as nk
import numpy as np

# Create complex signal
signal = nk.signal_simulate(duration=10, frequency=1)  # High freq
signal += 3 * nk.signal_simulate(duration=10, frequency=3)  # Higher freq
signal += 3 * np.linspace(0, 2, len(signal))  # Add baseline and linear trend
signal += 2 * nk.signal_simulate(duration=10, frequency=0.1, noise=0)  # Non-linear trend
signal += np.random.normal(0, 0.02, len(signal))  # Add noise
nk.signal_plot(signal)  # Visualize signal

# Decompose signal using Empirical Mode Decomposition (EMD)
components = nk.signal_decompose(signal, method='emd')
nk.signal_plot(components)  # Visualize components

# Recompose merging correlated components
recomposed = nk.signal_recompose(components, threshold=0.99)
nk.signal_plot(recomposed)  # Visualize components

But the signal_recompose() function was broken. The traceback shows line#103 of signal_recompose.py with error:

File c:\Users\scssh059\AppData\Local\Programs\Python\Python313\Lib\site-packages\neurokit2\signal\signal_recompose.py:103, in _signal_recompose_wcorr(components, threshold, metric)
    100 wcorr = _signal_recompose_get_wcorr(components, show=False)
    102 # Find clusters in correlation matrix
--> [103](file:///C:/Users/scssh059/AppData/Local/Programs/Python/Python313/Lib/site-packages/neurokit2/signal/signal_recompose.py:103) pairwise_distances = scipy.cluster.hierarchy.distance.pdist(wcorr, metric=metric)
    104 linkage = scipy.cluster.hierarchy.linkage(pairwise_distances, method="complete")
    105 threshold = threshold * pairwise_distances.max()

AttributeError: module 'scipy.cluster.hierarchy' has no attribute 'distance'

The version of scipy is 1.18.0 on my pc, which is running Windows11.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions