def make_stimulus(self, stimulus='tone', cf=16000., f0=16000., simulator=None, rundur=0.2, pipdur=0.05, dbspl=50., fmod=100., dmod=0.): self.stimulus = stimulus self.run_duration = rundur # in seconds self.pip_duration = pipdur # in seconds self.pip_start = [0.1] # in seconds self.Fs = 100e3 # in Hz self.f0 = f0 # stimulus in Hz self.cf = cf # SGCs in Hz self.fMod = fmod # mod freq, Hz self.dMod = dmod # % mod depth, Hz self.dbspl = dbspl self.simulator = simulator self.sr = 1 # set SR group if self.stimulus == 'SAM': self.stim = sound.SAMTone(rate=self.Fs, duration=self.run_duration, f0=self.f0, fmod=self.fMod, dmod=self.dMod, dbspl=self.dbspl, ramp_duration=2.5e-3, pip_duration=self.pip_duration, pip_start=self.pip_start) if self.stimulus == 'tone': self.stim = sound.TonePip(rate=self.Fs, duration=self.run_duration, f0=self.f0, dbspl=self.dbspl, ramp_duration=2.5e-3, pip_duration=self.pip_duration, pip_start=self.pip_start) if self.stimulus == 'clicks': self.click_rate = 0.020 # msec self.stim = sound.ClickTrain(rate=self.Fs, duration=self.run_duration, f0=self.f0, dbspl=self.dbspl, click_start=0.010, click_duration=100.e-6, click_interval=self.click_rate, nclicks=int((self.run_duration-0.01)/self.click_rate), ramp_duration=2.5e-3)
def run(self, temp=34.0, dt=0.025, seed=575982035, reps=10, stimulus='tone', simulator='cochlea'): assert stimulus in ['tone', 'SAM', 'clicks'] # cases available assert self.cell in ['bushy', 'tstellate', 'octopus', 'dstellate'] self.nrep = reps self.stimulus = stimulus self.run_duration = 0.20 # in seconds self.pip_duration = 0.05 # in seconds self.pip_start = [0.1] # in seconds self.Fs = 100e3 # in Hz self.f0 = 4000. # stimulus in Hz self.cf = 4000. # SGCs in Hz self.fMod = 100. # mod freq, Hz self.dMod = 0. # % mod depth, Hz self.dbspl = 50. self.simulator = simulator self.sr = 1 # set SR group if self.stimulus == 'SAM': self.stim = sound.SAMTone(rate=self.Fs, duration=self.run_duration, f0=self.f0, fmod=self.fMod, dmod=self.dMod, dbspl=self.dbspl, ramp_duration=2.5e-3, pip_duration=self.pip_duration, pip_start=self.pip_start) if self.stimulus == 'tone': self.f0 = 4000. self.cf = 4000. self.stim = sound.TonePip(rate=self.Fs, duration=self.run_duration, f0=self.f0, dbspl=self.dbspl, ramp_duration=2.5e-3, pip_duration=self.pip_duration, pip_start=self.pip_start) if self.stimulus == 'clicks': self.click_rate = 0.020 # msec self.stim = sound.ClickTrain( rate=self.Fs, duration=self.run_duration, f0=self.f0, dbspl=self.dbspl, click_start=0.010, click_duration=100.e-6, click_interval=self.click_rate, nclicks=int((self.run_duration - 0.01) / self.click_rate), ramp_duration=2.5e-3) n_sgc = data.get('convergence', species=species, post_type=self.cell, pre_type='sgc')[0] self.n_sgc = int(np.round(n_sgc)) # for simple synapses, need this value: self.AMPA_gmax = data.get( 'sgc_synapse', species=species, post_type=self.cell, field='AMPA_gmax')[0] / 1e3 # convert nS to uS for NEURON self.vms = [None for n in range(self.nrep)] self.synapses = [None for n in range(self.nrep)] self.xmtrs = [None for n in range(self.nrep)] self.pre_cells = [None for n in range(self.nrep)] self.time = [None for n in range(self.nrep)] info = { 'n_sgc': self.n_sgc, 'gmax': self.AMPA_gmax, 'stim': self.stim, 'simulator': self.simulator, 'cf': self.cf, 'sr': self.sr, 'seed': seed, 'run_duration': self.run_duration, 'temp': temp, 'dt': dt, 'init': custom_init } if not self.parallelize: for nr in range(self.nrep): info['seed'] = seed + 3 * self.n_sgc * nr res = RunTrial(self.cell, info) # res contains: {'time': time, 'vm': Vm, 'xmtr': xmtr, 'pre_cells': pre_cells, 'post_cell': post_cell} self.pre_cells[nr] = res['pre_cells'] self.time[nr] = res['time'] self.xmtr = {k: v.to_python() for k, v in res['xmtr'].items()} self.vms[nr] = res['vm'] self.synapses[nr] = res['synapses'] self.xmtrs[nr] = self.xmtr if self.parallelize: ### Use parallelize with multiple workers tasks = range(len(self.nrep)) results3 = results[:] start = time.time() # with mp.Parallelize(enumerate(tasks), results=results, progressDialog='processing in parallel..') as tasker: with mp.Parallelize(enumerate(tasks), results=results) as tasker: for i, x in tasker: tot = 0 for j in xrange(size): tot += j * x tasker.results[i] = tot print("\nParallel time, %d workers: %0.2f" % (mp.Parallelize.suggestedWorkerCount(), time.time() - start)) print("Results match serial: %s" % str(results3 == results))
def run(self, temp=34.0, dt=0.025, seed=575982035, stimulus='tone', species='mouse'): assert stimulus in ['tone', 'SAM', 'clicks'] # cases available if self.cell == 'bushy': postCell = cells.Bushy.create(species=species) elif self.cell == 'tstellate': postCell = cells.TStellate.create(species=species) elif self.cell == 'octopus': postCell = cells.Octopus.create(species=species) elif self.cell == 'dstellate': postCell = cells.DStellate.create(species=species) else: raise ValueError('cell %s is not yet implemented for phaselocking' % self.cell) self.post_cell = postCell self.stimulus = stimulus self.run_duration = 1. # in seconds self.pip_duration = 0.8 # in seconds self.pip_start = [0.02] # in seconds self.Fs = 100e3 # in Hz self.f0 = 4000. # stimulus in Hz self.cf = 4000. # SGCs in Hz self.fMod = 100. # mod freq, Hz self.dMod = 50. # % mod depth, Hz self.dbspl = 60. if self.stimulus == 'SAM': self.stim = sound.SAMTone(rate=self.Fs, duration=self.run_duration, f0=self.f0, fmod=self.fMod, dmod=self.dMod, dbspl=self.dbspl, ramp_duration=2.5e-3, pip_duration=self.pip_duration, pip_start=self.pip_start) if self.stimulus == 'tone': self.f0 = 1000. self.cf = 1000. self.stim = sound.TonePip(rate=self.Fs, duration=self.run_duration, f0=self.f0, dbspl=self.dbspl, ramp_duration=2.5e-3, pip_duration=self.pip_duration, pip_start=self.pip_start) if self.stimulus == 'clicks': self.click_rate = 0.020 # msec self.stim = sound.ClickTrain(rate=self.Fs, duration=self.run_duration, f0=self.f0, dbspl=self.dbspl, click_start=0.010, click_duration=100.e-6, click_interval=self.click_rate, nclicks=int((self.run_duration-0.01)/self.click_rate), ramp_duration=2.5e-3) n_sgc = data.get('convergence', species=species, post_type=postCell.type, pre_type='sgc')[0] self.n_sgc = int(np.round(n_sgc)) self.pre_cells = [] self.synapses = [] j = 0 for k in range(self.n_sgc): seed = seed + k preCell = cells.DummySGC(cf=self.cf, sr=2) synapse = preCell.connect(postCell) for i in range(synapse.terminal.n_rzones): self['xmtr%03d'%j] = synapse.terminal.relsite._ref_XMTR[i] j = j + 1 synapse.terminal.relsite.Dep_Flag = False preCell.set_sound_stim(self.stim, seed=seed) self.pre_cells.append(preCell) self.synapses.append(synapse) self['vm'] = postCell.soma(0.5)._ref_v #self['prevm'] = preCell.soma(0.5)._ref_v self['t'] = h._ref_t postCell.cell_initialize() h.tstop = 1e3*self.run_duration # duration of a run h.celsius = temp h.dt = dt self.custom_init() h.run()
def run(self, temp=34.0, dt=0.025, seed=575982035, reps=10, stimulus='tone', simulator='cochlea', parallelize=False): assert stimulus in ['tone', 'SAM', 'clicks'] # cases available assert self.cell in [ 'bushy', 'tstellate', 'octopus', 'dstellate', 'tuberculoventral', 'pyramidal' ] self.nrep = reps self.stimulus = stimulus self.run_duration = 0.20 # in seconds self.pip_duration = 0.05 # in seconds self.pip_start = [0.1] # in seconds self.Fs = 100e3 # in Hz self.f0 = 4000. # stimulus in Hz self.cf = 4000. # SGCs in Hz self.fMod = 100. # mod freq, Hz self.dMod = 0. # % mod depth, Hz self.dbspl = 50. self.simulator = simulator self.sr = 2 # set SR group if self.stimulus == 'SAM': self.dMod = 100. self.stim = sound.SAMTone(rate=self.Fs, duration=self.run_duration, f0=self.f0, fmod=self.fMod, dmod=self.dMod, dbspl=self.dbspl, ramp_duration=2.5e-3, pip_duration=self.pip_duration, pip_start=self.pip_start) if self.stimulus == 'tone': self.f0 = 4000. self.cf = 4000. self.stim = sound.TonePip(rate=self.Fs, duration=self.run_duration, f0=self.f0, dbspl=self.dbspl, ramp_duration=2.5e-3, pip_duration=self.pip_duration, pip_start=self.pip_start) if self.stimulus == 'clicks': self.click_rate = 0.020 # msec self.stim = sound.ClickTrain( rate=self.Fs, duration=self.run_duration, f0=self.f0, dbspl=self.dbspl, click_start=0.010, click_duration=100.e-6, click_interval=self.click_rate, nclicks=int((self.run_duration - 0.01) / self.click_rate), ramp_duration=2.5e-3) n_sgc = data.get('convergence', species=species, post_type=self.cell, pre_type='sgc')[0] self.n_sgc = int(np.round(n_sgc)) # for simple synapses, need this value: self.AMPA_gmax = data.get( 'sgc_synapse', species=species, post_type=self.cell, field='AMPA_gmax')[0] / 1e3 # convert nS to uS for NEURON self.vms = [None for n in range(self.nrep)] self.synapses = [None for n in range(self.nrep)] self.xmtrs = [None for n in range(self.nrep)] self.pre_cells = [None for n in range(self.nrep)] self.time = [None for n in range(self.nrep)] info = { 'n_sgc': self.n_sgc, 'gmax': self.AMPA_gmax, 'stim': self.stim, 'simulator': self.simulator, 'cf': self.cf, 'sr': self.sr, 'seed': seed, 'run_duration': self.run_duration, 'temp': temp, 'dt': dt, 'init': custom_init } if not parallelize: for nr in range(self.nrep): info['seed'] = seed + 3 * self.n_sgc * nr res = runTrial(self.cell, info) # res contains: {'time': time, 'vm': Vm, 'xmtr': xmtr, 'pre_cells': pre_cells, 'post_cell': post_cell} self.pre_cells[nr] = res['pre_cells'] self.time[nr] = res['time'] self.xmtr = {k: v.to_python() for k, v in res['xmtr'].items()} self.vms[nr] = res['vm'] self.synapses[nr] = res['synapses'] self.xmtrs[nr] = self.xmtr if parallelize: pass