- Timestamp:
- 06/12/09 09:17:12 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 2 modified
-
io.py (modified) (3 diffs)
-
signals/spikes.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/io.py
r396 r397 27 27 28 28 import os, logging, cPickle, numpy 29 DEFAULT_BUFFER_SIZE = 10000 30 29 DEFAULT_BUFFER_SIZE = -1 31 30 32 31 class FileHandler(object): … … 157 156 def get_data(self, sepchar = "\t", skipchar = "#"): 158 157 """ 159 Load data from a text file and returns a list ofdata158 Load data from a text file and returns an array of the data 160 159 """ 161 160 myfile = open(self.filename, "r", DEFAULT_BUFFER_SIZE) … … 164 163 data = [] 165 164 for line in contents: 166 line = line.strip() 167 if (len(line) != 0): 168 if (line[0] != skipchar): 169 line = line.split(sepchar) 170 id = [int(float(line[-1]))] 171 id.extend(map(float, line[0:-1])) 172 data.append(id) 165 if (line[0] != skipchar): 166 line = line.strip().split(sepchar) 167 id = [int(float(line[-1]))] 168 id.extend(map(float, line[0:-1])) 169 data.append(id) 173 170 logging.debug("Loaded %d lines of data from %s" % (len(data), self)) 174 171 return numpy.array(data, numpy.float32) 172 173 #def get_data(self, sepchar = "\t", skipchar = "#"): 174 #return numpy.loadtxt(self.filename, dtype=numpy.float32) 175 175 176 176 def write(self, object): -
trunk/src/signals/spikes.py
r396 r397 559 559 560 560 if nspk_1 > 0 and nspk_2 > 0: 561 for i in xrange(1, nspk_1+1):562 for j in xrange(1, nspk_2+1):561 for i in xrange(1, nspk_1+1): 562 for j in xrange(1, nspk_2+1): 563 563 scr[i,j] = min(scr[i-1,j]+1,scr[i,j-1]+1) 564 564 scr[i,j] = min(scr[i,j],scr[i-1,j-1]+cost*abs(self.spike_times[i-1]-spktrain.spike_times[j-1])) … … 591 591 if len(idx_spikes) > 0: 592 592 for spike in idx_spikes[1:]: 593 vec_1[previous_spike:spike] = (spike-previous_spike) *dt593 vec_1[previous_spike:spike] = (spike-previous_spike) 594 594 previous_spike = spike 595 595 idx_spikes = numpy.array(spktrain.spike_times/dt,int) … … 597 597 if len(idx_spikes) > 0: 598 598 for spike in idx_spikes[1:]: 599 vec_2[previous_spike:spike] = (spike-previous_spike) *dt599 vec_2[previous_spike:spike] = (spike-previous_spike) 600 600 previous_spike = spike 601 601 idx = numpy.where(vec_1 < vec_2)[0] … … 1547 1547 The 'dimensions' attribute of the SpikeList must be defined 1548 1548 1549 Examples: 1550 >> spklist.id2position(2536) 1551 (25, 35) 1552 1549 1553 See also 1550 1554 activity_map, activity_movie … … 1560 1564 1561 1565 1562 #def position2id(self, id): 1563 #""" 1564 #Return the id of the cell at position (x,y) if the cells are aranged on a 1565 #grid of size dims, as defined in the dims attribute of the SpikeList object 1566 1567 #Inputs: 1568 #id - the id of the cell 1569 1570 #The 'dimensions' attribute of the SpikeList must be defined 1571 1572 #See also 1573 #activity_map, activity_movie 1574 #""" 1575 #if self.dimensions is None: 1576 #raise Exception("Dimensions of the population are not defined ! Set spikelist.dimensions") 1577 #if len(self.dimensions) == 1: 1578 #return id 1579 #if len(self.dimensions) == 2: 1580 #x = id % self.dimensions[0] 1581 #y = numpy.floor(id/self.dimensions[0]) 1582 #return (x,y) 1566 def position2id(self, position): 1567 """ 1568 Return the id of the cell at position (x,y) if the cells are aranged on a 1569 grid of size dims, as defined in the dims attribute of the SpikeList object 1570 1571 Inputs: 1572 position - a tuple with the position of the cell 1573 1574 The 'dimensions' attribute of the SpikeList must be defined and have the same shape 1575 as the position argument 1576 1577 Examples: 1578 >> spklist.position2id((25,35)) 1579 2536 1580 1581 See also 1582 activity_map, activity_movie, id2position 1583 """ 1584 if self.dimensions is None: 1585 raise Exception("Dimensions of the population are not defined ! Set spikelist.dimensions") 1586 assert array(position).shape == self.dimensions.shape, "position does not have the correct shape !" 1587 if len(self.dimensions) == 1: 1588 return position 1589 if len(self.dimensions) == 2: 1590 return position[0]*self.dimensions[0] + position[1] 1583 1591 1584 1592 … … 1835 1843 pairs = pairs_generator.get_pairs(nb_pairs) 1836 1844 N = len(pairs) 1837 1838 1845 distance = 0. 1839 1840 1846 for idx in xrange(N): 1841 1847 idx_1 = pairs[idx,0]
