- Timestamp:
- 07/15/11 18:52:03 (10 months ago)
- bzr:base-revision:
- michael.fsp@gmail.com-20110714163140-v3qk0357xh8xn2zv
- bzr:committer:
- Michael Pereira <michael.fsp@gmail.com>
- bzr:file-ids:
src/analysis.py 106@400bb3d0-8d2e-0410-a2c0-f692ac833539:trunk%2Fsrc%2Fanalysis.py
src/signals/spikes.py 375@400bb3d0-8d2e-0410-a2c0-f692ac833539:trunk%2Fsrc%2Fsignals%2Fspikes.py- bzr:mapping-version:
- v4
- bzr:merge:
michael.fsp@gmail.com-20110715165055-30cyagkrbyn2q7yv- bzr:repository-uuid:
- 400bb3d0-8d2e-0410-a2c0-f692ac833539
- bzr:revision-id:
- michael.fsp@gmail.com-20110715165126-dd4oub61g4lous2j
- bzr:revno:
- 431
- bzr:revprop:branch-nick:
- trunk
- bzr:root:
- trunk
- bzr:text-revisions:
src/analysis.py michael.fsp@gmail.com-20110715165055-30cyagkrbyn2q7yv
src/signals/spikes.py michael.fsp@gmail.com-20110715165055-30cyagkrbyn2q7yv- bzr:timestamp:
- 2011-07-15 18:51:26.930000067 +0200
- bzr:user-agent:
- bzr2.3.1+bzr-svn1.0.5dev0
- svn:original-date:
- 2011-07-15T16:51:26.930000Z
- Location:
- trunk/src
- Files:
-
- 2 modified
-
analysis.py (modified) (3 diffs)
-
signals/spikes.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/analysis.py
r486 r487 294 294 here as an alternative definition to the cut-off 295 295 frequency of the associated linear filter. 296 time_stamp_resolution - temporal resolution of input and output in SI 297 units. E.g. value 0.001 means 1ms time 298 resolution 296 time_stamp_resolution - temporal resolution of input and output in ms 299 297 direction - Asymmetric kernels have two possible directions. 300 298 The values are -1 or 1, default is 1. The … … 323 321 324 322 To obtain single trial rate function of trial one should use 325 r = norm * numpy.convolve(sua, kernel)323 r = norm * scipy.signal.fftconvolve(sua, kernel) 326 324 To obtain trial-averaged spike train one should use 327 r_avg = norm * numpy.convolve(sua, np.mean(X,1))325 r_avg = norm * scipy.signal.fftconvolve(sua, numpy.mean(X,1)) 328 326 329 327 where X is an array of shape (l,n), where n is the number of trials and 330 328 l the length of each trial 331 332 Note that filter assumes a causal filtering. To represent the resulting 333 firing rate function at center of gravity (acausal) use 334 335 r=r(length(kernel):end); -> discard first length(kernel)-1 336 elements which considered zero entries 337 (border effect) 338 t=((1:length(r))+m_idx)*TimeStampResolution -> in seconds 339 plot(t,r) -> in second time scale 329 330 Note that the output of scipy.signal.fftconvolve needs to trimmed acordingly 331 before being displayed. For more information see the source of the method 332 SpikeTrain.instantaneous_rate() 333 334 See also: 335 SpikeTrain.instantaneous_rate, SpikeList.averaged_instantaneous_rate 340 336 """ 341 337 assert form.upper() in ('BOX','TRI','GAU','EPA','EXP','ALP'), "form must \ … … 343 339 344 340 assert direction in (1,-1), "direction must be either 1 or -1" 341 342 time_stamp_resolution = time_stamp_resolution / 1000. #convert to SI units 345 343 346 344 norm = 1./time_stamp_resolution -
trunk/src/signals/spikes.py
r486 r487 573 573 return hist 574 574 575 def instantaneous_rate(self, resolution, kernel, norm, t_start=None, 576 t_stop=None, acausal=True, m_idx=None, 577 trim=False): 575 def instantaneous_rate(self, resolution, kernel, norm, m_idx=None, 576 t_start=None, t_stop=None, acausal=True, trim=False): 578 577 """ 579 578 Estimate instantaneous firing rate by kernel convolution. … … 603 602 NOTE: if True and an assymetrical kernel is provided 604 603 the output will not be aligned with [t_start, t_stop] 604 605 See also: 606 analysis.make_kernel 605 607 """ 606 608 … … 1038 1040 return self.id_list 1039 1041 elif type(sub_list) == int: 1042 import ipdb; ipdb.set_trace() 1040 1043 return numpy.random.permutation(self.id_list)[0:sub_list] 1041 1044 else: … … 1786 1789 return result 1787 1790 1791 def averaged_instantaneous_rate(self, resolution, kernel, norm, m_idx=None, 1792 t_start=None, t_stop=None, acausal=True, 1793 trim=False): 1794 """ 1795 Estimate the instantaneous firing rate averaged across neurons in the 1796 SpikeList, by kernel convolution. 1797 1798 Inputs: 1799 resolution - time stamp resolution of the spike times (ms). the 1800 same resolution will be assumed for the kernel 1801 kernel - kernel function used to convolve with 1802 norm - normalization factor associated with kernel function 1803 (see analysis.make_kernel for details) 1804 t_start - start time of the interval used to compute the firing 1805 rate 1806 t_stop - end time of the interval used to compute the firing 1807 rate (included) 1808 acausal - if True, acausal filtering is used, i.e., the gravity 1809 center of the filter function is aligned with the 1810 spike to convolve 1811 m_idx - index of the value in the kernel function vector that 1812 corresponds to its gravity center. this parameter is 1813 not mandatory for symmetrical kernels but it is 1814 required when assymmetrical kernels are to be aligned 1815 at their gravity center with the event times 1816 trim - if True, only the 'valid' region of the convolved 1817 signal are returned, i.e., the points where there 1818 isn't complete overlap between kernel and spike train 1819 are discarded 1820 NOTE: if True and an assymetrical kernel is provided 1821 the output will not be aligned with [t_start, t_stop] 1822 1823 See also: 1824 analysis.make_kernel, SpikeTrain.instantaneous_rate 1825 """ 1826 1827 if t_start is None: 1828 t_start = self.t_start 1829 1830 if t_stop is None: 1831 t_stop = self.t_stop 1832 1833 if m_idx is None: 1834 m_idx = kernel.size / 2 1835 1836 spikes_slice = [] 1837 for i in self: 1838 train_slice = i.spike_times[(i.spike_times >= t_start) & ( 1839 i.spike_times <= t_stop)] 1840 spikes_slice += train_slice.tolist() 1841 1842 time_vector = numpy.zeros((t_stop - t_start)/resolution + 1) 1843 1844 for spike in spikes_slice: 1845 index = (spike - t_start) / resolution 1846 time_vector[index] += 1. 1847 1848 avg_time_vector = time_vector / float(self.id_list.size) 1849 1850 r = norm * scipy.signal.fftconvolve(avg_time_vector, kernel, 'full') 1851 1852 if acausal is True: 1853 if trim is False: 1854 r = r[m_idx:-(kernel.size - m_idx)] 1855 t_axis = numpy.linspace(t_start, t_stop, r.size) 1856 return t_axis, r 1857 1858 elif trim is True: 1859 r = r[2 * m_idx:-2*(kernel.size - m_idx)] 1860 t_start = t_start + m_idx * resolution 1861 t_stop = t_stop - ((kernel.size) - m_idx) * resolution 1862 t_axis = numpy.linspace(t_start, t_stop, r.size) 1863 return t_axis, r 1864 1865 if acausal is False: 1866 if trim is False: 1867 r = r[m_idx:-(kernel.size - m_idx)] 1868 t_axis = (numpy.linspace(t_start, t_stop, r.size) + 1869 m_idx * resolution) 1870 return t_axis, r 1871 1872 elif trim is True: 1873 r = r[2 * m_idx:-2*(kernel.size - m_idx)] 1874 t_start = t_start + m_idx * resolution 1875 t_stop = t_stop - ((kernel.size) - m_idx) * resolution 1876 t_axis = (numpy.linspace(t_start, t_stop, r.size) + 1877 m_idx * resolution) 1878 return t_axis, r 1879 1788 1880 def fano_factor(self, time_bin): 1789 1881 """
