bendalab / thunderfish

python scripts for analyzing recordings of efish electric fields.
GNU General Public License v3.0
5 stars 8 forks source link

error: threshold array incomaptible in bestwindow.py #100

Closed muchaste closed 2 years ago

muchaste commented 2 years ago

Recording of wavetype fish (normalized wav file, fs = 20000 Hz) yields error

Error log:

C:\Users\XXXX>thunderfish "recording.wav" analyze recording C:\Users\XXXX\recording.wav ... Traceback (most recent call last): File "c:\users\XXXX\anaconda3\lib\site-packages\thunderfish\thunderfish.py", line 1111, in run_thunderfish msg = thunderfish(file, *pool_args) File "c:\users\XXXX\anaconda3\lib\site-packages\thunderfish\thunderfish.py", line 1023, in thunderfish data, idx0, idx1, clipped, min_clip, max_clip = find_best_window(raw_data, samplerate, File "c:\users\XXXX\anaconda3\lib\site-packages\thunderfish\bestwindow.py", line 680, in find_best_window idx0, idx1, clipped = best_window_indices(raw_data, samplerate, File "c:\users\XXXX\anaconda3\lib\site-packages\thunderfish\bestwindow.py", line 308, in best_window_indices peak_idx, trough_idx = detect_peaks(data, threshold) File "c:\users\XXXX\anaconda3\lib\site-packages\thunderfish\eventdetection.py", line 87, in detect_peaks raise ValueError('input argument threshold must be positive!') ValueError: input argument threshold must be positive!

Manual traceback: bestwindow.py: percentile_threshold (line 303) creates array of thresholds which is incompatible with detect_peaks

Makeshift solution: in bestwindow.py:

insert if/else condition with detect_array_peaks after line 307: if(len(threshold)==1): peak_idx, trough_idx = detect_peaks(data, threshold) else: peak_idx, trough_idx = detect_peaks_array(data, threshold)

add detect_array_peaks to import

There's probably a better fix but this works for us.

janscience commented 2 years ago

Can you please check, whether you get this error with my fork on janscience ? I did change something on the detect_peaks() function, maybe that solves this issue.

muchaste commented 2 years ago

Results in a similar error: C:\Users\XXXX>thunderfish "C:\Users\XXXX\recording.wav" analyze recording C:\Users\XXXX\recording.wav ... Traceback (most recent call last): File "c:\users\XXXX\thunderfish_troubleshoot\lib\site-packages\thunderfish\thunderfish.py", line 1102, in run_thunderfish msg = thunderfish(file, *pool_args) File "c:\users\XXXX\thunderfish_troubleshoot\lib\site-packages\thunderfish\thunderfish.py", line 1014, in thunderfish data, idx0, idx1, clipped, min_clip, max_clip = find_best_window(raw_data, samplerate, File "c:\users\XXXX\thunderfish_troubleshoot\lib\site-packages\thunderfish\bestwindow.py", line 688, in find_best_window idx0, idx1, clipped = best_window_indices(raw_data, samplerate, File "c:\users\XXXX\thunderfish_troubleshoot\lib\site-packages\thunderfish\bestwindow.py", line 316, in best_window_indices peak_idx, trough_idx = detect_peaks(data, threshold) File "c:\users\XXXX\thunderfish_troubleshoot\lib\site-packages\thunderfish\eventdetection.py", line 96, in detect_peaks raise ValueError('threshold values must be positive!') ValueError: threshold values must be positive!

janscience commented 2 years ago

Ok. I found it. In eventdetection.py: percentile_threshold() returned for the last window a zero threshold, because there was only a single data point in this window. I fixed it.