Changeset 446
- Timestamp:
- 04/12/10 15:37:12 (22 months ago)
- Location:
- trunk/src
- Files:
-
- 7 modified
-
__init__.py (modified) (1 diff)
-
facets/fkbtools.py (modified) (1 diff)
-
io.py (modified) (1 diff)
-
random.py (modified) (2 diffs)
-
signals/spikes.py (modified) (6 diffs)
-
stgen.py (modified) (1 diff)
-
visualization/__init__.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/__init__.py
r442 r446 119 119 import ll.ansistyle 120 120 def colour(col, text): 121 return unicode(ll.ansistyle.Text(col, unicode(text))) 121 try: 122 return unicode(ll.ansistyle.Text(col, unicode(text))) 123 except UnicodeDecodeError, e: 124 raise UnicodeDecodeError("%s. text was %s" % (e, text)) 122 125 except ImportError: 123 126 def colour(col, text): -
trunk/src/facets/fkbtools.py
r298 r446 19 19 if check_dependency('srblib'): 20 20 import srblib 21 else: 22 import urllib as srblib 21 23 22 24 import os, sys, zipfile, tempfile, shutil, subprocess, logging, time, numpy -
trunk/src/io.py
r445 r446 393 393 394 394 395 class PyNNNumpyBinaryFile(FileHandler): 396 397 def __init__(self, filename): 398 FileHandler.__init__(self, filename) 399 self.fileobj = open(self.filename, 'r') 400 401 def read_spikes(self, params): 402 from NeuroTools.signals import spikes 403 contents = numpy.load(self.fileobj) 404 spike_data = contents['data'][:, (1,0)] 405 self.metadata = M = {} 406 for k,v in contents['metadata']: 407 M[k] = eval(v) 408 id_list = range(M['first_id'], M['last_id']) 409 t_stop = params['t_stop'] 410 # really need to check the agreement between file metadata and 411 # params for all metadata items 412 return spikes.SpikeList(spike_data, id_list, t_start=0.0, t_stop=t_stop, 413 dims=M['dimensions']) 414 415 #def read_analogs(self, type, params): 416 # contents = numpy.load(self.fileobj) 417 # values, ids = contents['data'].T # need to check the shape first 418 419 395 420 396 421 class DataHandler(object): -
trunk/src/random.py
r353 r446 20 20 21 21 have_scipy = check_dependency('scipy') 22 if have_scipy:23 import scipy.stats24 22 25 23 … … 95 93 self.dist_name = 'GammaDist' 96 94 97 if have_scipy: 95 if have_scipy: 96 import scipy.stats 98 97 def next(self,n=1): 99 98 return scipy.stats.gamma.rvs(self.params['a'],size=n)*self.params['b'] -
trunk/src/signals/spikes.py
r443 r446 186 186 187 187 188 def merge(self, spiketrain ):188 def merge(self, spiketrain, relative=False): 189 189 """ 190 190 Add the spike times from a spiketrain to the current SpikeTrain … … 192 192 Inputs: 193 193 spiketrain - The SpikeTrain that should be added 194 relative - if True, relative_times() is called on both spiketrains before merging 194 195 195 196 Examples: … … 204 205 500 205 206 """ 207 if relative: 208 self.relative_times() 209 spiketrain.relative_times() 206 210 self.spike_times = numpy.insert(self.spike_times, self.spike_times.searchsorted(spiketrain.spike_times), \ 207 211 spiketrain.spike_times) … … 464 468 def time_slice(self, t_start, t_stop): 465 469 """ 466 Return a new SpikeTrain obtained by slicing between t_start and t_stop. The new 467 t_start and t_stop values of the returned SpikeTrain are the one given as arguments 470 Return a new SpikeTrain obtained by slicing between t_start and t_stop, 471 where t_start and t_stop may either be single values or sequences of 472 start and stop times. 468 473 469 474 Inputs: … … 477 482 >> spk.t_stop 478 483 100 479 """ 480 spikes = numpy.extract((self.spike_times >= t_start) & (self.spike_times <= t_stop), self.spike_times) 484 >>> spk = spktrain.time_slice([20,70], [40,90]) 485 >>> spk.t_start 486 20 487 >>> spk.t_stop 488 90 489 >>> len(spk.time_slice(41, 69)) 490 0 491 """ 492 if hasattr(t_start, '__len__'): 493 if len(t_start) != len(t_stop): 494 raise ValueError("t_start has %d values and t_stop %d. They must be of the same length." % (len(t_start), len(t_stop))) 495 mask = False 496 for t0,t1 in zip(t_start, t_stop): 497 mask = mask | ((self.spike_times >= t0) & (self.spike_times <= t1)) 498 t_start = t_start[0] 499 t_stop = t_stop[-1] 500 else: 501 mask = (self.spike_times >= t_start) & (self.spike_times <= t_stop) 502 spikes = numpy.extract(mask, self.spike_times) 481 503 return SpikeTrain(spikes, t_start, t_stop) 482 504 … … 536 558 537 559 Note that the SpikeTrain object itself is modified, t_start 538 is sub stracted tospike_times, t_start and t_stop560 is subtracted from spike_times, t_start and t_stop 539 561 """ 540 562 if self.t_start != 0: -
trunk/src/stgen.py
r438 r446 243 243 def inh_poisson_generator(self, rate, t, t_stop, array=False): 244 244 """ 245 Returns a Spike Listwhose spikes are a realization of an inhomogeneous245 Returns a SpikeTrain whose spikes are a realization of an inhomogeneous 246 246 poisson process (dynamic rate). The implementation uses the thinning 247 247 method, as presented in the references. -
trunk/src/visualization/__init__.py
r442 r446 143 143 h,w = spk.dimensions 144 144 id_offset = min(spk.id_list()) 145 xarr,yarr = spk.id2position(self.spikelist.id_list() - id_offset) 145 146 while (self.i < self.max_i) and (self.time[self.i] < self.t_start + self.frame_duration): 146 xy = spk.id2position(self.ids[self.i] - id_offset) 147 activity_map[xy2ij(xy, h)] += 1 147 id = self.ids[self.i] - id_offset 148 x = xarr[id] 149 y = yarr[id] 150 #xy = spk.id2position(self.ids[self.i] - id_offset) 151 #assert xy == (x,y), "%s != %s" % (xy, str((x,y))) 152 activity_map[xy2ij((x,y), h)] += 1 148 153 self.i += 1 149 154 self.t_start += self.frame_duration
