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

Issue with current injection via ACSource in Brian #442

Closed
appukuttan-shailesh opened this issue Feb 2, 2017 · 4 comments
Closed

Issue with current injection via ACSource in Brian #442

appukuttan-shailesh opened this issue Feb 2, 2017 · 4 comments
Milestone

Comments

@appukuttan-shailesh
Copy link
Contributor

appukuttan-shailesh commented Feb 2, 2017

There is a problem with the output of current injection via ACSource in Brian. The current profile is incorrect (as can be inferred from the voltage trace in below figure), and also the current injection fails to cease at t_stop.

The figure below illustrates this (for this source code):

Brian Output:
ac_brian_bad

NEURON Output:
ac_neuron_good

@appukuttan-shailesh
Copy link
Contributor Author

The problems here are similar to those described in issue #437. The solution for ensuring that current injection stops at t_stop is same as that discussed there.

Brian requires time to be specified with units of seconds. Most of the required conversion is done, except for simulator.state.dt which is still specified in ms, and the frequency which is converted to 1/ms. To fix this, we need to update the following:

i) method _generate() in line https://github.com/NeuralEnsemble/PyNN/blob/master/pyNN/brian/standardmodels/electrodes.py#L114
from:

self.times = numpy.arange(self.start, self.stop, simulator.state.dt)

to:

self.times = numpy.arange(self.start, self.stop, simulator.state.dt * 1e-3)

ii) method _compute() in line https://github.com/NeuralEnsemble/PyNN/blob/master/pyNN/brian/standardmodels/electrodes.py#L117
from:

return self.amplitude * numpy.sin(time * 2 * numpy.pi * self.frequency / 1000. + 2 * numpy.pi * self.phase / 360)

to:

return self.amplitude * numpy.sin(time * 2 * numpy.pi * self.frequency + 2 * numpy.pi * self.phase / 360)

Brian output with above fixes:

ac_brian_fixed

@appukuttan-shailesh
Copy link
Contributor Author

If the alternative fix for problem 1 in issue #437 is adopted, then the method '_generate' in line https://github.com/NeuralEnsemble/PyNN/blob/master/pyNN/brian/standardmodels/electrodes.py#L114 should be changed from:

def _generate(self):
        self.times = numpy.arange(self.start, self.stop, simulator.state.dt)

to

def _generate(self):
    self.times = numpy.arange(self.start, self.stop, simulator.state.dt * 1e-3)
    self.times = numpy.append(self.times, self.stop)

Note: Issue #445 would need to be fixed for this to work properly.

@appukuttan-shailesh
Copy link
Contributor Author

Found two more issues with current injection via AC source, as seen in the below outputs:
Note: start = 47.5 ms and offset = 0.1

NEURON output:
neuron_good_stop47 5_offset0 1

Brian output:
brian_bad_stop47 5_offset0 1

The issues are:

  1. Brian implementation evaluates current amplitudes with times from t = 0 ms, instead of from t = t_start
  2. Brian implementation is not taking into consideration the parameter 'offset' while evaluating the amplitudes

Combined fix for all of the above

Methods _generate() and _compute() for the class ACSource in file https://github.com/NeuralEnsemble/PyNN/blob/master/pyNN/brian/standardmodels/electrodes.py
needs to be updated to:

def _generate(self):
        self.times = numpy.arange(self.start, self.stop + simulator.state.dt * 1e-3, simulator.state.dt * 1e-3)

def _compute(self, time):
        return self.offset + self.amplitude * numpy.sin((time-self.start) * 2 * numpy.pi * self.frequency + 2 * numpy.pi * self.phase / 360)

Brian output with above fix:
brian_fixed_stop47 5_offset0 1

@apdavison
Copy link
Member

Fixed in #467

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants