Пример #1
0
        def check_current(ampl, dtc):
            '''
            Inputs are an amplitude to test and a virtual model
            output is an virtual model with an updated dictionary.
            '''
            import copy
            import os
            import quantities
            from neuronunit.models.reduced import ReducedModel
            import neuronunit
            LEMS_MODEL_PATH = str(neuronunit.__path__[0]) + str(
                '/models/NeuroML2/LEMS_2007One.xml')
            dtc.model_path = LEMS_MODEL_PATH
            model = ReducedModel(dtc.model_path,
                                 name='vanilla',
                                 backend=(str(dtc.backend), {
                                     'DTC': dtc
                                 }))

            import copy
            model.set_attrs(dtc.attrs)

            DELAY = 100.0 * pq.ms
            DURATION = 1000.0 * pq.ms
            params = {
                'injected_square_current': {
                    'amplitude': 100.0 * pq.pA,
                    'delay': DELAY,
                    'duration': DURATION
                }
            }

            dtc = copy.copy(dtc)
            ampl = float(ampl)
            #print(dtc.lookup)
            if ampl not in dtc.lookup or len(dtc.lookup) == 0:
                current = params.copy()['injected_square_current']
                uc = {'amplitude': ampl}
                current.update(uc)
                current = {'injected_square_current': current}
                dtc.run_number += 1
                model.set_attrs(dtc.attrs)
                model.inject_square_current(current)
                dtc.previous = ampl
                n_spikes = model.get_spike_count()
                dtc.lookup[float(ampl)] = n_spikes
                if n_spikes == 1:
                    dtc.rheobase = float(ampl)
                    dtc.boolean = True
                    return dtc

                return dtc
            if float(ampl) in dtc.lookup:
                return dtc
Пример #2
0
        def check_current(dtc):
            '''
            Inputs are an amplitude to test and a virtual model
            output is an virtual model with an updated dictionary.
            '''

            LEMS_MODEL_PATH = str(neuronunit.__path__[0]) + str(
                '/models/NeuroML2/LEMS_2007One.xml')
            dtc.model_path = LEMS_MODEL_PATH

            model = ReducedModel(dtc.model_path,
                                 name='vanilla',
                                 backend=(dtc.backend, {
                                     'DTC': dtc
                                 }))

            dtc.current_src_name = model._backend.current_src_name
            assert type(dtc.current_src_name) is not type(None)
            dtc.cell_name = model._backend._cell_name
            #model.set_attrs(dtc.attrs)

            DELAY = 100.0 * pq.ms
            DURATION = 1000.0 * pq.ms
            params = {
                'injected_square_current': {
                    'amplitude': 100.0 * pq.pA,
                    'delay': DELAY,
                    'duration': DURATION
                }
            }

            ampl = float(dtc.ampl)
            if ampl not in dtc.lookup or len(dtc.lookup) == 0:
                current = params.copy()['injected_square_current']
                uc = {'amplitude': ampl}
                current.update(uc)
                current = {'injected_square_current': current}
                dtc.run_number += 1
                model.set_attrs(dtc.attrs)
                model.inject_square_current(current)
                #dtc.previous = ampl
                n_spikes = model.get_spike_count()
                dtc.lookup[float(ampl)] = n_spikes
                if n_spikes == 1:
                    dtc.rheobase = float(ampl)
                    dtc.boolean = True
                    return dtc

                return dtc
            if float(ampl) in dtc.lookup:
                return dtc
Пример #3
0
        def check_current(ampl, dtc):
            '''
            Inputs are an amplitude to test and a virtual model
            output is an virtual model with an updated dictionary.
            '''
            ampl = float(ampl)
            import os
            #from neuronunit.models import reduced
            from neuronunit.models.reduced import ReducedModel
            #assert os.path.isfile(dtc.model_path), "%s is not a file" % dtc.model_path
            model = ReducedModel(dtc.model_path,
                                 name='vanilla',
                                 backend='NEURON')
            #print(model)
            #import pdb; pdb.set_trace()
            DELAY = 100.0 * pq.ms
            DURATION = 1000.0 * pq.ms
            params = {
                'injected_square_current': {
                    'amplitude': 100.0 * pq.pA,
                    'delay': DELAY,
                    'duration': DURATION
                }
            }

            if ampl not in dtc.lookup or len(dtc.lookup) == 0:
                current = params.copy()['injected_square_current']
                uc = {'amplitude': ampl}
                current.update(uc)
                current = {'injected_square_current': current}
                dtc.run_number += 1
                #import ipyparallel as ipp
                #model = ipp.Reference('model')
                model.set_attrs(dtc.attrs)
                model.name = dtc.attrs
                model.inject_square_current(current)
                dtc.previous = ampl
                n_spikes = model.get_spike_count()
                dtc.lookup[float(ampl)] = n_spikes
                #name = str('rheobase {0} parameters {1}'.format(str(current),str(model.params)))

                if n_spikes == 1:
                    dtc.rheobase = float(ampl)
                    dtc.boolean = True
                    return dtc

                return dtc
            if float(ampl) in dtc.lookup:
                return dtc
Пример #4
0
def use_dtc_to_plotting(dtcpop, minimagr):
    from neuronunit.capabilities import spike_functions
    import matplotlib.pyplot as plt
    import numpy as np
    plt.clf()
    plt.style.use('ggplot')
    fig, axes = plt.subplots(figsize=(10, 10), facecolor='white')
    stored_min = []
    stored_max = []
    for dtc in dtcpop[1:-1]:
        plt.plot(dtc.tvec, dtc.vm0, linewidth=3.5, color='grey')
        stored_min.append(np.min(dtc.vm0))
        stored_max.append(np.max(dtc.vm0))

    from neuronunit.models.reduced import ReducedModel
    from neuronunit.optimization.get_neab import tests as T
    from neuronunit.optimization import get_neab
    from neuronunit.optimization import evaluate_as_module
    from neuronunit.optimization.evaluate_as_module import pre_format
    model = ReducedModel(get_neab.LEMS_MODEL_PATH,
                         name=str('vanilla'),
                         backend='NEURON')
    import neuron
    model._backend.reset_neuron(neuron)
    model.set_attrs(minimagr.attrs)
    model.rheobase = minimagr.rheobase['value']
    minimagr = pre_format(minimagr)
    parameter_list = list(minimagr.vtest.values())
    model.inject_square_current(parameter_list[0])
    model._backend.local_run()
    assert model.get_spike_count() == 1
    print(model.get_spike_count(), bool(model.get_spike_count() == 1))
    brute_best = list(model.results['vm'])

    plt.plot(dtcpop[0].tvec,
             brute_best,
             linewidth=1,
             color='blue',
             label='best candidate via grid')  #+str(mini.scores))
    plt.plot(dtcpop[0].tvec,
             dtcpop[0].vm0,
             linewidth=1,
             color='red',
             label='best candidate via GA')  #+str(miniga.scores))
    plt.legend()
    plt.ylabel('$V_{m}$ mV')
    plt.xlabel('ms')
    plt.show()
Пример #5
0
        def check_current(ampl,dtc):
            '''
            Inputs are an amplitude to test and a virtual model
            output is an virtual model with an updated dictionary.
            '''
            import copy
            import os
            import quantities
            from neuronunit.models.reduced import ReducedModel
            import neuronunit
            LEMS_MODEL_PATH = str(neuronunit.__path__[0])+str('/models/NeuroML2/LEMS_2007One.xml')
            dtc.model_path = LEMS_MODEL_PATH
            model = ReducedModel(dtc.model_path,name='vanilla', backend=(str(dtc.backend), {'DTC':dtc}))

            import copy
            model.set_attrs(dtc.attrs)

            DELAY = 100.0*pq.ms
            DURATION = 1000.0*pq.ms
            params = {'injected_square_current':
                      {'amplitude':100.0*pq.pA, 'delay':DELAY, 'duration':DURATION}}

            dtc = copy.copy(dtc)
            ampl = float(ampl)
            #print(dtc.lookup)
            if ampl not in dtc.lookup or len(dtc.lookup) == 0:
                current = params.copy()['injected_square_current']
                uc = {'amplitude':ampl}
                current.update(uc)
                current = {'injected_square_current':current}
                dtc.run_number += 1
                model.set_attrs(dtc.attrs)
                model.inject_square_current(current)
                dtc.previous = ampl
                n_spikes = model.get_spike_count()
                dtc.lookup[float(ampl)] = n_spikes
                if n_spikes == 1:
                    dtc.rheobase = float(ampl)
                    dtc.boolean = True
                    return dtc

                return dtc
            if float(ampl) in dtc.lookup:
                return dtc
Пример #6
0
def plot_vm(hof,ax,key):
    ax.cla()
    best_dtc = hof[1].dtc
    best_rh = hof[1].dtc.rheobase
    print( [ h.dtc.rheobase for h in hof ])
    
    neuron = None
    model = ReducedModel(path_params['model_path'],name = str('regular_spiking'),backend =('NEURON',{'DTC':best_dtc}))
    params = {'injected_square_current':
            {'amplitude': best_rh['value'], 'delay':DELAY, 'duration':DURATION}}
    model.set_attrs(hof[0].dtc.attrs)
    results = model.inject_square_current(params)
    print(model.attrs,best_dtc.attrs,best_rh)
    vm = model.get_membrane_potential()
    times = vm.times
    ax.plot(times,vm)
    #ax.xlabel('ms')
    #ax.ylabel('mV')
    #ax.set_xlim(np.min(x),np.max(x))
    #ax.set_ylim(np.min(z),np.max(z))
    return ax
Пример #7
0
dtc = DataTC()
from neuronunit.tests import np, pq, cap, VmTest, scores, AMPL, DELAY, DURATION

opt_keys = ['a', 'b', 'vr']
nparams = len(opt_keys)
import numpy as np

attrs = {
    'a': np.median(mp['a']),
    'b': np.median(mp['b']),
    'vr': np.median(mp['vr'])
}
dtc.attrs = attrs
model = ReducedModel(path_params['model_path'],
                     name=str('vanilla'),
                     backend=('NEURON', {
                         'DTC': dtc
                     }))

params = {
    'injected_square_current': {
        'amplitude': 10.0 * pq.pA,
        'delay': DELAY,
        'duration': DURATION
    }
}

model.inject_square_current(params)
n_spikes = model.get_spike_count()
print(n_spikes)
        def check_current(dtc):
            '''
            Inputs are an amplitude to test and a virtual model
            output is an virtual model with an updated dictionary.
            '''
            dtc.boolean = False

            LEMS_MODEL_PATH = str(neuronunit.__path__[0]) + str(
                '/models/NeuroML2/LEMS_2007One.xml')
            dtc.model_path = LEMS_MODEL_PATH
            model = ReducedModel(dtc.model_path,
                                 name='vanilla',
                                 backend=(dtc.backend, {
                                     'DTC': dtc
                                 }))
            if dtc.backend is str('NEURON') or dtc.backend is str('jNEUROML'):
                dtc.current_src_name = model._backend.current_src_name
                assert type(dtc.current_src_name) is not type(None)
                dtc.cell_name = model._backend.cell_name

            params = {
                'injected_square_current': {
                    'amplitude': 100.0 * pq.pA,
                    'delay': DELAY,
                    'duration': DURATION
                }
            }

            ampl = float(dtc.ampl)
            if ampl not in dtc.lookup or len(dtc.lookup) == 0:
                uc = {'amplitude': ampl, 'duration': DURATION, 'delay': DELAY}

                dtc.run_number += 1
                model.set_attrs(**dtc.attrs)
                model.inject_square_current(uc)
                n_spikes = model.get_spike_count()

                dtc.previous = ampl

                if dtc.use_diff == True:
                    from neuronunit.tests import druckman2013 as dm
                    DM = dm.Druckmann2013Test()

                    #vm = model.get_membrane_potential()
                    spike_train = DM.get_APs(model)
                    #diff = diff(vm)
                    #spike_train = threshold_detection(diff,threshold= 0.000193667327364)
                    n_spikes = len(spike_train)

                    if n_spikes >= 1:
                        dtc.negative_spiker = None
                        dtc.negative_spiker = True

                else:
                    n_spikes = model.get_spike_count()

                if float(ampl) < -1.0:
                    dtc.rheobase = None
                    dtc.boolean = True
                    return dtc

                if n_spikes == 1:
                    dtc.lookup[float(ampl)] = 1
                    dtc.rheobase = float(ampl) * pq.pA
                    dtc.boolean = True
                    return dtc

                dtc.lookup[float(ampl)] = n_spikes
            return dtc