SpikeInterface / spikeinterface

A Python-based module for creating flexible and robust spike sorting pipelines.
https://spikeinterface.readthedocs.io
MIT License
526 stars 187 forks source link

Polyorder must be less than the window length error #3176

Closed AbhiSwamiUConn closed 4 months ago

AbhiSwamiUConn commented 4 months ago
SpikeSortingError                         Traceback (most recent call last)
File ~\anaconda3\Lib\site-packages\spikeinterface\sorters\runsorter.py:175, in run_sorter(sorter_name, recording, output_folder, remove_existing_folder, delete_output_folder, verbose, raise_error, docker_image, singularity_image, delete_container_files, with_output, **sorter_params)
    168             container_image = singularity_image
    169     return run_sorter_container(
    170         container_image=container_image,
    171         mode=mode,
    172         **common_kwargs,
    173     )
--> 175 return run_sorter_local(**common_kwargs)

File ~\anaconda3\Lib\site-packages\spikeinterface\sorters\runsorter.py:225, in run_sorter_local(sorter_name, recording, output_folder, remove_existing_folder, delete_output_folder, verbose, raise_error, with_output, **sorter_params)
    223 SorterClass.set_params_to_folder(recording, output_folder, sorter_params, verbose)
    224 SorterClass.setup_recording(recording, output_folder, verbose=verbose)
--> 225 SorterClass.run_from_folder(output_folder, raise_error, verbose)
    226 if with_output:
    227     sorting = SorterClass.get_result_from_folder(output_folder, register_recording=True, sorting_info=True)

File ~\anaconda3\Lib\site-packages\spikeinterface\sorters\basesorter.py:292, in BaseSorter.run_from_folder(cls, output_folder, raise_error, verbose)
    289         print(f"{sorter_name} run time {run_time:0.2f}s")
    291 if has_error and raise_error:
--> 292     raise SpikeSortingError(
    293         f"Spike sorting error trace:\n{log['error_trace']}\n"
    294         f"Spike sorting failed. You can inspect the runtime trace in {output_folder}/spikeinterface_log.json."
    295     )
    297 return run_time

SpikeSortingError: Spike sorting error trace:
concurrent.futures.process._RemoteTraceback: 
"""
Traceback (most recent call last):
  File "C:\Users\User\anaconda3\Lib\concurrent\futures\process.py", line 261, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\anaconda3\Lib\concurrent\futures\process.py", line 210, in _process_chunk
    return [fn(*args) for args in chunk]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\anaconda3\Lib\concurrent\futures\process.py", line 210, in <listcomp>
    return [fn(*args) for args in chunk]
            ^^^^^^^^^
  File "C:\Users\User\anaconda3\Lib\site-packages\spikeinterface\core\job_tools.py", line 451, in function_wrapper
    return _func(segment_index, start_frame, end_frame, _worker_ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\anaconda3\Lib\site-packages\spikeinterface\core\node_pipeline.py", line 522, in _compute_peak_pipeline_chunk
    node_output = node.compute(traces_chunk, *node_input_args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\anaconda3\Lib\site-packages\spikeinterface\sortingcomponents\waveforms\savgol_denoiser.py", line 59, in compute
    denoised_waveforms = scipy.signal.savgol_filter(waveforms, self.window_length, self.order, axis=1)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\anaconda3\Lib\site-packages\scipy\signal\_savitzky_golay.py", line 341, in savgol_filter
    coeffs = savgol_coeffs(window_length, polyorder, deriv=deriv, delta=delta)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\anaconda3\Lib\site-packages\scipy\signal\_savitzky_golay.py", line 101, in savgol_coeffs
    raise ValueError("polyorder must be less than window_length.")
ValueError: polyorder must be less than window_length.
"""

I am getting this error when running a large plexon file with a 8k sampling rate. Looking further into the issue, I notice that others have also faced this problem, such as in #1871. Is this something on my end. I am running version 0.100.8.

zm711 commented 4 months ago

@yger, I think you were working on figuring this out, no?

yger commented 4 months ago

I'll fix that with a PR. Meanwhile, you can simply get rid of that with passing some parameters to SC2 like clutering={"smoothing_kwargs": {"window_length_ms": 0.25, "order" : 1}}.

yger commented 4 months ago

But actually, are you using the main branch? Because it seems to be already fixed in main

AbhiSwamiUConn commented 4 months ago

Got it. Thank you for your help.