How to use the neuron.h.Vector function in NEURON

To help you get started, we’ve selected a few NEURON examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neuronsimulator / nrn / share / lib / python / neuron / rxd / section1d.py View on Github external
def _transfer_to_legacy():
    global  _c_ptr_vector, _c_ptr_vector_storage, _c_ptr_vector_storage_nrn
    global _last_c_ptr_length
    
    size = len(_all_cptrs)
    if _last_c_ptr_length != size:
        if size:
            _c_ptr_vector = h.PtrVector(size)
            _c_ptr_vector.ptr_update_callback(_donothing)
            for i, ptr in enumerate(_all_cptrs):
                _c_ptr_vector.pset(i, ptr)
            _c_ptr_vector_storage_nrn = h.Vector(size)
            _c_ptr_vector_storage = _c_ptr_vector_storage_nrn.as_numpy()
        else:
            _c_ptr_vector = None
        _last_c_ptr_length = size
    if size:
        _c_ptr_vector_storage[:] = node._get_states()[_all_cindices]
        _c_ptr_vector.scatter(_c_ptr_vector_storage_nrn)
github mattions / neuronvisio / src / neuronvisio / manager.py View on Github external
def create_t_ref(self, time_interval_recording):
        """Create t ref vector if not present"""
        if not self.group.has_key('t'):
            t = h.Vector()
            if time_interval_recording is None:
                t.record(h._ref_t)
            else:
                t.record(h._ref_t, time_interval_recording)
        
        self.groups['t'] = self.groups[name] # Adding a shortcut to the NEURON time
github Neurosim-lab / netpyne / netpyne / analysis.py View on Github external
if 'stims' in sim.allSimData:
                cellStims = [cellStim for cell,cellStim in sim.allSimData['stims'].iteritems() if netStimPop in cellStim]
                if len(cellStims) > 0:
                    spktsNew = [spkt for cellStim in cellStims for spkt in cellStim[netStimPop] ]
                    spkts.extend(spktsNew)
                    numNetStims += len(cellStims)

        spks2 = list(spkts)

    # time range
    if getattr(sim, 'cfg', None):
        timeRange = [0,sim.cfg.duration]
    else:
        timeRange = [0, max(spks1+spks2)]

    inputVec = h.Vector()
    outputVec = h.Vector()
    histo1 = np.histogram(spks1, bins = np.arange(timeRange[0], timeRange[1], binSize))
    histoCount1 = histo1[0] 
    histo2 = np.histogram(spks2, bins = np.arange(timeRange[0], timeRange[1], binSize))
    histoCount2 = histo2[0] 

    inputVec.from_python(histoCount1)
    outputVec.from_python(histoCount2)
    out = h.normte(inputVec, outputVec, numShuffle)
    TE, H, nTE, _, _ = out.to_python()
    return nTE
github AllenInstitute / bmtk / bmtk / simulator / bionet / biocell.py View on Github external
def setup_ecp(self):
        self.im_ptr = h.PtrVector(self._nseg)  # pointer vector
        # used for gathering an array of  i_membrane values from the pointer vector
        self.im_ptr.ptr_update_callback(self.set_im_ptr)
        self.imVec = h.Vector(self._nseg)

        self.__set_extracell_mechanism()
        #for sec in self.hobj.all:
github Neurosim-lab / netpyne / netpyne / cell / inputs.py View on Github external
if eventsPerCycle > 2 or eventsPerCycle <= 0:
        print("eventsPerCycle should be either 1 or 2, trying 2")
        eventsPerCycle = 2
    # If frequency is 0, create empty vector if input times
    if not freq:
        t_input = []
    elif distribution == 'normal':
        # array of mean stimulus times, starts at start
        isi_array = np.arange(start, params['stop'], 1000. / freq)
        # array of single stimulus times -- no doublets
        if freqStd:
            #t_array = self.prng.normal(np.repeat(isi_array, self.p_ext['repeats']), stdev)
            #t_array = np.array([rand.normal(x, freqStd) for x in np.repeat(isi_array, params['repeats'])])  # not efficient!
            isi_array_repeat = np.repeat(isi_array, params['repeats'])
            stdvec = h.Vector(int(len(isi_array_repeat)))
            rand.normal(0, freqStd*freqStd)
            stdvec.setrand(rand)
            t_array = np.array([mean+std for (mean,std) in zip(list(stdvec), isi_array_repeat)])
        else:
            t_array = isi_array
        if eventsPerCycle == 2: # spikes/burst in GUI
            # Two arrays store doublet times
            t_array_low = t_array - 5
            t_array_high = t_array + 5
            # Array with ALL stimulus times for input
            # np.append concatenates two np arrays
            t_input = np.append(t_array_low, t_array_high)
        elif eventsPerCycle == 1:
            t_input = t_array
        # brute force remove zero times. Might result in fewer vals than desired
        t_input = t_input[t_input > 0]
github Neurosim-lab / netpyne / netpyne / cell / compartCell.py View on Github external
switchtimes = [0, sim.cfg.duration]
                    else:
                        if not params['shape']['switchOnOff'] == sorted(params['shape']['switchOnOff']):
                            raise Exception('On-off switching times for a particular stimulus are not monotonic')   
                        switchtimes = deepcopy(params['shape']['switchOnOff'])
                        switchtimes.append(sim.cfg.duration)
                    
                    switchiter = iter(switchtimes)
                    switchpairs = list(zip(switchiter,switchiter))
                    for pair in switchpairs:
                        # Note: Cliff's makestim code is in seconds, so conversions from ms to s occurs in the args.
                        stimvecs = self._shapeStim(width=float(pulsewidth)/1000.0, isi=float(pulseperiod)/1000.0, weight=params['weight'], start=float(pair[0])/1000.0, finish=float(pair[1])/1000.0, stimshape=pulsetype)
                        temptimevecs.extend(stimvecs[0])
                        tempweightvecs.extend(stimvecs[1])
                    
                    self.conns[-1]['shapeTimeVec'] = h.Vector().from_python(temptimevecs)
                    self.conns[-1]['shapeWeightVec'] = h.Vector().from_python(tempweightvecs)
                    self.conns[-1]['shapeWeightVec'].play(netcon._ref_weight[weightIndex], self.conns[-1]['shapeTimeVec'])


                # Add plasticity
                self._addConnPlasticity(params, sec, netcon, weightIndex)

            if sim.cfg.verbose: 
                sec = params['sec'] if pointp else synMechSecs[i]
                loc = params['loc'] if pointp else synMechLocs[i]
                preGid = netStimParams['source']+' NetStim' if netStimParams else params['preGid']
                try:
                    print(('  Created connection preGid=%s, postGid=%s, sec=%s, loc=%.4g, synMech=%s, weight=%.4g, delay=%.2f' 
                        % (preGid, self.gid, sec, loc, params['synMech'], weights[i], delays[i])))
                except:
                    print(('  Created connection preGid=%s' % (preGid)))
github JustasB / BlenderNEURON / blenderneuron / nrn / neuronsection.py View on Github external
self.coords = blender_section["coords"]
        self.radii = blender_section["radii"]

        nrn_section = self.nrn_section

        # Use 3D points as the L and diam sources
        h.pt3dconst(1,sec=nrn_section)

        # Clear the existing points - and allocate room for the incoming points
        h.pt3dclear(self.point_count, sec=nrn_section)

        # Use vectorization to add the points to section
        coords = np.array(self.coords).reshape((-1, 3))
        diams = np.array(self.radii) * 2.0

        xvec = h.Vector(coords[:,0])
        yvec = h.Vector(coords[:,1])
        zvec = h.Vector(coords[:,2])
        dvec = h.Vector(diams)

        h.pt3dadd(xvec, yvec, zvec, dvec, sec=nrn_section)
github openworm / pygeppetto / jupyter-frontend / verysimple_cell.py View on Github external
from neuron import h
h.load_file('stdrun.hoc')

print('Loading Model...')
soma = h.Section(name='soma')
soma.insert('pas')
asyn = h.AlphaSynapse(soma(0.5))
asyn.onset = 20
asyn.gmax = 1
v_vec = h.Vector()             # Membrane potential vector
t_vec = h.Vector()             # Time stamp vector
v_vec.record(soma(0.5)._ref_v)
t_vec.record(h._ref_t)
h.tstop = 80.0

def analysis():
    from matplotlib import pyplot
    pyplot.figure(figsize=(8,4)) # Default figsize is (8,6)
    pyplot.plot(t_vec, v_vec)
    pyplot.xlabel('time (ms)')
    pyplot.ylabel('mV')
    pyplot.show()
github AllenInstitute / biophys_optimize / biophys_optimize / neuron_passive_fit.py View on Github external
h.v_init = 0
    h.tstop = 100
    h.cvode_active(1)

    v_rec = h.Vector()
    t_rec = h.Vector()
    v_rec.record(h.soma[0](0.5)._ref_v)
    t_rec.record(h._ref_t)

    mrf = h.MulRunFitter[0]
    gen0 = mrf.p.pf.generatorlist.object(0)
    gen0.toggle()
    fit0 = gen0.gen.fitnesslist.object(0)

    up_t = h.Vector(up_data[:, 0])
    up_v = h.Vector(up_data[:, 1])
    fit0.set_data(up_t, up_v)
    fit0.boundary.x[0] = fit_window_start
    fit0.boundary.x[1] = fit_window_end
    fit0.set_w()

    gen1 = mrf.p.pf.generatorlist.object(1)
    gen1.toggle()
    fit1 = gen1.gen.fitnesslist.object(0)

    down_t = h.Vector(down_data[:, 0])
    down_v = h.Vector(down_data[:, 1])
    fit1.set_data(down_t, down_v)
    fit1.boundary.x[0] = fit_window_start
    fit1.boundary.x[1] = fit_window_end
    fit1.set_w()
github AllenInstitute / biophys_optimize / biophys_optimize / neuron_passive_fit.py View on Github external
gen0.toggle()
    fit0 = gen0.gen.fitnesslist.object(0)

    up_t = h.Vector(up_data[:, 0])
    up_v = h.Vector(up_data[:, 1])
    fit0.set_data(up_t, up_v)
    fit0.boundary.x[0] = fit_window_start
    fit0.boundary.x[1] = fit_window_end
    fit0.set_w()

    gen1 = mrf.p.pf.generatorlist.object(1)
    gen1.toggle()
    fit1 = gen1.gen.fitnesslist.object(0)

    down_t = h.Vector(down_data[:, 0])
    down_v = h.Vector(down_data[:, 1])
    fit1.set_data(down_t, down_v)
    fit1.boundary.x[0] = fit_window_start
    fit1.boundary.x[1] = fit_window_end
    fit1.set_w()

    return mrf