# How to obtain the current time index in Programmable Source

**URL:** https://discourse.paraview.org/t/how-to-obtain-the-current-time-index-in-programmable-source/11268
**Category:** ParaView Support
**Tags:** python
**Created:** [January 25, 2023, 2:59pm UTC](https://discourse.paraview.org/t/how-to-obtain-the-current-time-index-in-programmable-source/11268 "2023-01-25T14:59:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![robertsawko](https://discourse.paraview.org/user_avatar/discourse.paraview.org/robertsawko/32/6283_2.png) [@robertsawko](https://discourse.paraview.org/u/robertsawko)
#### Post date: [January 25, 2023, 2:59pm UTC](https://discourse.paraview.org/t/how-to-obtain-the-current-time-index-in-programmable-source/11268/1 "2023-01-25T14:59:44Z")

</div>

Hello,

I am prototyping a reader for a code which generates one file per time step. Using advice from [here](https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html#reading-a-csv-file-series), I was able to correctly read the number of time steps to my Programmable Source and I know I can read the current time step using the helper function below:

```python
#...

def GetUpdateTimestep(algorithm):
    """Returns the requested time value, or None if not present"""
    executive = algorithm.GetExecutive()
    output_info = executive.GetOutputInformation(0)

    return output_info.Get(executive.UPDATE_TIME_STEP()) \
        if output_info.Has(executive.UPDATE_TIME_STEP()) else None

```

How to obtain the time index instead of the time step value? The indices are clearly displayed in the Information tab of the object.

PS Slightly unrelated, but is it possible to also save the file list in `vtkInformation` or elsewhere?

---

<div class="post-metadata">

### Author: ![robertsawko](https://discourse.paraview.org/user_avatar/discourse.paraview.org/robertsawko/32/6283_2.png) [@robertsawko](https://discourse.paraview.org/u/robertsawko)
#### Post date: [February 2, 2023, 5:11pm UTC](https://discourse.paraview.org/t/how-to-obtain-the-current-time-index-in-programmable-source/11268/2 "2023-02-02T17:11:57Z")

</div>

I came up with something which may be very crude, but it works for my current scenario:

```python
def get_update_timestep(algorithm):
    executive = algorithm.GetExecutive()
    output_info = executive.GetOutputInformation(0)
    if output_info.Has(executive.UPDATE_TIME_STEP()) is False:
        return None

    requested_time = output_info.Get(executive.UPDATE_TIME_STEP())
    time_steps = output_info.Get(executive.TIME_STEPS())
    return time_steps.index(requested_time)

```

This will return `None` in cases when the requested time step is not present! I could improve this, by making sure I select the nearest neighbour.

Perhaps my original request was impossible, because of the way VTK handles time as metadata. My current understanding is that `vtkExecutive` may receive requests for times that are not necessarily in the dataset it handles. Inside ParaView, this could happen, I think, where there are multiple data sources registering different time series information.
