In [1]:
import pandas as pd
import klustaviewa as kv
In [2]:
%pylab
We specify the path to any file of the data set (.xml, .clu.x, etc.).
In [3]:
filename = 'data/test.xml'
Now we create a loader object with the filename as an argument. It offers convenient methods to access parts of the data. This line might take a while as all files are fully loaded in memory.
In [4]:
loader = kv.KlustersLoader(filename=filename)
In [5]:
# These are spike indices.
spikes = [10, 20, 30]
# We need to specify explicitely spikes as a keyword argument.
loader.select(spikes=spikes)
Now we can access the different data sets.
In [6]:
clusters = loader.get_clusters() # shape=Nspikes
waveforms = loader.get_waveforms() # shape=Nspikes x Nsamples n Channels
features = loader.get_features() # shape=Nspikes x Nfeatures
masks = loader.get_masks() # shape=Nspikes x Nchannels
spiketimes = loader.get_spiketimes() # shape=Nspikes
In [7]:
waveforms_array = kv.get_array(waveforms)
# Plot the waveforms of the first selected spike (spike #10).
plot(waveforms_array[0,...]);
In [8]:
# Showing the times of the selected spikes. The spike index is shown along with the spike time.
print(spiketimes)
In [9]:
# We need to specify explicitely clusters as a keyword argument.
loader.select(clusters=range(2, 12))
# Now we can acccess the data.
clusters = loader.get_clusters() # shape=Nspikes
waveforms = loader.get_waveforms() # shape=Nspikes x Nsamples n Channels
features = loader.get_features() # shape=Nspikes x Nfeatures
masks = loader.get_masks() # shape=Nspikes x Nchannels
masks_full = loader.get_masks(full=True) # shape=Nspikes x Nfeatures
spiketimes = loader.get_spiketimes() # shape=Nspikes
In [10]:
print(clusters)
Here is how to create a new Pandas DataFrame with the spike times, the clusters.
In [11]:
frame = pd.DataFrame(dict(clusters=clusters, spiketimes=spiketimes))
We can display nicely the head of the frame.
In [12]:
frame.head()
Out[12]:
To plot the spike times:
In [13]:
scatter(kv.get_array(spiketimes), kv.get_array(features)[:,0])
xlim(0, loader.get_duration());
To find out more possibilities with the loader, use tab completion with loader.get_<TAB>.
In [14]:
# ncorrbins is the number of bins in the correlograms, corrbin is the bin size in seconds.
correlograms = kv.compute_correlograms(spiketimes, clusters, ncorrbins=100, corrbin=.001)
In [15]:
bar(arange(100), correlograms[2, 2], ec='none');
In [16]:
correlations = kv.compute_correlations(kv.get_array(features), kv.get_array(clusters), kv.get_array(masks_full))
matrix = kv.normalize(kv.get_similarity_matrix(correlations))
In [17]:
imshow(matrix, interpolation='none')
Out[17]:
In [17]: