Changeset 436 for trunk/src/signals/spikes.py
- Timestamp:
- 09/25/09 14:02:04 (3 years ago)
- Files:
-
- 1 modified
-
trunk/src/signals/spikes.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/signals/spikes.py
r416 r436 1663 1663 1664 1664 1665 def id2position(self, id ):1665 def id2position(self, id, offset=0): 1666 1666 """ 1667 1667 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. 1669 1673 1670 1674 Inputs: … … 1672 1676 1673 1677 The 'dimensions' attribute of the SpikeList must be defined 1674 1675 Examples:1676 >> spklist.id2position(2536)1677 (25, 35)1678 1678 1679 1679 See also … … 1683 1683 raise Exception("Dimensions of the population are not defined ! Set spikelist.dimensions") 1684 1684 if len(self.dimensions) == 1: 1685 return id 1685 return id-offset 1686 1686 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])) 1689 1689 return (x,y) 1690 1690 1691 1691 1692 def position2id(self, position ):1692 def position2id(self, position, offset=0): 1693 1693 """ 1694 1694 Return the id of the cell at position (x,y) if the cells are aranged on a … … 1701 1701 as the position argument 1702 1702 1703 Examples:1704 >> spklist.position2id((25,35))1705 25361706 1707 1703 See also 1708 1704 activity_map, activity_movie, id2position … … 1710 1706 if self.dimensions is None: 1711 1707 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 !" 1713 1709 if len(self.dimensions) == 1: 1714 return position 1710 return position+offset 1715 1711 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 1717 1713 1718 1714 … … 1728 1724 float_positions - None by default, meaning that the dimensions attribute 1729 1725 of the SpikeList is used to arange the ids on a 2D grid. 1730 Otherwise, if the cells have flo tting positions,1726 Otherwise, if the cells have floating positions, 1731 1727 float_positions should be an array of size 1732 1728 (2, nb_cells) with the x (first line) and y (second line) … … 1763 1759 activity_map = numpy.zeros(self.dimensions, float) 1764 1760 rates = spklist.mean_rates() 1761 id_offset = min(self.id_list()) 1765 1762 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] 1768 1766 if not subplot or not HAVE_PYLAB or not HAVE_MATPLOTLIB: 1769 1767 return activity_map … … 2229 2227 while (t_start < t_stop): 2230 2228 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 2234 2233 idx += 1 2235 2234 im.set_array(activity_map)
