flatironinstitute / mountainsort5

MountainSort spike sorting algorithm, version 5
Apache License 2.0
36 stars 8 forks source link

PermissionError: [WinError 32] #34

Open borrepp opened 8 months ago

borrepp commented 8 months ago

Hello,

I'm using spikeInterface to run MS5 on Windows 11 and Python 3.8, but I got the following error when creating the sorting object. Thanks in advance for your help.

filtering whitening write_binary_recording: 100%|███████████████████████████████████████████████████████████████████████████████████| 49/49 [00:02<00:00, 20.12it/s] Using training recording of duration 300 sec with the sampling mode uniform MS5 Elapsed time for SCHEME2 get_sampled_recording_for_training: 0.000 seconds Running phase 1 sorting Number of channels: 1 Number of timepoints: 7329960 Sampling frequency: 30000.0 Hz Channel 0: [ 0. -3.1] Loading traces MS5 Elapsed time for load_traces: 0.000 seconds Detecting spikes

Adjacency for detect spikes with channel radius 200 [[0]]

m = 0 (nbhd size: 1) Detected 193 spikes MS5 Elapsed time for detect_spikes: 0.020 seconds Removing duplicate times MS5 Elapsed time for remove_duplicate_times: 0.000 seconds Extracting 193 snippets MS5 Elapsed time for extract_snippets: 0.001 seconds Computing PCA features with npca=3 MS5 Elapsed time for compute_pca_features: 0.002 seconds Isosplit6 clustering with npca_per_subdivision=10 Found 1 clusters MS5 Elapsed time for isosplit6_subdivision_method: 0.001 seconds Computing templates MS5 Elapsed time for compute_templates: 0.001 seconds Determining optimal alignment of templates Template alignment converged. Align templates offsets: [0] MS5 Elapsed time for align_templates: 0.000 seconds Aligning snippets MS5 Elapsed time for align_snippets: 0.000 seconds Clustering aligned snippets Computing PCA features with npca=3 MS5 Elapsed time for compute_pca_features: 0.002 seconds Isosplit6 clustering with npca_per_subdivision=10 MS5 Elapsed time for isosplit6_subdivision_method: 0.001 seconds Found 1 clusters after alignment Computing templates MS5 Elapsed time for compute_templates: 0.001 seconds Offsetting times to peak Offsets to peak: [0] MS5 Elapsed time for determine_offsets_to_peak: 0.000 seconds Sorting times MS5 Elapsed time for sorting times: 0.000 seconds Removing out of bounds times MS5 Elapsed time for removing out of bounds times: 0.000 seconds Reordering units MS5 Elapsed time for reordering units: 0.000 seconds Creating sorting object MS5 Elapsed time for creating sorting object: 0.000 seconds MS5 Elapsed time for SCHEME2 sorting_scheme1: 0.041 seconds MS5 Elapsed time for SCHEME2 get_times_labels_from_sorting: 0.000 seconds Loading training traces MS5 Elapsed time for SCHEME2 training_recording.get_traces: 0.000 seconds Training classifier MS5 Elapsed time for SCHEME2 training classifier step 1: 0.001 seconds Adding snippets from phase 1 sorting Fitting models MS5 Elapsed time for SCHEME2 fitting models: 0.006 seconds Chunk size: 3333.3333333333335 sec Time chunk 1 of 1 Loading traces MS5 Elapsed time for SCHEME2 loading traces: 0.000 seconds Detecting spikes

Adjacency for detect spikes with channel radius 50 [[0]]

Scheme 2 detected 193 spikes in chunk 1 of 1 MS5 Elapsed time for SCHEME2 detecting spikes: 0.030 seconds Extracting and classifying snippets MS5 Elapsed time for SCHEME2 extracting and classifying snippets: 0.000 seconds Updating events Removing duplicates MS5 Elapsed time for SCHEME2 updating events: 0.001 seconds Concatenating results MS5 Elapsed time for SCHEME2 concatenating results: 0.000 seconds Perorming label mapping MS5 Elapsed time for SCHEME2 label mapping: 0.000 seconds Creating sorting object MS5 Elapsed time for SCHEME2 creating sorting object: 0.000 seconds Error running mountainsort5 Traceback (most recent call last): File "m:/Monkey_Python/SIenv/test_SI.py", line 91, in MS5_sort = si.run_sorter(sorter_name='mountainsort5', recording=recording_path, docker_image=False, File "m:\Monkey_Python\SIenv\lib\site-packages\spikeinterface\sorters\runsorter.py", line 174, in run_sorter return run_sorter_local(**common_kwargs) File "m:\Monkey_Python\SIenv\lib\site-packages\spikeinterface\sorters\runsorter.py", line 224, in run_sorter_local SorterClass.run_from_folder(output_folder, raise_error, verbose) File "m:\Monkey_Python\SIenv\lib\site-packages\spikeinterface\sorters\basesorter.py", line 293, in run_from_folder raise SpikeSortingError( spikeinterface.sorters.utils.misc.SpikeSortingError: Spike sorting error trace: Traceback (most recent call last): File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 613, in _rmtree_unsafe os.unlink(fullname) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\josev\AppData\Local\Temp\tmp4kibvgq8\recording.dat'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 803, in onerror _os.unlink(path) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\josev\AppData\Local\Temp\tmp4kibvgq8\recording.dat'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "m:\Monkey_Python\SIenv\lib\site-packages\spikeinterface\sorters\basesorter.py", line 258, in run_from_folder SorterClass._run_from_folder(sorter_output_folder, sorter_params, verbose) File "m:\Monkey_Python\SIenv\lib\site-packages\spikeinterface\sorters\external\mountainsort5.py", line 203, in _run_from_folder raise ValueError(f"Invalid scheme: {scheme} given. scheme must be one of '1', '2' or '3'") File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 828, in exit self.cleanup() File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 832, in cleanup self._rmtree(self.name) File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 814, in _rmtree _shutil.rmtree(name, onerror=onerror) File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 737, in rmtree return _rmtree_unsafe(path, onerror) File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 615, in _rmtree_unsafe onerror(os.unlink, fullname, sys.exc_info()) File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 806, in onerror cls._rmtree(path) File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 814, in _rmtree _shutil.rmtree(name, onerror=onerror) File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 737, in rmtree return _rmtree_unsafe(path, onerror) File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 596, in _rmtree_unsafe onerror(os.scandir, path, sys.exc_info()) File "C:\Users\josev\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 593, in _rmtree_unsafe with os.scandir(path) as scandir_it: NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\Users\josev\AppData\Local\Temp\tmp4kibvgq8\recording.dat'

Spike sorting failed. You can inspect the runtime trace in M:\Monkey_Project\AlbusTesting\Albus-S1_TwoHands_5FR_NOpostchoice\sortMS5/spikeinterface_log.json.

Impavidpku commented 8 months ago

Same as I met. Do you solve it now?

borrepp commented 8 months ago

Same as I met. Do you solve it now?

Not yet. and I didn't try anything to solve it. But, I was able to run MS5 using the Docker image method.

zm711 commented 7 months ago

We updated the spikeinterface wrapper to try to help deal with some of these issues. If you reinstall spikeinterface from main (we haven't released a version with the fixes yet) we think we will prevent those issues on Windows. (I test on Windows myself and haven't run into this issue locally). Docker is also a potential solution.

borrepp commented 7 months ago

Thanks @zm711

I have been running MS5 from docker and it works fine, but I think it will run a little faster if I run it directly. I will reinstall spikeinterface.

And just to confirm, when you said reinstall from main, did you mean do it like this?:

https://spikeinterface.readthedocs.io/en/latest/installation.html#from-source

Thanks again and I will update you on how it goes.

zm711 commented 7 months ago

Yep that link explains. The only thing is that there is an API change (switching from waveform_extractor to sorting_analyzer), so if you're not ready for that switch then I just opened a PR to back port our MS5 patches into our 0.100.bug-fixes branch but that won't be ready for a little bit at least. Happy to help if you run into issues though! Just open an issue on the spikeinterface repo after the install.

borrepp commented 7 months ago

OK¡ I'm just starting to implement a spikeinterface pipeline, so I will try to use sorting_analyzer instead of waveform_extractor. If I run into any issues I will post it on the spikeinterface repo (should I tag you on that repo? ). If I can't make the switch I will wait for the changes in the PR you opened, and in the meantime, I will keep using MS5 from docker.

Thank you so much and I will update how it goes.

zm711 commented 7 months ago

Everyone is pretty responsive over there so up to you (you're welcome to tag me, but someone will definitely respond even if you don't :) ).

If you're just starting I would definitely recommend using the sorting_analyzer instead since that will be what is used going forward so I would hate for you to build a pipeline and then need to switch stuff over. And the analyzer is better :)

borrepp commented 7 months ago

Great¡

Thanks again for all your help¡¡