Working with external data : Time series : Case 7

Working with time series

There are two principle means of loading time series data into a model, depending on whether it is desired to store the data in the model itself, in which case the table(…) function is used, or whether the data are to be read from an external file, in which case a scenario file is appropriate. It is also possible to enter the data directly into an array, which may be convenient if there are only a few rows of data.

Using an intermediate array

Whichever way the data are provided, they are stored in an array. The following procedure is suitable for transforming the array into a time series.

  1. Make a scalar variable (i.e. not an array) whose value is to change each time-step.
  2. Draw an influence from the time-series array to the scalar variable.
  3. Set the equation for the scalar variable to:

    element([time_series], time()+1)

    where [time_series] is any array that is being used to store values for the time-series.

This procedure selects one value from the array, in the row corresponding to the current simulation time. Note that in the sub-expression time()+1, the +1 is to account for array indices starting at 1, whilst the simulation begins at time()=0.

Using a file directly

The following procedure is used:

  1. Create the file in comma-separated value (CSV) format.
  2. In your model, set the variable to be a "Variable parameter". You must enter maximum and minimum values here, to allow the parameter to be set using a slider.
  3. Build the model.
  4. From the File menu of the Run Control, select the "Parameters..." command. If you are using the single-window execution environment, there is also a toolbar button to display the parameter dialogue.
  5. From the resulting parameter dialogue box, click the "Get values from file" button (with the pencil icon) next to the variable name.
  6. Create a table in the usual way, with or without an index, depending on how the values in the file are distributed with respect to time. You will need an index if the values do not correspond to times 1, 2, 3 etc.
  7. Click OK.
  8. Click the reset (stop) button.

This last step is necessary to re-set the model to use the new parameters at zero time. If you do not do this, a warning will be issued. Note that the index can start from zero.

Time series values do not have to be at regular intervals - for example, if you give a variable parameter the time series:

#0: 1 #20: 2 #80: 3

then it will change on reset and at times 20 and 80 but keep its previous value (or respond to slider input) at other times.

Getting a time series to repeat

If you want your time series values to be used again after a certain period of time, there are two ways to do this. If editing the list directly in the file parameter dialogue, you can end it with, e.g.,

#100: restart

to cause the values to restart from 0 at time 100. This must be at the end of the line.

If you are loading the values from a .csv file, then the load file dialogue will include an entry box labelled "Wraparound at:" into which you can enter a time at which to restart the time series. Doing either of these will cause the time series to repeat indefinitely over the specified period as the model runs.

In: Contents >> Working with external data