Esempio n. 1
0
def perturbations():
    sim_time = 10000.0
    size = 20000.0
    threads = 1

    freqs = [1., 2.0]

    path = ('/home/mikael/results/papers/inhibition' +
            '/network/simulate_inhibition_ZZZ4/')
    l = op.get()[-3:]

    for i in range(len(l)):
        l[i] += pl(
            {
                'simu': {
                    'sim_time': sim_time,
                    'sim_stop': sim_time,
                    'threads': threads
                },
                'netw': {
                    'size': size
                }
            }, '=')

    damp = process(path, freqs)
    for key in sorted(damp.keys()):
        val = damp[key]
        print numpy.round(val, 2), key

    ll = []
    for i, _l in enumerate(l):
        for j, _ in enumerate(freqs):

            amp = [numpy.round(damp[_l.name][j], 2), 1]
            d = {
                'type': 'oscillation2',
                'params': {
                    'p_amplitude_mod': amp[0],
                    'p_amplitude0': amp[1],
                    'freq': 20.
                }
            }
            _ll = deepcopy(_l)
            dd = {}
            for key in ['C1', 'C2', 'CF', 'CS']:
                dd = misc.dict_update(dd, {'netw': {'input': {key: d}}})

            _ll += pl(dd, '=', **{'name': 'amp_{0}-{1}'.format(*amp)})

            ll.append(_ll)

    return ll, threads
Esempio n. 2
0
def pert_add_oscillations(**kwargs):

    amp_base = kwargs.get('amp_base')  # Scaling of base frequency
    amp_base_skip = kwargs.get(
        'amp_base_skip',
        [])  #skip amplitude modulation for nuclies in this list
    do_reset = kwargs.get(
        'do_reset',
        True)  #reset simulations between runs in engine.py with nest.reset
    down_vec = kwargs.get('down_vec')  #?
    freqs = kwargs.get('freqs')  # Frequency amplitude modulation
    freq_oscillation = kwargs.get('freq_oscillation')
    external_input_mod = kwargs.get('external_input_mod', [])
    input_mod = kwargs.get('input_mod', ['C1', 'C2', 'CF', 'CS'])
    no_mod = kwargs.get('no_mod', [])
    local_num_threads = kwargs.get('local_num_threads')
    null_down = kwargs.get('null_down', False)
    null_down_STN = kwargs.get('null_down_stn', False)
    path_rate_runs = kwargs.get('path_rate_runs')
    perturbation_list = kwargs.get('perturbation_list')
    sim_time = kwargs.get('sim_time')
    size = kwargs.get('size')
    STN_amp_mod = kwargs.get('STN_amp_mod', [1.])
    tuning_freq_amp_to = kwargs.get('tuning_freq_amp_to', 'M1')

    l = perturbation_list
    for i in range(len(l)):
        l[i] += pl(
            {
                'simu': {
                    'do_reset': do_reset,
                    'sd_params': {
                        'to_file': True,
                        'to_memory': False
                    },
                    'sim_time': sim_time,
                    'sim_stop': sim_time,
                    'local_num_threads': local_num_threads
                },
                'netw': {
                    'size': size
                }
            }, '=')

    kw_process = {'freqs': freqs, 'tuning_freq_amp_to': tuning_freq_amp_to}
    damp = process(path_rate_runs, **kw_process)
    for key in sorted(damp.keys()):
        val = damp[key]
        print key, numpy.round(val, 2)

    ll = []

    for j, i, STN_amp, _l in iterator_oscillations(freqs, STN_amp_mod, l):
        amp = [numpy.round(damp[_l.name][j], 2), amp_base[j]]

        _l = deepcopy(_l)
        dd = {}
        for key in input_mod:

            if key in ['C1', 'C2', 'CF']:
                factor = 1
            elif key in ['CS']:
                factor = STN_amp

            if null_down:
                down = -1.
            elif null_down_STN and key in ['CS']:
                down = -1
            elif down_vec:
                down = down_vec[j]
            else:
                down = -amp[0] * factor

            if key not in amp_base_skip:
                amp0 = amp[1]
            else:
                amp0 = 1.

            if amp0 > 1.0:
                pass

            upp = amp[0]

            #             print amp, amp0

            if (key in no_mod): upp, down = 0., 0.

            d = {
                'type': 'oscillation2',
                'params': {
                    'p_amplitude_upp': upp * factor,
                    'p_amplitude_down': down,
                    'p_amplitude0': amp0,
                    'freq': freq_oscillation
                }
            }

            dd = misc.dict_update(dd, {'netw': {'input': {key: d}}})

        if STN_amp != 1:
            _l += pl(
                dd, '=',
                **{'name': 'amp_{0}_{1}_stn_{2}'.format(upp, amp[1], STN_amp)})
        elif down_vec:
            _l += pl(dd, '=',
                     **{'name': 'amp_{0}_{1}_{2}'.format(upp, down, amp[1])})

        else:
            _l += pl(dd, '=', **{'name': 'amp_{0}_{1}'.format(*[upp, amp[1]])})

        if external_input_mod:

            dd = {}
            for key in external_input_mod:
                dd = misc.dict_update(dd, {'node': {key: {'rate': amp0}}})

            _l += pl(dd, '*', **{'name': 'EIEA_{0}'.format(amp0)})

        ll.append(_l)

    return ll
Esempio n. 3
0
    def get_setup_args_and_kwargs(i_p_list, **kwargs):

        amp_base = kwargs.get('amp_base')
        amp_base_skip = kwargs.get('amp_base_skip')
        duration = kwargs.get('duration')
        freqs = kwargs.get('freqs')
        freq_oscillations = kwargs.get('freq_oscillations')
        home = kwargs.get('home')
        home_data = kwargs.get('home_data')
        home_module = kwargs.get('home_module')
        input_type = kwargs.get('input_type', 'burst3')
        labels = kwargs.get('labels', [
            'Only D1', 'D1,D2', 'MSN lesioned (D1, D2)',
            'FSN lesioned (D1, D2)', 'GPe TA lesioned (D1,D2)'
        ])
        laptime = kwargs.get('laptime')
        l_mean_rate_slices = kwargs.get('l_mean_rate_slices')
        local_num_threads = kwargs.get('local_num_threads')
        other_scenario = kwargs.get('other_scenario', False)
        #         oscillation_returbations_index=kwargs.get('oscillation_returbations_index')
        p_pulses = kwargs.get('p_pulses')
        path_rate_runs = kwargs.get('path_rate_runs')
        perturbation_list = kwargs.get('perturbation_list')
        props_conn = kwargs.get('proportion_connected', 1.)
        res = kwargs.get('res')
        rep = kwargs.get('rep')
        STN_amp_mod = kwargs.get('STN_amp_mod')
        threshold = kwargs.get('threshold')
        time_bin = kwargs.get('time_bin')
        tuning_freq_amp_to = kwargs.get('tuning_freq_amp_to')

        kw_process = {'freqs': freqs, 'tuning_freq_amp_to': tuning_freq_amp_to}
        damp = process(path_rate_runs, **kw_process)  #freq in kwargs
        for key in sorted(damp.keys()):
            val = damp[key]
            print key, numpy.round(val, 2)

        freqs = numpy.round(damp[perturbation_list[0].name][0], 2)

        if type(props_conn) == list:
            print i_p_list
            pc = props_conn[i_p_list]
        else:
            pc = props_conn

        kwargs = {
            'amp_base': amp_base,
            'amp_base_skip': amp_base_skip,
            'duration': duration,
            'freqs': freqs,
            'freq_oscillations': freq_oscillations,
            'home': home,
            'home_data': home_data,
            'home_module': home_module,
            'input_type': input_type,
            'l_mean_rate_slices': l_mean_rate_slices,
            'labels': labels,
            'laptime': laptime,
            'local_num_threads': local_num_threads,
            'other_scenario': other_scenario,
            'proportion_connected': pc,
            'p_pulses': p_pulses,
            'resolution': res,
            'repetition': rep,
            'STN_amp_mod': STN_amp_mod,
            'threshold': threshold,
            'time_bin': time_bin,
        }
        return [], kwargs