Python IndependentObservations Example

Introduction

The python independentobservations example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: Python

Namespace/package name: optofitobservationobservable

Example#1
File: new_model_demo.pyProject: HIPS/optofit

def make_model():
    """Make a model of a single compartment neuron with a handful of channels and a directly
    observable voltage
    """
    model = Model()
    # The population object doesn't do anything yet, but eventually it could support
    # synapses between neurons
    population = Population('population', model)
    # Explicitly build the neuron
    neuron = Neuron('neuron', population)
    # The single compartment corresponds to the cell body
    body = CalciumCompartment('body', neuron)
    # Add a few channels
    leak = LeakChannel('leak', body)

    ca3kdr = Ca3KdrChannel('ca3kdr', body)
    ca3ka = Ca3KaChannel('ca3ka', body)
    ca3na = Ca3NaChannel('ca3na', body)
    ca3ca = Ca3CaChannel('ca3ca', body)
    ca3kahp = Ca3KahpChannel('ca3kahp', body)
    ca3kc = Ca3KcChannel('ca3kc', body)
    chr2 = ChR2Channel('chr2', body)

    # Now connect all the pieces of the neuron together
    body.add_channel(leak)
    # body.add_channel(na)
    # body.add_channel(kdr)

    body.add_channel(ca3kdr)
    body.add_channel(ca3ka)
    body.add_channel(ca3na)
    body.add_channel(ca3ca)
    body.add_channel(ca3kahp)
    body.add_channel(ca3kc)
    body.add_channel(chr2)

    neuron.add_compartment(body, None)
    population.add_neuron(neuron)
    model.add_population(population)

    # Create the observation model
    observation = IndependentObservations('observations', model)
    # Direct voltage measurement
    # body_voltage = NewDirectCompartmentVoltage('body voltage', model, body)
    # observation.add_observation(body_voltage)

    # Low pass filtered voltage measurement
    lp_body_voltage = LowPassCompartmentVoltage('lp body voltage', model, body, filterbins=2)
    observation.add_observation(lp_body_voltage)

    # Fluorescence (linearly scaled voltage) measurement
    # body_fluorescence = LinearFluorescence('body fluorescence' , model, body)
    # observation.add_observation(body_fluorescence)

    model.add_observation(observation)

    return model

Example#2
File: geweke_test.pyProject: HIPS/optofit

def make_model():
    """Make a model of a single compartment neuron with a handful of channels and a directly
    observable voltage
    """
    model = Model()
    # The population object doesn't do anything yet, but eventually it could support
    # synapses between neurons
    population = Population('population', model)
    # Explicitly build the neuron
    neuron = Neuron('neuron', population)
    # The single compartment corresponds to the cell body
    body = Compartment('body', neuron)
    # body = CalciumCompartment('body', neuron)
    # Add a few channels
    # body.add_channel(LeakChannel('leak', body))
    # body.add_channel(NaChannel('na', body))
    body.add_channel(KdrChannel('kdr', body))


    # ca3kdr = Ca3KdrChannel('ca3kdr', body)
    # ca3ka = Ca3KaChannel('ca3ka', body)
    # ca3na = Ca3NaChannel('ca3na', body)
    # ca3ca = Ca3CaChannel('ca3ca', body)
    # ca3kahp = Ca3KahpChannel('ca3kahp', body)
    # ca3kc = Ca3KcChannel('ca3kc', body)
    #
    #body.add_channel(ca3kdr)
    #body.add_channel(ca3ka)
    #body.add_channel(ca3na)
    #body.add_channel(ca3ca)
    #body.add_channel(ca3kahp)
    #body.add_channel(ca3kc)

    # Now connect all the pieces of the neuron together
    neuron.add_compartment(body, None)
    population.add_neuron(neuron)
    model.add_population(population)

    # Create the observation model
    observation = IndependentObservations('observations', model)
    body_voltage = NewDirectCompartmentVoltage('body voltage', model, body)
    # body_fluorescence = LinearFluorescence('body fluorescence' , model, body)
    # observation.add_observation(body_fluorescence)
    observation.add_observation(body_voltage)
    model.add_observation(observation)

    return model

Example#3
File: bayes_opt_target.pyProject: HIPS/optofit

def params_to_model(params):
    model = Model()
    population = Population('population', model)
    neuron     = Neuron('neuron', population)
    body       = CalciumCompartment('body', neuron)

    channel_constructor_dict = {
        u'leak': LeakChannel,
        u'ca3kdr': Ca3KdrChannel,
        u'ca3ka': Ca3KaChannel,
        u'ca3na': Ca3NaChannel,
        u'ca3ca': Ca3CaChannel,
        u'ca3kahp': Ca3KahpChannel,
        u'ca3kc': Ca3KcChannel,
        u'chr2': ChR2Channel
    }

    for ch, g in params.iteritems():
        if ch in channel_constructor_dict:
            channel = channel_constructor_dict[ch](
                ch.encode('ascii', 'ignore'), body,
                Parameter('g_' + ch.encode('ascii', 'ignore'), g.tolist()[0] ,lb=0.0),
            )
            body.add_channel(channel)
        else:
            print "Warning: ", ch, " not in dict"

    neuron.add_compartment(body, None)
    population.add_neuron(neuron)
    model.add_population(population)

    observation = IndependentObservations('observations', model)
    lp_body_voltage = LowPassCompartmentVoltage('lp body voltage', model, body, filterbins=20)
    #import pdb; pdb.set_trace()
    lp_body_voltage.sigma.value = params[u'sigma']
    observation.add_observation(lp_body_voltage)
    model.add_observation(observation)
    return model