Changeset 397 for trunk

Show
Ignore:
Timestamp:
06/12/09 09:17:12 (3 years ago)
Author:
pierre
Message:

Minor modifications

Location:
trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/io.py

    r396 r397  
    2727 
    2828import os, logging, cPickle, numpy 
    29 DEFAULT_BUFFER_SIZE = 10000 
    30  
     29DEFAULT_BUFFER_SIZE = -1 
    3130 
    3231class FileHandler(object): 
     
    157156    def get_data(self, sepchar = "\t", skipchar = "#"): 
    158157        """ 
    159         Load data from a text file and returns a list of data 
     158        Load data from a text file and returns an array of the data 
    160159        """ 
    161160        myfile = open(self.filename, "r", DEFAULT_BUFFER_SIZE) 
     
    164163        data = [] 
    165164        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) 
    173170        logging.debug("Loaded %d lines of data from %s" % (len(data), self)) 
    174171        return numpy.array(data, numpy.float32) 
     172     
     173    #def get_data(self, sepchar = "\t", skipchar = "#"): 
     174        #return numpy.loadtxt(self.filename, dtype=numpy.float32) 
    175175 
    176176    def write(self, object): 
  • trunk/src/signals/spikes.py

    r396 r397  
    559559             
    560560        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): 
    563563                    scr[i,j] = min(scr[i-1,j]+1,scr[i,j-1]+1) 
    564564                    scr[i,j] = min(scr[i,j],scr[i-1,j-1]+cost*abs(self.spike_times[i-1]-spktrain.spike_times[j-1])) 
     
    591591        if len(idx_spikes) > 0: 
    592592            for spike in idx_spikes[1:]: 
    593                 vec_1[previous_spike:spike] = (spike-previous_spike)*dt 
     593                vec_1[previous_spike:spike] = (spike-previous_spike) 
    594594                previous_spike = spike 
    595595        idx_spikes     = numpy.array(spktrain.spike_times/dt,int) 
     
    597597        if len(idx_spikes) > 0: 
    598598            for spike in idx_spikes[1:]: 
    599                 vec_2[previous_spike:spike] = (spike-previous_spike)*dt 
     599                vec_2[previous_spike:spike] = (spike-previous_spike) 
    600600                previous_spike = spike 
    601601        idx = numpy.where(vec_1 < vec_2)[0] 
     
    15471547        The 'dimensions' attribute of the SpikeList must be defined 
    15481548         
     1549        Examples: 
     1550            >> spklist.id2position(2536) 
     1551                (25, 35) 
     1552         
    15491553        See also 
    15501554            activity_map, activity_movie 
     
    15601564 
    15611565 
    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] 
    15831591 
    15841592 
     
    18351843        pairs = pairs_generator.get_pairs(nb_pairs) 
    18361844        N     = len(pairs) 
    1837          
    18381845        distance   = 0. 
    1839          
    18401846        for idx in xrange(N): 
    18411847            idx_1 = pairs[idx,0]