# Pass current timestep to affect! to modify integrator values with lookup table

**URL:** <https://discourse.julialang.org/t/pass-current-timestep-to-affect-to-modify-integrator-values-with-lookup-table/100617>\
**Category:** Modelling & Simulations\
**Created:** [June 20, 2023, 6:07pm UTC](https://discourse.julialang.org/t/pass-current-timestep-to-affect-to-modify-integrator-values-with-lookup-table/100617 "2023-06-20T18:07:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidanboyne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aidanboyne/32/45502_2.png) [@aidanboyne](https://discourse.julialang.org/u/aidanboyne)\
**Post date:** [June 20, 2023, 6:07pm UTC](https://discourse.julialang.org/t/pass-current-timestep-to-affect-to-modify-integrator-values-with-lookup-table/100617/1 "2023-06-20T18:07:46Z")

</div>

I am trying to simulate patient response to a drug and am currently fitting a model to patient data. However the frequency and strength of the dose changes frequently, so I have the time and strength for each dose recorded in a dataframe. Is it possible to pass the current timestep `t` to `affect!` so that it can lookup the value in the table?

```julia
example_doses = DataFrame([[0,3,10,40], [50,88,88,12]], ["time", "dose"])

function condition(u, t, integrator)
    t in example_doses.time
end

function affect!(integrator)
    integrator.u[10] = example_doses.dose[findfirst(==(t), example_doses.time)]
end

cb = ContinuousCallback(condition, affect!)

```

Note the actual doses dataframe has \> 1000 rows and this must be simulated for many patients, so as far as I can see storing the doses in the integrator parameters to be accessed via integrator.p as mentioned [here](https://discourse.julialang.org/t/pass-additional-parameters-to-affect-in-solving-odes/29755) is not practical.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 21, 2023, 2:51am UTC](https://discourse.julialang.org/t/pass-current-timestep-to-affect-to-modify-integrator-values-with-lookup-table/100617/2 "2023-06-21T02:51:50Z")

</div>

> [@aidanboyne](#):
>
> Is it possible to pass the current timestep `t` to `affect!` so that it can lookup the value in the table?

it’s just `integrator.t` to get the current time.

Though note that if you’re going to do this you need to set `tstop`. You may want to use the `PresetTimeCallback` for this.

---

<div class="post-metadata">

**Author:** ![aidanboyne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aidanboyne/32/45502_2.png) [@aidanboyne](https://discourse.julialang.org/u/aidanboyne)\
**Post date:** [June 21, 2023, 3:02am UTC](https://discourse.julialang.org/t/pass-current-timestep-to-affect-to-modify-integrator-values-with-lookup-table/100617/3 "2023-06-21T03:02:03Z")

</div>

Thanks Chris, this was exactly what I was looking for.
