Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding get_native_parameters() method for Brian and modification of "… #552

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions pyNN/brian/standardmodels/electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def set_native_parameters(self, parameters):
object.__setattr__(self, name, value)
self._reset()

def get_native_parameters(self):
return ParameterSpace(dict((k, self.__getattr__(k)) for k in self.get_native_names()))

def _reset(self):
# self.i reset to 0 only at the start of a new run; not for continuation of existing runs
if not hasattr(self, 'running') or self.running == False:
Expand All @@ -105,14 +108,14 @@ def inject_into(self, cell_list):

def _update_current(self):
# check if current timestamp is within dt/2 of target time; Brian uses seconds as unit of time
if self.running and abs(simulator.state.t - self.times[self.i] * 1e3) < (simulator.state.dt/2.0):
if self.running and abs(simulator.state.t - self._times[self.i] * 1e3) < (simulator.state.dt/2.0):
for cell, idx in zip(self.cell_list, self.indices):
if not self._is_playable:
cell.parent.brian_group.i_inj[idx] = self.amplitudes[self.i] * ampere
else:
cell.parent.brian_group.i_inj[idx] = self._compute(self.times[self.i]) * ampere
cell.parent.brian_group.i_inj[idx] = self._compute(self._times[self.i]) * ampere
self.i += 1
if self.i >= len(self.times):
if self.i >= len(self._times):
self.running = False
if self._is_playable:
# ensure that currents are set to 0 after t_stop
Expand All @@ -130,7 +133,7 @@ def _get_data(self):
device = self.i_state_monitor
current_t_value = device.P.state_('t')[device.record]
current_i_value = device.P.state_(device.varname)[device.record]
t_all_values = numpy.append(device.times, current_t_value)
t_all_values = numpy.append(device._times, current_t_value)
i_all_values = numpy.append(device._values, current_i_value)
return (t_all_values / ms, i_all_values / nA)

Expand All @@ -142,6 +145,7 @@ class StepCurrentSource(BrianCurrentSource, electrodes.StepCurrentSource):
('amplitudes', 'amplitudes', nA),
('times', 'times', ms)
)

_is_computed = False
_is_playable = False

Expand All @@ -167,7 +171,7 @@ def __init__(self, **parameters):
def _generate(self):
# Note: Brian uses seconds as unit of time
temp_num_t = len(numpy.arange(self.start, self.stop + simulator.state.dt * 1e-3, simulator.state.dt * 1e-3))
self.times = numpy.array([self.start+(i*simulator.state.dt*1e-3) for i in range(temp_num_t)])
self._times = numpy.array([self.start+(i*simulator.state.dt*1e-3) for i in range(temp_num_t)])

def _compute(self, time):
# Note: Brian uses seconds as unit of time; frequency is specified in Hz; thus no conversion required
Expand All @@ -191,14 +195,14 @@ def __init__(self, **parameters):

def _generate(self):
if self.start == 0:
self.times = [self.start, self.stop]
self._times = [self.start, self.stop]
self.amplitudes = [self.amplitude, 0.0]
else:
self.times = [0.0, self.start, self.stop]
self._times = [0.0, self.start, self.stop]
self.amplitudes = [0.0, self.amplitude, 0.0]
# ensures proper handling of changes in parameters on the fly
if self.start < simulator.state.t*1e-3 < self.stop:
self.times.insert(-1, simulator.state.t*1e-3)
self._times.insert(-1, simulator.state.t*1e-3)
self.amplitudes.insert(-1, self.amplitude)
if (self.start==0 and self.i==2) or (self.start!=0 and self.i==3):
self.i -= 1
Expand All @@ -223,8 +227,8 @@ def __init__(self, **parameters):

def _generate(self):
temp_num_t = len(numpy.arange(self.start, self.stop, max(self.dt, simulator.state.dt * 1e-3)))
self.times = numpy.array([self.start+(i*max(self.dt, simulator.state.dt * 1e-3)) for i in range(temp_num_t)])
self.times = numpy.append(self.times, self.stop)
self._times = numpy.array([self.start+(i*max(self.dt, simulator.state.dt * 1e-3)) for i in range(temp_num_t)])
self._times = numpy.append(self._times, self.stop)

def _compute(self, time):
return self.mean + self.stdev * numpy.random.randn()
return self.mean + self.stdev * numpy.random.randn()