コード例 #1
0
    if sys.argv[-1] == 'plot':
        ## load file
        data = ntwk.load_dict_from_hdf5('CellRep2019_data.h5')
        print(data)
        # ## plot
        fig, _ = ntwk.raster_and_Vm_plot(data, smooth_population_activity=10.)
        ntwk.show()

    else:
        import numpy as np
        from analyz.processing.signanalysis import smooth

        NTWK = ntwk.build_populations(Model, ['RecExc', 'RecInh', 'DsInh'],
                                      AFFERENT_POPULATIONS=['AffExc'],
                                      with_raster=True,
                                      with_Vm=4,
                                      verbose=True)

        ntwk.build_up_recurrent_connections(NTWK, SEED=5, verbose=True)

        #######################################
        ########### AFFERENT INPUTS ###########
        #######################################

        t_array = ntwk.arange(int(Model['tstop'] / Model['dt'])) * Model['dt']
        faff = smooth(np.array([4 * int(tt / 1000) for tt in t_array]),
                      int(200 / 0.1))

        # ######################
        # ## ----- Plot ----- ##
コード例 #2
0
def run_sim(Model,
            with_Vm=0,
            with_synaptic_currents=False,
            firing_rate_only=False,
            tdiscard=100):

    if 'RATES' in Model.keys():
        RATES = Model['RATES']
    else:
        RATES = {}
        for pop in Model['POP_STIM']:
            RATES['F_' + pop] = Model['F_' + pop]

    if tdiscard >= Model['tstop']:
        print('discard time higher than simulation time -> set to 0')
        tdiscard = 0

    t_array = np.arange(int(Model['tstop'] / Model['dt'])) * Model['dt']

    ############################################################################
    # everything is reformatted to have it compatible with the network framework
    ############################################################################

    aff_pops_discard_self = []
    for p in Model['POP_STIM']:
        if p != Model['NRN_KEY']:
            aff_pops_discard_self.append(p)

    # note that number of neurons become number of different seeds
    NTWK = ntwk.build_populations(
        Model, [Model['NRN_KEY']],
        NEURONS=[{
            'name': Model['NRN_KEY'],
            'N': Model['N_SEED']
        }],
        AFFERENT_POPULATIONS=aff_pops_discard_self,
        with_Vm=with_Vm,
        with_raster=True,
        with_synaptic_currents=with_synaptic_currents)

    ntwk.initialize_to_rest(
        NTWK)  # (fully quiescent State as initial conditions)

    SPKS, SYNAPSES, PRESPKS = [], [], []

    for i, afferent_pop in enumerate(Model['POP_STIM']):
        rate_array = RATES['F_' + afferent_pop] + 0. * t_array
        ntwk.construct_feedforward_input(NTWK,
                                         Model['NRN_KEY'],
                                         afferent_pop,
                                         t_array,
                                         rate_array,
                                         SEED=i + Model['SEED'])

    sim = ntwk.collect_and_run(NTWK)

    # calculating firing rate
    vec = np.zeros(Model['N_SEED'])
    ispikes = np.array(NTWK['RASTER'][0].i)
    tspikes = np.array(NTWK['RASTER'][0].t / ntwk.ms)
    for nrn in range(Model['N_SEED']):
        i0 = np.argwhere(ispikes == nrn).flatten()
        ts = tspikes[i0]
        fout = 1e3 * len(ts[ts > tdiscard]) / (Model['tstop'] - tdiscard
                                               )  # from ms to Hz
        vec[nrn] = fout

    if firing_rate_only:
        return vec.mean(), vec.std()
    else:
        output = {
            'ispikes': np.array(NTWK['RASTER'][0].i),
            'tspikes': np.array(NTWK['RASTER'][0].t / ntwk.ms),
            'Model': Model,
            'fout_mean': vec.mean(),
            'fout_std': vec.std()
        }
        if with_Vm:
            output['i_prespikes'] = NTWK['iRASTER_PRE']
            output['t_prespikes'] = [
                vv / ntwk.ms for vv in NTWK['tRASTER_PRE']
            ]
            output['Vm'] = np.array([vv.V / ntwk.mV for vv in NTWK['VMS'][0]])
        if with_synaptic_currents:
            output['Ie'] = np.array(
                [vv.Ie / ntwk.pA for vv in NTWK['ISYNe'][0]])
            output['Ii'] = np.array(
                [vv.Ii / ntwk.pA for vv in NTWK['ISYNi'][0]])
        return output
コード例 #3
0
    ## plot
    fig, AX = plt.subplots(2)
    AX[0].plot(data['tRASTER_Exc'], data['iRASTER_Exc'], 'bo', ms=2)
    AX[0].plot(data['tRASTER_Inh'], -data['iRASTER_Inh'], 'ro', ms=2)
    ntwk.set_plot(AX[0], [], xticks=[], yticks=[])
    for v in data['VMS_Exc']:
        AX[1].plot(np.arange(len(v)) * data['dt'], v, 'k-', lw=1)
    ntwk.set_plot(AX[1], xlabel='time (ms)', ylabel='Vm (mV)')
    ntwk.show()

else:
    ## we build and run the simulation
    NTWK = ntwk.build_populations(
        Model,
        ['Exc', 'Inh'],
        with_raster=True,
        with_Vm=4,
        # with_synaptic_currents=True,
        # with_synaptic_conductances=True,
        verbose=True)

    ntwk.build_up_recurrent_connections(NTWK, SEED=5, verbose=True)

    ################################################################
    ## --------------- Initial Condition ------------------------ ##
    ################################################################
    for i in range(2):
        NTWK['POPS'][i].V = (-65 + 5 * np.random.randn(NTWK['POPS'][i].N)
                             ) * ntwk.mV  # random Vm

    # then excitation
    NTWK['POPS'][0].GExcExc = abs(40 + 15 *
コード例 #4
0
    ######################

    t_array = ntwk.arange(int(Model['tstop'] / Model['dt'])) * Model['dt']
    faff = smooth(np.array([4 * int(tt / 1000) for tt in t_array]),
                  int(200 / 0.1))

    fnoise = 3.

    #######################################
    ########### BUILD POPS ################
    #######################################

    NTWK = ntwk.build_populations(Model,
                                  REC_POPS,
                                  AFFERENT_POPULATIONS=AFF_POPS,
                                  with_pop_act=True,
                                  with_raster=True,
                                  with_Vm=4,
                                  verbose=True)

    ntwk.build_up_recurrent_connections(NTWK, SEED=5, verbose=True)

    #######################################
    ########### AFFERENT INPUTS ###########
    #######################################

    #  time-dep afferent excitation
    for i, tpop in enumerate(REC_POPS):  # both on excitation and inhibition
        ntwk.construct_feedforward_input(NTWK,
                                         tpop,
                                         'AffExc',
コード例 #5
0
    # ## ----- Plot ----- ##
    # ######################

    ## load file
    data = ntwk.load_dict_from_hdf5('3pop_model_data.h5')

    # ## plot
    fig, _ = ntwk.activity_plots(data, smooth_population_activity=10.)

    plt.show()
else:
    NTWK = ntwk.build_populations(
        Model,
        ['Exc', 'Inh', 'DsInh'],
        AFFERENT_POPULATIONS=['AffExc'],
        with_raster=True,
        with_Vm=4,
        # with_synaptic_currents=True,
        # with_synaptic_conductances=True,
        verbose=True)

    ntwk.build_up_recurrent_connections(NTWK, SEED=5, verbose=True)

    #######################################
    ########### AFFERENT INPUTS ###########
    #######################################

    faff = 1.
    t_array = ntwk.arange(int(Model['tstop'] / Model['dt'])) * Model['dt']
    # # # afferent excitation onto cortical excitation and inhibition
    for i, tpop in enumerate(['Exc', 'Inh',
コード例 #6
0
    ## load file
    data = ntwk.load_dict_from_hdf5('sinusoidal_input_data.h5')
    data['iRASTER_L4Exc'] = data['iRASTER_PRE1']
    data['tRASTER_L4Exc'] = data['tRASTER_PRE1']
    # # ## plot
    fig, _ = ntwk.activity_plots(
        data,
        POP_KEYS=['L23Exc', 'PVInh', 'SOMInh', 'VIPInh'],
        COLORS=['green', 'red', 'orange', 'purple'],
        smooth_population_activity=10.)
    plt.show()
else:
    NTWK = ntwk.build_populations(Model,
                                  ['L23Exc', 'PVInh', 'SOMInh', 'VIPInh'],
                                  AFFERENT_POPULATIONS=['L4Exc'],
                                  with_raster=True,
                                  with_Vm=4,
                                  with_pop_act=True,
                                  verbose=True)

    ntwk.build_up_recurrent_connections(NTWK, SEED=5, verbose=True)

    #######################################
    ########### AFFERENT INPUTS ###########
    #######################################

    t_array = ntwk.arange(int(Model['tstop'] / Model['dt'])) * Model['dt']
    faff = 0.8 + 0.7 * (1 - np.cos(2 * np.pi * 4e-3 * t_array))
    faff[t_array < 750] = 1.

    # # # afferent excitation onto cortical excitation and inhibition