Show
Ignore:
Timestamp:
09/25/09 14:02:04 (3 years ago)
Author:
apdavison
Message:

Modified the mapping of cell id to image position for plotting activity maps/movies.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/signals/spikes.py

    r416 r436  
    16631663 
    16641664     
    1665     def id2position(self, id): 
     1665    def id2position(self, id, offset=0): 
    16661666        """ 
    16671667        Return a position (x,y) from an id if the cells are aranged on a 
    1668         grid of size dims, as defined in the dims attribute of the SpikeList object 
     1668        grid of size dims, as defined in the dims attribute of the SpikeList object. 
     1669        This assumes that cells are ordered from left to right, top to bottom, 
     1670        and that dims specifies (height, width), i.e. if dims = (10,12), this is 
     1671        an array with 10 rows and 12 columns, and hence has width 12 units and 
     1672        height 10 units. 
    16691673         
    16701674        Inputs: 
     
    16721676         
    16731677        The 'dimensions' attribute of the SpikeList must be defined 
    1674          
    1675         Examples: 
    1676             >> spklist.id2position(2536) 
    1677                 (25, 35) 
    16781678         
    16791679        See also 
     
    16831683            raise Exception("Dimensions of the population are not defined ! Set spikelist.dimensions") 
    16841684        if len(self.dimensions) == 1: 
    1685             return id 
     1685            return id-offset 
    16861686        if len(self.dimensions) == 2: 
    1687             x = id % self.dimensions[0] 
    1688             y = numpy.floor(id/self.dimensions[0]) 
     1687            x = (id-offset) % self.dimensions[1] 
     1688            y = self.dimensions[0] - 1 - int(numpy.floor((id-offset)/self.dimensions[1])) 
    16891689            return (x,y) 
    16901690 
    16911691 
    1692     def position2id(self, position): 
     1692    def position2id(self, position, offset=0): 
    16931693        """ 
    16941694        Return the id of the cell at position (x,y) if the cells are aranged on a 
     
    17011701        as the position argument 
    17021702         
    1703         Examples: 
    1704             >> spklist.position2id((25,35)) 
    1705                 2536 
    1706          
    17071703        See also 
    17081704            activity_map, activity_movie, id2position 
     
    17101706        if self.dimensions is None: 
    17111707            raise Exception("Dimensions of the population are not defined ! Set spikelist.dimensions") 
    1712         assert array(position).shape == self.dimensions.shape, "position does not have the correct shape !" 
     1708        assert len(position) == len(tuple(self.dimensions)), "position does not have the correct shape !" 
    17131709        if len(self.dimensions) == 1: 
    1714             return position 
     1710            return position+offset 
    17151711        if len(self.dimensions) == 2: 
    1716             return position[0]*self.dimensions[0] + position[1] 
     1712            return (self.dimensions[0] - 1 - position[1])*self.dimensions[1] + position[0] + offset 
    17171713 
    17181714 
     
    17281724            float_positions - None by default, meaning that the dimensions attribute  
    17291725                              of the SpikeList is used to arange the ids on a 2D grid.  
    1730                               Otherwise, if the cells have flotting positions,  
     1726                              Otherwise, if the cells have floating positions,  
    17311727                              float_positions should be an array of size 
    17321728                              (2, nb_cells) with the x (first line) and y (second line)  
     
    17631759            activity_map = numpy.zeros(self.dimensions, float) 
    17641760            rates        = spklist.mean_rates() 
     1761            id_offset = min(self.id_list()) 
    17651762            for count, id in enumerate(spklist.id_list()): 
    1766                 position = spklist.id2position(id) 
    1767                 activity_map[position] = rates[count] 
     1763                x,y = spklist.id2position(id, id_offset) 
     1764                j,i = x, self.dimensions[0] - 1 -y 
     1765                activity_map[i,j] = rates[count] 
    17681766            if not subplot or not HAVE_PYLAB or not HAVE_MATPLOTLIB: 
    17691767                return activity_map 
     
    22292227                while (t_start < t_stop): 
    22302228                    activity_map = numpy.zeros(spk.dimensions) 
    2231                     while ((time[idx] < t_start + time_bin) and (idx < max_idx)): 
    2232                         addr = spk.id2position(pos[idx]) 
    2233                         activity_map[addr] += 1 
     2229                    while ((time[idx] < t_start + time_bin) and (idx < max_idx)):                         
     2230                        x,y = spk.id2position(pos[idx]) 
     2231                        j,i = x, self.dimensions[0] - 1 -y 
     2232                        activity_map[i,j] += 1 
    22342233                        idx += 1 
    22352234                    im.set_array(activity_map)