예제 #1
0
    def _cluster_spike_waveforms_by_freq(self, plot_hist = False):
        """
        Clusters the found spikes into simple and complex, using a gmm_nc component GMM
        It uses the maximum power in the lower region of the frequency spectrum of the 
        spike waveforms
        """
        max_powers = self._find_max_powers()[0]
        gmm = GaussianMixture(self.cs_num_gmm_components, covariance_type = self.cs_cov_type, random_state=0).fit(max_powers.reshape(-1,1))
        cluster_labels = gmm.predict(max_powers.reshape(-1,1))
        cluster_labels = cluster_labels.reshape(max_powers.shape)

        cs_indices = self.get_spike_indices()[cluster_labels == np.argmax(gmm.means_)]
        if plot_hist:
            plt.figure()
            # uniq = np.unique(ss.d_voltage[prang] , return_counts=True)
            x = np.arange(np.min(max_powers), np.max(max_powers), 1)
            if self.cs_cov_type == 'tied':
                gauss_mixt = np.array([p * norm.pdf(x, mu, np.sqrt(gmm.covariances_.flatten())) 
                    for mu, p in zip(gmm.means_.flatten(), gmm.weights_)])
            else:
                gauss_mixt = np.array([p * norm.pdf(x, mu, sd) 
                    for mu, sd, p in zip(gmm.means_.flatten(), np.sqrt(gmm.covariances_.flatten()), gmm.weights_)])
                        
            colors = plt.cm.jet(np.linspace(0,1,len(gauss_mixt)))

            # plot histogram overlaid by gmm gaussians
            for i, gmixt in enumerate(gauss_mixt):
                    plt.plot(x, gmixt, label = 'Gaussian '+str(i), color = colors[i])

                    plt.hist(max_powers.reshape(-1,1),bins=256,density=True, color='gray')
                    axvlines(plt.gca(), gmm.means_)
                    plt.show()
        self.cs_indices = cs_indices
예제 #2
0
 def plot_spike_peaks(self, use_filtered=False, figsize=(21, 5)):
     """
     Plots the voltage signal, overlaid by spike peak times,
     overlaid by lines indicating the window around the spike peaks
     """
     if use_filtered:
         plt.figure(figsize=figsize)
         plt.plot(self.voltage_filtered)
         plt.plot(self.spike_indices,
                  self.voltage_filtered[self.spike_indices], '.r')
         axvlines(plt.gca(),
                  self.spike_indices +
                  int(np.round(self.post_window / self.dt)),
                  color='g')
         axvlines(plt.gca(),
                  self.spike_indices -
                  int(np.round(self.pre_window / self.dt)),
                  color='m')
     else:
         plt.figure(figsize=figsize)
         plt.plot(self.voltage)
         plt.plot(self.spike_indices, self.voltage[self.spike_indices],
                  '.r')
         axvlines(plt.gca(),
                  self.spike_indices +
                  int(np.round(self.post_window / self.dt)),
                  color='g')
         axvlines(plt.gca(),
                  self.spike_indices -
                  int(np.round(self.pre_window / self.dt)),
                  color='m')