| | 906 | def first_spike_time(self): |
|---|
| | 907 | """ |
|---|
| | 908 | Get the time of the first real spike in the SpikeList |
|---|
| | 909 | """ |
|---|
| | 910 | first_spike = self.t_stop |
|---|
| | 911 | is_empty = True |
|---|
| | 912 | for id in self.id_list(): |
|---|
| | 913 | if len(self.spiketrains[id]) > 0: |
|---|
| | 914 | is_empty = False |
|---|
| | 915 | if self.spiketrains[id].spike_times[0] < first_spike: |
|---|
| | 916 | first_spike = self.spiketrains[id].spike_times[0] |
|---|
| | 917 | if is_empty: |
|---|
| | 918 | raise Exception("No spikes can be found in the SpikeList object !") |
|---|
| | 919 | else: |
|---|
| | 920 | return first_spike |
|---|
| | 921 | |
|---|
| | 922 | def last_spike_time(self): |
|---|
| | 923 | """ |
|---|
| | 924 | Get the time of the last real spike in the SpikeList |
|---|
| | 925 | """ |
|---|
| | 926 | last_spike = self.t_start |
|---|
| | 927 | is_empty = True |
|---|
| | 928 | for id in self.id_list(): |
|---|
| | 929 | if len(self.spiketrains[id]) > 0: |
|---|
| | 930 | is_empty = False |
|---|
| | 931 | if self.spiketrains[id].spike_times[-1] > last_spike: |
|---|
| | 932 | last_spike = self.spiketrains[id].spike_times[-1] |
|---|
| | 933 | if is_empty: |
|---|
| | 934 | raise Exception("No spikes can be found in the SpikeList object !") |
|---|
| | 935 | else: |
|---|
| | 936 | return last_spike |
|---|
| | 937 | |
|---|
| | 938 | |
|---|
| | 939 | def select_ids(self, criteria=None): |
|---|
| | 940 | """ |
|---|
| | 941 | Return the list of all the cells in the SpikeList that will match the criteria |
|---|
| | 942 | expressed with the following syntax. |
|---|
| | 943 | |
|---|
| | 944 | Inputs : |
|---|
| | 945 | criteria - a string that can be evaluated on a SpikeTrain object, where the |
|---|
| | 946 | SpikeTrain should be named ``cell''. |
|---|
| | 947 | |
|---|
| | 948 | Exemples: |
|---|
| | 949 | >>> spklist.select_ids("cell.mean_rate() > 0") (all the active cells) |
|---|
| | 950 | >>> spklist.select_ids("cell.mean_rate() == 0") (all the silent cells) |
|---|
| | 951 | >>> spklist.select_ids("len(cell.spiketimes) > 10") |
|---|
| | 952 | >>> spklist.select_ids("mean(cell.isi()) < 1") |
|---|
| | 953 | """ |
|---|
| | 954 | selected_ids = [] |
|---|
| | 955 | for id in self.id_list(): |
|---|
| | 956 | cell = self.spiketrains[id] |
|---|
| | 957 | if eval(criteria): |
|---|
| | 958 | selected_ids.append(id) |
|---|
| | 959 | return selected_ids |
|---|
| | 960 | |
|---|
| | 961 | |
|---|
| 1676 | | #################################################################### |
|---|
| 1677 | | ### TOO SPECIFIC METHOD ? |
|---|
| 1678 | | ### Better documentation |
|---|
| 1679 | | #################################################################### |
|---|
| 1680 | | def pw_corr_pearson(self,edge,bins,number_of_neuron_pairs): |
|---|
| 1681 | | """ |
|---|
| 1682 | | TODO: document/test this function |
|---|
| 1683 | | |
|---|
| 1684 | | """ |
|---|
| 1685 | | #bins = edge[1]-edge[0] |
|---|
| 1686 | | cor = numpy.zeros((number_of_neuron_pairs,)) |
|---|
| 1687 | | [neuron_ids_array, spike_times_array] = self.as_list_id_list_time() |
|---|
| 1688 | | |
|---|
| 1689 | | # Pairwise correlation |
|---|
| 1690 | | neuron_ids_unique = numpy.unique(neuron_ids_array) |
|---|
| 1691 | | |
|---|
| 1692 | | if len(neuron_ids_unique)==0: |
|---|
| 1693 | | return (0,0) |
|---|
| 1694 | | |
|---|
| 1695 | | for count in range(number_of_neuron_pairs): |
|---|
| 1696 | | # draw two neuron radomly out of the neuron_id_unique pool |
|---|
| 1697 | | neuron_1_tmp = neuron_ids_unique[numpy.floor(numpy.random.uniform()*len(neuron_ids_unique))] |
|---|
| 1698 | | neuron_2_tmp = neuron_ids_unique[numpy.floor(numpy.random.uniform()*len(neuron_ids_unique))] |
|---|
| 1699 | | # get the spike_times of the neurons |
|---|
| 1700 | | spike_times_1_tmp = self.spiketrains[neuron_1_tmp].spike_times |
|---|
| 1701 | | spike_times_2_tmp = self.spiketrains[neuron_2_tmp].spike_times |
|---|
| 1702 | | |
|---|
| 1703 | | # hist of the spiketrains |
|---|
| 1704 | | n1_hist = numpy.histogram(spike_times_1_tmp,bins=bins,range=edge) |
|---|
| 1705 | | n2_hist = numpy.histogram(spike_times_2_tmp,bins=bins,range=edge) |
|---|
| | 1743 | def pairwise_pearson_corrcoeff(self, pairs, spklist=None, time_bin=1.): |
|---|
| | 1744 | """ |
|---|
| | 1745 | Function to return the mean and the variance of the pearson correlation coefficient. |
|---|
| | 1746 | For more details, see Kumar et al, .... |
|---|
| | 1747 | |
|---|
| | 1748 | Inputs: |
|---|
| | 1749 | pairs - an int to specify the number of pairs used to estimate the correlation coefficient |
|---|
| | 1750 | time_bin - The time bin used to gather the spikes |
|---|
| | 1751 | """ |
|---|
| | 1752 | if spklist == None: |
|---|
| | 1753 | spklist = self |
|---|
| | 1754 | |
|---|
| | 1755 | if type(pairs) == int: |
|---|
| | 1756 | spk1 = self.id_slice(pairs) |
|---|
| | 1757 | spk2 = spklist.id_slice(pairs) |
|---|
| | 1758 | N = pairs |
|---|
| | 1759 | else: |
|---|
| | 1760 | pairs = numpy.array(pairs) |
|---|
| | 1761 | N = len(pairs[:,0]) |
|---|
| | 1762 | spk1 = self.id_slice(pairs[:,0]) |
|---|
| | 1763 | spk2 = spklist.id_slice(pairs[:,1]) |
|---|
| | 1764 | |
|---|
| | 1765 | cor = numpy.zeros(N, float) |
|---|
| | 1766 | |
|---|
| | 1767 | ## We have to extract only the non silent cells, to avoied problems |
|---|
| | 1768 | non_silent = spk1.select_ids("cell.mean_rate() > 0") |
|---|
| | 1769 | spk1 = spk1.id_slice(non_silent) |
|---|
| | 1770 | non_silent = spk2.select_ids("cell.mean_rate() > 0") |
|---|
| | 1771 | spk2 = spk2.id_slice(non_silent) |
|---|
| | 1772 | |
|---|
| | 1773 | for count in range(N): |
|---|
| | 1774 | # draw two neuron randomly out of the neuron_id_unique pool |
|---|
| | 1775 | neuron_1 = self.id_list()[numpy.floor(numpy.random.uniform()*len(self))] |
|---|
| | 1776 | neuron_2 = self.id_list()[numpy.floor(numpy.random.uniform()*len(self))] |
|---|
| | 1777 | |
|---|
| | 1778 | # get the spike_times of the selected neurons |
|---|
| | 1779 | spk_1 = self.spiketrains[neuron_1] |
|---|
| | 1780 | spk_2 = self.spiketrains[neuron_2] |
|---|
| | 1781 | |
|---|
| | 1782 | # get the histogram of the spiketrains |
|---|
| | 1783 | n1_hist = spk_1.time_histogram(time_bin) |
|---|
| | 1784 | n2_hist = spk_2.time_histogram(time_bin) |
|---|