Skip to content

BUG: peak_analysis function causes program crash #20

@FOSSatScribner

Description

@FOSSatScribner

Environment:

Windows 10

Package versions:

❯ pip list
Package            Version
------------------ -----------
certifi            2024.8.30  
charset-normalizer 2.0.12     
click              8.1.7      
colorama           0.4.6      
contourpy          1.3.0      
cvxopt             1.3.2      
cycler             0.12.1     
fonttools          4.54.1     
idna               3.10       
joblib             1.4.2      
kiwisolver         1.4.7      
matplotlib         3.7.3
numpy              1.24.1
packaging          24.1
pandas             1.5.3
pillow             11.0.0
pip                23.2.1
pyparsing          3.2.0
PyQt5              5.15.9
PyQt5-Qt5          5.15.2
PyQt5_sip          12.15.0
python-dateutil    2.9.0.post0
pytz               2024.2
requests           2.28.0
scikit-learn       1.5.2
scipy              1.10.0
setuptools         68.2.0
six                1.16.0
threadpoolctl      3.5.0
urllib3            1.26.20
wheel              0.41.2

pyDRTools GIT commit ID: c886aaf

What happened

Using pyDRTools with the example data located at: 'EIS data\text files\LIB_data.txt'
I ran a "simple run" with inductance modeled in, then fit 4 peaks resulting in the following UI state:
image

Running the same analysis with "5" peaks causes a program crash.

Root Cause

The crash occurs in the "runs.py" file because of an inconsistent use of the "N_Peaks" parameter entered by the user. The inconsistent use of N_Peaks causes out of bounds array accesses, causing a crash.

When the software runs this code:

    # Find initial peaks in the gamma spectrum
    peak_indices, _ = find_peaks(entry.gamma, height=0.005 * np.std(entry.gamma), distance=5)
    N_peaks = min(len(peak_indices), entry.N_peaks)

on the data, the "find_peaks" function returns the number of local maxima. This is not the same thing as the number of peaks the peak_fct algorithm is supposed to find. What's more is that it's unclear what "find_peaks" is used for.

Here is a patch that fixes the issue from a programming perspective, I am unsure if it is correct.
peak_analysis_fix.patch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions