- Timestamp:
- 09/25/09 14:02:04 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 3 modified
-
io.py (modified) (1 diff)
-
signals/spikes.py (modified) (8 diffs)
-
visualization/__init__.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/io.py
r415 r436 147 147 if not ('id_list' in params) or (params['id_list'] is None): 148 148 if ('first_id' in self.metadata) and ('last_id' in self.metadata): 149 logging.debug("id_list is infered from the file header")150 149 params['id_list'] = range(int(self.metadata['first_id']), int(self.metadata['last_id'])+1) 150 logging.debug("id_list (%d...%d) is infered from the file header" % (int(self.metadata['first_id']), int(self.metadata['last_id'])+1)) 151 151 else: 152 152 raise Exception("id_list can not be infered while reading %s" %self.filename) -
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) -
trunk/src/visualization/__init__.py
r416 r436 103 103 return self.t, numpy.sin(self.t + self.phase) 104 104 105 def xy2ij(coordinates ):105 def xy2ij(coordinates, height): 106 106 """ 107 107 Generally, we use (x,y) coordinates, but since arrays use matrix coordinates, … … 109 109 """ 110 110 assert len(coordinates) == 2 111 return (coordinates[1], coordinates[0]) 111 x,y = coordinates 112 j = x 113 i = height - 1 - y 114 return (i,j) 112 115 113 116 class ActivityMap(object): … … 122 125 raise Exception("Dimensions of the population are not defined ! Set spikelist.dims") 123 126 124 self.time, self. pos = self.spikelist.convert("times, ids")127 self.time, self.ids = self.spikelist.convert("times, ids") 125 128 # We sort the spikes to allow faster process later 126 129 sort_idx = self.time.ravel().argsort(kind="quicksort") 127 130 self.time = self.time[sort_idx] 128 self. pos = self.pos[sort_idx]129 self.i dx= 0130 self.max_i dx= len(self.time)-1131 self.ids = self.ids[sort_idx] 132 self.i = 0 133 self.max_i = len(self.time)-1 131 134 self.t_start = 0 132 135 133 136 def next_frame(self): 134 137 spk = self.spikelist 135 activity_map = numpy.zeros(xy2ij(spk.dimensions)) 136 137 while ((self.idx < self.max_idx) and (self.time[self.idx] < self.t_start + self.frame_duration)): 138 addr = spk.id2position(self.pos[self.idx]) 139 activity_map[xy2ij(addr)] += 1 140 self.idx += 1 138 activity_map = numpy.zeros(spk.dimensions) 139 h,w = spk.dimensions 140 id_offset = min(spk.id_list()) 141 while (self.i < self.max_i) and (self.time[self.i] < self.t_start + self.frame_duration): 142 xy = spk.id2position(self.ids[self.i] - id_offset) 143 activity_map[xy2ij(xy, h)] += 1 144 self.i += 1 141 145 self.t_start += self.frame_duration 142 #logging.debug("next_frame: i dx=%d, t_start=%g, max_idx=%d, time[idx]=%g" % (self.idx, self.t_start, self.max_idx, self.time[self.idx]))146 #logging.debug("next_frame: i=%d, t_start=%g, max_i=%d, time[i]=%g" % (self.i, self.t_start, self.max_i, self.time[self.i])) 143 147 activity_map *= 1000.0/self.frame_duration # convert to spikes/second 144 148 return [activity_map]
