# Time dependent rate for PoissinGroup

**URL:** <https://brian.discourse.group/t/time-dependent-rate-for-poissingroup/236>\
**Category:** Support\
**Created:** [17 December 2020 14:39 UTC](https://brian.discourse.group/t/time-dependent-rate-for-poissingroup/236 "2020-12-17T14:39:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ziaeemehr](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/ziaeemehr/32/12_2.png) [@Ziaeemehr](https://brian.discourse.group/u/Ziaeemehr)\
**Post date:** [17 December 2020 14:39 UTC](https://brian.discourse.group/t/time-dependent-rate-for-poissingroup/236/1 "2020-12-17T14:39:33Z")

</div>

Hi,  
I am converting an old Brian1 code to the current version. It has a rate to `PossonGroup` like this:

```python
sim_duration = 1000
stimulus = sin(arange(0, sim_duration)*2*pi/sim_duration)

def input_rates(t):
        '''
        Returns firing rates for spatially patterned stimulus to E cells.  
        stimulus is array of stimulus orientations as function of time in ms.
        Range of stimulus is 0 - 1.
        '''
        return 400*(1+0.35* cos(2*pi*stimulus[floor(t*1000) 
                                % size (stimulus)] + pi + linspace(2*pi/N], 2*pi,N)))*Hz

poisson_to_E = PoissonGroup(N, input_rates)

```

So the `input _rates` give an array of size N at each time step, right?  
and for the current version should be converted to something like this:

```python
input_rates = b2.TimedArray(400.0*(1 + 0.35 * np.cos(2*pi*stimulus[int(floor(t*1000) % stimulus.size)]))*b2.Hz, dt=dt0)

```

Making an array stimulus at each time step is not clear for me.

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [17 December 2020 16:49 UTC](https://brian.discourse.group/t/time-dependent-rate-for-poissingroup/236/2 "2020-12-17T16:49:55Z")

</div>

Hi. Brian 1 required you to think of things in terms of indices and matrices, while Brian 2 uses an approach that abstracts away the implementation and focuses on the mathematical formulation.

In principle, you could have a 2D array as the `TimedArray` which would be the closest to the Brian 1 solution. It would look like this (assuming that the dt is 0.1ms and the 1000 steps in the stimulus array therefore correspond to 100ms):

```auto
sim_duration = 1000
N = 50
stimulus = sin(arange(0, sim_duration)*2*pi/sim_duration)
input_rates = b2.TimedArray(400.0*(1 + 0.35 * np.cos(2*pi*stimulus[:, None] +
                                                     np.pi + np.linspace(2*pi/N, 2*pi, N)))*b2.Hz, dt=dt0)

poisson_to_E = PoissonGroup(N, rates='input_rates(t % (100*ms), i)')

```

But in this specific case there is no need to pre-generate the stimulus and store it in a `TimedArray`. Brian 2’s string syntax is powerful enough to calculate the rates during the simulation by expressing them as a function of time and the neuron index:

```auto
poisson_to_E = PoissonGroup(N, rates='400.0*(1 + 0.35 * cos(2*pi*sin(2*pi*t/(100*ms)) + pi +'
                                                           '2*pi/N + (1.0*i/N)*2*pi))*Hz')

```

(Not 100% sure it is correct, but you get the idea).

```auto

```

---

<div class="post-metadata">

**Author:** ![Ziaeemehr](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/ziaeemehr/32/12_2.png) [@Ziaeemehr](https://brian.discourse.group/u/Ziaeemehr)\
**Post date:** [17 December 2020 17:01 UTC](https://brian.discourse.group/t/time-dependent-rate-for-poissingroup/236/3 "2020-12-17T17:01:35Z")

</div>

Great! Thank you Marcel for quick replay.
