csn-le / wave_clus

A fast and unsupervised algorithm for spike detection and sorting using wavelets and super-paramagnetic clustering
127 stars 66 forks source link

Wrong Spike time (ms) #143

Closed kiks9012 closed 5 years ago

kiks9012 commented 5 years ago

Hello,

When i try to align the time_stamps from cluster_class output file with my original data, the times_stamps do not match with the actual spikes. This issue was already reported by https://github.com/csn-le/wave_clus/issues/16 and https://github.com/csn-le/wave_clus/issues/82.

I recorded my data with open-ephys and used their converter to save the data for 1 tetrode into a .mat matrix. I loaded this .mat into wave_clus. I am sure the sr parameter was correct. However, when i convert the time_stamps in ms to samples and try to align them with my .mat data they do not match (and i am sure i am doing the correct conversion: samples = (ms/1000)*sr).

Additionally, even if i change the sample frequency (to a random frequency) in the par.sr (through set paramater in the GUI) the wave_clus output time_stamps in ms are always the same, regardless the sr, which is really strange.

How can i solve this?

Thank you for your help.

ferchaure commented 5 years ago

I recorded my data with open-ephys and used their converter to save the data for 1 tetrode into a .mat matrix.

Just to be in the same page: you have tetrode data (continuous signal or spikes?), then you make a file with a matrix (4 files with one channel in each file, etc?) and finally you convent the time_stamps in ms to samples (exactly how do you do that?)

Additionally, even if i change the sample frequency (to a random frequency) in the par.sr (through set paramater in the GUI) the wave_clus output time_stamps in ms are always the same, regardless the sr, which is really strange.

That is ok, if the data file have a sr variable that set the sr without looking the parameters file.

ferchaure commented 5 years ago

any updates?

kiks9012 commented 5 years ago

Sorry for the delay in responding.

Just to clarify. I have a .mat file which is 4 channels (the 4 wires in 1 tetrode) in 1 file (size: 4xdatapoints). This is the file I load into Waveclus. After the spike detection and clustering, when I look at the timestamps of the detected/clustered spikes (in the times_[filename].mat file) they do not match with the actual spikes in the original signal in the .mat file (and the way I'm converting the timestamps to samples is as posted above: samples = (timestamps-in-ms / 1000)*sampling frequency.

Additionally, if I look at the plot on the Waveclus GUI, the time is already wrong there (i.e., the times of the data in ms in the plot do not match the times of the original file; and I can know this just by looking for example at the first spike that occurs on the original data and on the GUI plot).

You are right that if I have an sr file in the folder Waveclus does not use the info from the par.sr. The problem is that even if I don't have an sr file in the folder and I change sr in the parameters; the times (in ms) both of the plot and the timestamps of the detected spikes do not change!

And I found an additional issue. When I set the par.tmax to 'all' only a small fraction of the signal is actually processed. If I want to have the full signal analyzed I have to set it to a value - which, strangely, also does not match the full time of my signal (in seconds).

There seems to be some kind of time distortion happening here, which I have no idea where it may be coming from, since I load my full/original signal in the .mat format.

How can we troubleshoot this?

ferchaure commented 5 years ago

Just to clarify. I have a .mat file which is 4 channels (the 4 wires in 1 tetrode) in 1 file (size: 4xdatapoints).

And I found an additional issue. When I set the par.tmax to 'all' only a small fraction of the signal is actually processed. If I want to have the full signal analyzed I have to set it to a value - which, strangely, also does not match the full time of my signal (in seconds).

That is probably the issue, check the way to use polytrodes in wave_clus here

You are right that if I have an sr file in the folder Waveclus does not use the info from the par.sr. The problem is that even if I don't have an sr file in the folder and I change sr in the parameters; the times (in ms) both of the plot and the timestamps of the detected spikes do not change!

"I have an sr file in the folder Waveclus" I guess that it means "sr variable in the file". Again, that is generate by the wrong way to load polytrodes.

kiks9012 commented 5 years ago

Thank you for the reply. I tried to use polytrodes as explained in https://github.com/csn-le/wave_clus/wiki/Polytrodes. I created four .mat files, each with its own channel (1xdata), as well as the polytrode1.txt file with the name of the channels. However when i tried to execute the batch file Get_spikes_pol(1) the following error message appered:

Undefined function or variable 'true1'.

Error in Get_spikes_pol (line 55) if run_parfor == true1

How can i solve this?

ferchaure commented 5 years ago

That is a bug, I don't know if that is from an older version or a local change, but to be sure just download the last version from: wave_clus master.zip

kiks9012 commented 5 years ago

Hello, i downloaded the latest version and a different error message apperead:

Error using Get_spikes_pol>get_spikes_pol_single (line 107) The file my_channel_4.mat doesn't have raw data

Error in Get_spikes_pol (line 62) get_spikes_pol_single(polytrodes(j), par_input);

However, i know that the my_channel_4.mat file contains a 1xdata array. How can i solve this?

ferchaure commented 5 years ago

The variable inside that channel is called 'data'? that is the only channel with issues? (can you load the polytrodes if you remove it from polytrode1.txt)

kiks9012 commented 5 years ago

I changed the variable name inside every channel to 'data' and the toolbox is now loading the polytrodes correctly. Thank you very much for your help!