Beispiel #1
0
def sim_plot(model, net, connections, population, pg=None):
    traces, names = [], []
    for inj in model.param_sim.injection_current:
        print('ready to simulation with', inj)
        if pg is None:
            create_model_sim.runOneSim(model,
                                       simtime=model.param_sim.simtime,
                                       injection_current=inj)
        else:
            pg.firstLevel = inj
            create_model_sim.runOneSim(model, simtime=model.param_sim.simtime)
        if net.single and len(model.vmtab):
            for neurnum, neurtype in enumerate(model.neurons.keys()):
                traces.append(model.vmtab[neurtype][0].vector)
                names.append('{} @ {}'.format(neurtype, inj))
            if model.synYN:
                net_graph.syn_graph(connections, model.syntab, model.param_sim)
                if model.stpYN and len(model.stp_tab):
                    net_graph.syn_graph(connections,
                                        model.stp_tab,
                                        param_sim,
                                        graph_title='short term plasticity')
            if model.spineYN:
                spine_graph.spineFig(model, model.spinecatab, model.spinevmtab,
                                     model.param_sim.simtime)
        else:
            if net.plot_netvm:
                net_graph.graphs(population['pop'], model.param_sim.simtime,
                                 model.vmtab, model.catab, model.plastab)
            if model.synYN and model.param_sim.plot_synapse:
                net_graph.syn_graph(connections, model.syntab, param_sim)
                if model.stpYN and len(model.stp_tab):
                    net_graph.syn_graph(connections,
                                        model.stp_tab,
                                        model.param_sim,
                                        graph_title='stp',
                                        factor=1)
            #net_output.writeOutput(model, net.outfile,model.spiketab,model.vmtab,population)

    if net.single:
        neuron_graph.SingleGraphSet(traces, names, model.param_sim.simtime)
        # block in non-interactive mode
    util.block_if_noninteractive()
    return
Beispiel #2
0
    run_simulation(simtime=param_sim.simtime, injection_current=inj)
    if param_sim.plot_vm:
        neuron_graph.graphs(ca1, vmtab, param_sim.plot_current,
                            param_sim.simtime, currtab,
                            param_sim.plot_current_label, catab, plastab)
    #set up tables that accumulate soma traces for multiple simulations
    for neurnum, neurtype in enumerate(ca1.neurontypes()):
        traces.append(vmtab[neurnum][0].vector)
        if ca1.calYN and param_sim.plot_calcium:
            catraces.append(catab[neurnum][0].vector)
        names.append('{} @ {}'.format(neurtype, inj))
        # In Python3.6, the following syntax works:
        #names.append(f'{neurtype} @ {inj}')
    #plot spines
    if len(spinevmtab) and param_sim.plot_vm:
        spine_graph.spineFig(ca1, spinecatab, spinevmtab, param_sim.simtime)
    #save output - expand this to optionally save current data
    if param_sim.save:
        inj_nA = inj * 1e9
        tables.write_textfile(vmtab, 'Vm', fname, inj_nA, param_sim.simtime)
        if ca1.calYN:
            tables.write_textfile(catab, 'Ca', fname, inj_nA,
                                  param_sim.simtime)
        if ca1.spineYN and len(spinevmtab):
            tables.write_textfile(list(spinevmtab.values()), 'SpVm', fname,
                                  inj_nA, param_sim.simtime)
            if ca1.spineYN and len(spinecatab):
                tables.write_textfile(list(spinecatab.values()), 'SpCa', fname,
                                      inj_nA, param_sim.simtime)
if param_sim.plot_vm:
    neuron_graph.SingleGraphSet(traces, names, param_sim.simtime)
Beispiel #3
0
if model.synYN and (param_sim.plot_synapse or net.single):
    # overwrite plastab above, since it is empty
    syntab, plastab, stp_tab = tables.syn_plastabs(connections, model)

################### Actually run the simulation
traces, names = [], []
for inj in param_sim.injection_current:
    create_model_sim.runOneSim(model, simtime=model.param_sim.simtime, injection_current=inj)
    if net.single and len(model.vmtab):
        for neurnum, neurtype in enumerate(util.neurontypes(model.param_cond)):
            traces.append(model.vmtab[neurtype][0].vector)
            names.append('{} @ {}'.format(neurtype, inj))
        if model.synYN:
            net_graph.syn_graph(connections, syntab, param_sim)
        if model.spineYN:
            spine_graph.spineFig(model, model.spinecatab, model.spinevmtab, param_sim.simtime)
    else:
        if net.plot_netvm:
            net_graph.graphs(population['pop'], param_sim.simtime, vmtab, catab, plastab)
        if model.synYN and param_sim.plot_synapse:
            net_graph.syn_graph(connections, syntab, param_sim)
            if model.stpYN:
                net_graph.syn_graph(connections, stp_tab, param_sim, graph_title='stp', factor=1)
        outfname = net.outfile + str(inj) + 'gaba' + str(model.param_syn.SYNAPSE_TYPES.gaba.Gbar)
        net_output.writeOutput(model, outfname, spiketab, vmtab, population)

if net.single:
    neuron_graph.SingleGraphSet(traces, names, param_sim.simtime)
    # block in non-interactive mode
util.block_if_noninteractive()
Beispiel #4
0
traces, names = [], []
for inj in param_sim.injection_current:
    run_simulation(injection_current=inj, simtime=param_sim.simtime)
    if net.single and len(model.vmtab):
        for neurnum,neurtype in enumerate(util.neurontypes(model.param_cond)):
            traces.append(model.vmtab[neurtype][0].vector)
            names.append('{} @ {}'.format(neurtype, inj))
        if model.synYN:
            net_graph.syn_graph(connections, syntab, param_sim)
        if model.plasYN:
            net_graph.syn_graph(connections, plastab, param_sim, graph_title='Plas Weight')
            net_graph.syn_graph(connections, nonstim_plastab, param_sim, graph_title='NonStim Plas Weight')

        if model.spineYN:
            spine_graph.spineFig(model,model.spinecatab,model.spinevmtab, param_sim.simtime)
    else:
        if net.plot_netvm:
            net_graph.graphs(population['pop'], param_sim.simtime, vmtab,catab,plastab)
        if model.synYN and param_sim.plot_synapse:
            net_graph.syn_graph(connections, syntab, param_sim)
        net_output.writeOutput(model, net.outfile+str(inj),spiketab,vmtab,population)

if net.single:
    neuron_graph.SingleGraphSet(traces, names, param_sim.simtime)
    # block in non-interactive mode

weights = [w.value for w in moose.wildcardFind('/##/plas##[TYPE=Function]')]
plt.figure()
plt.hist(weights,bins=100)
util.block_if_noninteractive()
Beispiel #5
0
def runAll(model, plotIndividualInjections=False, writeWavesCSV=False, printParams = False):
    plt.ion()
    if model.plasYN:
        plotIndividualInjections=True
    traces, names, catraces, current_traces, curr_names = [], [], [], [], []
    for inj in model.param_sim.injection_current:
        runOneSim(model, simtime=model.param_sim.simtime, injection_current=inj)
        if model.param_sim.plot_vm and plotIndividualInjections:
            neuron_graph.graphs(model, model.vmtab, model.param_sim.plot_current,
                                model.param_sim.simtime, model.currtab,
                                model.param_sim.plot_current_label,
                                model.catab, model.plastab)
        #set up tables that accumulate soma traces for multiple simulations
        for neurnum,neurtype in enumerate(model.neurons.keys()):
            for plotcompnum, plotcomp in enumerate(model.param_sim.plotcomps):
                traces.append(model.vmtab[neurtype][plotcompnum].vector)
                if model.calYN and model.param_sim.plot_calcium:
                    catraces.append(model.catab[neurtype][plotcompnum].vector)
                names.append('{} {} @ {}'.format(plotcomp, neurtype, inj))
                # In Python3.6, the following syntax works:
                #names.append(f'{neurtype} @ {inj}')
        if model.param_sim.plot_current:
            for channame in model.Channels.keys():
                current_traces.append(model.currtab[neurtype][channame][0].vector)
                curr_names.append('{}: {} @ {}'.format(neurtype, channame,inj))

        #plot spines
        if len(model.spinevmtab) and model.param_sim.plot_vm:
            spine_graph.spineFig(model, model.spinecatab, model.spinevmtab,
                                 model.param_sim.simtime)
        #save plain text output - expand this to optionally save current data
        if model.param_sim.save_txt:
            tables.write_textfiles(model, inj)

        # Switch hdf5writer mode from 2 (overwrite) to 1 (append)
        # Note that hdf5writer is initialized in mode 2, overwriting prior simulations,
        # But within one simulation at multiple current injections setting mode to 1
        # allows appending the file with each current injection iteration,
        # and calling "wrap_hdf5" modifies the hdf5 file for each injection
        if model.param_sim.save:
            model.writer.mode=1
            model.writer.close()
            tables.wrap_hdf5(model,'injection_{}'.format(inj))

    if model.param_sim.plot_vm:
        neuron_graph.SingleGraphSet(traces, names, model.param_sim.simtime)
        if model.calYN and model.param_sim.plot_calcium:
            neuron_graph.SingleGraphSet(catraces, names, model.param_sim.simtime,title='Calcium')

    if model.param_sim.plot_current:
        num_currents=np.shape(current_traces)[0]//len(model.param_sim.injection_current)
        neuron_graph.SingleGraphSet(current_traces[-num_currents:], curr_names,model.param_sim.simtime)
        if getattr(model.param_sim,'plotgate',None):
            plt.figure()
            ts = np.linspace(0, model.param_sim.simtime, len(model.gatetables['gatextab'].vector))
            plt.suptitle('X,Y,Z gates; hsolve='+str(model.param_sim.hsolve)+' calYN='+str(model.calYN)+' Zgate='+str(model.Channels[model.param_sim.plotgate][0][2]))
            plt.plot(ts,model.gatetables['gatextab'].vector,label='X')
            plt.plot(ts,model.gatetables['gateytab'].vector,label='Y')
            if model.Channels[model.param_sim.plotgate][0][2]==1:
                plt.plot(ts,model.gatetables['gateztab'].vector,label='Z')
            plt.legend()

    util.block_if_noninteractive()
    for st in model.spiketab:
          print("number of spikes", st.path, ' = ',len(st.vector))

    model.traces, model.catraces = traces, catraces
    if model.param_sim.save:
        tables.save_hdf5_attributes(model)
        model.writer.close()
    if writeWavesCSV:
        timeCol = np.linspace(0, model.param_sim.simtime, len(model.traces[0]))*1e3 #ms
        vCol = model.traces[0] *1e3 #mV
        inj = model.param_sim.injection_current[0]
        header = 'Time (ms),{} pA'.format(inj*1e12)
        np.savetxt(model.param_sim.fname+'difshellwaves.csv', np.column_stack((timeCol,vCol)), delimiter=',', header = header, comments='' )