Skip to content

Commit

Permalink
Rename the equations keyword argument to model (as in Brian 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Jul 12, 2013
1 parent df8aeaa commit 614d150
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
28 changes: 14 additions & 14 deletions brian2/groups/neurongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class NeuronGroup(BrianObject, Group, SpikeSource):
----------
N : int
Number of neurons in the group.
equations : (str, `Equations`)
model : (str, `Equations`)
The differential equations defining the group
method : (str, function), optional
The numerical integration method. Either a string with the name of a
Expand Down Expand Up @@ -177,7 +177,7 @@ class NeuronGroup(BrianObject, Group, SpikeSource):
attribute is set to 0 initially, but this can be modified using the
attributes `state_updater`, `thresholder` and `resetter`.
'''
def __init__(self, N, equations, method=None,
def __init__(self, N, model, method=None,
threshold=None,
reset=None,
refractory=False,
Expand All @@ -196,22 +196,22 @@ def __init__(self, N, equations, method=None,
raise ValueError("NeuronGroup size should be at least 1, was " + str(N))

##### Prepare and validate equations
if isinstance(equations, basestring):
equations = Equations(equations)
if not isinstance(equations, Equations):
raise TypeError(('equations has to be a string or an Equations '
'object, is "%s" instead.') % type(equations))
if isinstance(model, basestring):
model = Equations(model)
if not isinstance(model, Equations):
raise TypeError(('model has to be a string or an Equations '
'object, is "%s" instead.') % type(model))

# Check flags
equations.check_flags({DIFFERENTIAL_EQUATION: ('unless-refractory'),
PARAMETER: ('constant')})
model.check_flags({DIFFERENTIAL_EQUATION: ('unless-refractory'),
PARAMETER: ('constant')})

# add refractoriness
equations = add_refractoriness(equations)
self.equations = equations
uses_refractoriness = len(equations) and any(['unless-refractory' in eq.flags
for eq in equations.itervalues()
if eq.type == DIFFERENTIAL_EQUATION])
model = add_refractoriness(model)
self.equations = model
uses_refractoriness = len(model) and any(['unless-refractory' in eq.flags
for eq in model.itervalues()
if eq.type == DIFFERENTIAL_EQUATION])

logger.debug("Creating NeuronGroup of size {self.N}, "
"equations {self.equations}.".format(self=self))
Expand Down
26 changes: 13 additions & 13 deletions brian2/synapses/synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class Synapses(BrianObject, Group):
target : `Group`, optional
The target of the spikes, typically a `NeuronGroup`. If none is given,
the same as `source`
equations : {`str`, `Equations`}, optional
model : {`str`, `Equations`}, optional
The model equations for the synapses.
pre : {str, dict}, optional
The code that will be executed after every pre-synaptic spike. Can be
Expand Down Expand Up @@ -582,7 +582,7 @@ class Synapses(BrianObject, Group):
The name for this object. If none is given, a unique name of the form
``synapses``, ``synapses_1``, etc. will be automatically chosen.
'''
def __init__(self, source, target=None, equations=None, pre=None, post=None,
def __init__(self, source, target=None, model=None, pre=None, post=None,
connect=False, delay=None, namespace=None, dtype=None,
language=None, clock=None, method=None, name='synapses*'):

Expand All @@ -600,25 +600,25 @@ def __init__(self, source, target=None, equations=None, pre=None, post=None,
self.target = weakref.proxy(target)

##### Prepare and validate equations
if equations is None:
equations = ''
if model is None:
model = ''

if isinstance(equations, basestring):
equations = Equations(equations)
if not isinstance(equations, Equations):
raise TypeError(('equations has to be a string or an Equations '
'object, is "%s" instead.') % type(equations))
if isinstance(model, basestring):
model = Equations(model)
if not isinstance(model, Equations):
raise TypeError(('model has to be a string or an Equations '
'object, is "%s" instead.') % type(model))

# Check flags
equations.check_flags({DIFFERENTIAL_EQUATION: ['event-driven', 'lumped'],
STATIC_EQUATION: ['lumped'],
PARAMETER: ['constant', 'lumped']})
model.check_flags({DIFFERENTIAL_EQUATION: ['event-driven', 'lumped'],
STATIC_EQUATION: ['lumped'],
PARAMETER: ['constant', 'lumped']})

# Separate the equations into event-driven and continuously updated
# equations
event_driven = []
continuous = []
for single_equation in equations.itervalues():
for single_equation in model.itervalues():
if 'event-driven' in single_equation.flags:
if 'lumped' in single_equation.flags:
raise ValueError(('Event-driven variable %s cannot be '
Expand Down
2 changes: 1 addition & 1 deletion brian2/tests/test_neurongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_creation():
A basic test that creating a NeuronGroup works.
'''
for language in languages:
G = NeuronGroup(42, equations='dv/dt = -v/(10*ms) : 1', reset='v=0',
G = NeuronGroup(42, model='dv/dt = -v/(10*ms) : 1', reset='v=0',
threshold='v>1', language=language)
assert len(G) == 42

Expand Down
2 changes: 1 addition & 1 deletion examples/I-F_curve_Hodgkin_Huxley.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
I : amp
''')
# Threshold and refractoriness are only used for spike counting
group = NeuronGroup(N, equations=eqs, threshold='is_active * (v > -40*mV)',
group = NeuronGroup(N, model=eqs, threshold='is_active * (v > -40*mV)',
language=language)
group.refractory = 1*ms
group.v = El
Expand Down
2 changes: 1 addition & 1 deletion examples/I-F_curve_LIF.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
dv/dt=(v0-v)/tau : volt (unless-refractory)
v0 : volt
'''
group = NeuronGroup(N, equations=eqs, threshold='v>10 * mV',
group = NeuronGroup(N, model=eqs, threshold='v>10 * mV',
reset='v = 0 * mV', refractory=5*ms)
group.v = 0 * mV
group.v0 = linspace(0 * mV, 20 * mV, N)
Expand Down
2 changes: 1 addition & 1 deletion examples/non_reliability.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
eqs_neurons = '''
dx/dt=(1.1-x)/tau+sigma*(2./tau)**.5*xi:1
'''
neurons = NeuronGroup(N, equations=eqs_neurons, threshold='x>1', reset='x=0')
neurons = NeuronGroup(N, model=eqs_neurons, threshold='x>1', reset='x=0')
neurons.refractory = 5*ms
spikes = SpikeMonitor(neurons)

Expand Down
2 changes: 1 addition & 1 deletion examples/phase_locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
dv/dt=(-v+a*sin(2*pi*freq*t)+b)/tau : 1
a : 1
'''
neurons = NeuronGroup(N, equations=eqs, threshold='v>1', reset='v=0')
neurons = NeuronGroup(N, model=eqs, threshold='v>1', reset='v=0')
neurons.v = rand(N)
neurons.a = linspace(.05, 0.75, N)
S = SpikeMonitor(neurons)
Expand Down

0 comments on commit 614d150

Please sign in to comment.