def sgc_psd_test(cell_class, seed, plot=False, tstop=5.0, n_syn=20): """ Tests a multisite synapse from the SGC to a target cell. The values returned from an actual set of runs of the synapse are compared to the expected values in the synapses.py table. This is needed because the maximal open probability of the receptor models is not 1, so the maximal conductance per receptor needs to be adjusted empirically. If the measured current does not match the expected current, then we print a message with the expected value, and fail with an assert statment in the test. The measurement itself is made in measure_gmax(). Parameters ---------- cell_class : an instance of the cell class seed : int random number seed for the call plot : boolean (default False) plot request, passed to measure_gmax tstop : float (default 5.0 ms) duration of run for measurement of gmax. Needs to be long enough to find the maximum of the EPSC/IPSC. n_syn : int (default 20) number of synapses to instantiate for testing (to get an average value) """ celltyp = cell_class.__name__.lower() random_seed.set_seed(seed) reset(raiseError=False) # avoid failure because we cannot release NEURON objects completely. tsc = cell_class.create(ttx=True) (ampa_gmax, nmda_gmax, epsc_cv) = measure_gmax(tsc, n_syn=n_syn, tstop=tstop, plot=plot) exp_ampa_gmax = data.get('sgc_synapse', species='mouse', post_type=celltyp, field='AMPA_gmax')[0] exp_nmda_gmax = data.get('sgc_synapse', species='mouse', post_type=celltyp, field='NMDA_gmax')[0] exp_epsc_cv = data.get('sgc_synapse', species='mouse', post_type=celltyp, field='EPSC_cv') ampa_correct = np.allclose(exp_ampa_gmax, ampa_gmax) if not ampa_correct: AMPAR_gmax = data.get('sgc_synapse', species='mouse', post_type=celltyp, field='AMPAR_gmax') ratio = exp_ampa_gmax/ampa_gmax print('AMPA Receptor conductance in model should be %.16f (table is %.16f)' % (AMPAR_gmax * ratio, AMPAR_gmax)) nmda_correct = np.allclose(exp_nmda_gmax, nmda_gmax) if not nmda_correct: NMDAR_gmax = data.get('sgc_synapse', species='mouse', post_type=celltyp, field='NMDAR_gmax') ratio = exp_nmda_gmax/nmda_gmax print('NMDA Receptor conductance in model should be %.16f (table is %.16f)' % (NMDAR_gmax * ratio, NMDAR_gmax)) cv_correct = (abs(exp_epsc_cv / epsc_cv - 1.0) < 0.1) print 'cv_correct: ', cv_correct if not cv_correct: ratio = exp_epsc_cv/epsc_cv print('CV Receptor in synapses.py model should be %.6f (measured = %.6f; table = %.6f)' % (epsc_cv * ratio, epsc_cv, exp_epsc_cv)) print ((abs(exp_epsc_cv / (epsc_cv * ratio) - 1.0) < 0.1)) assert cv_correct assert ampa_correct and nmda_correct
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