# timeseries_inputs

Named time-series profiles read by TS("name") in any expression.

In the model file this key holds a list of `timeseries_input` entries, each named by its `name`.

A scenario, an experiment or an optimizer can set a field by the path `timeseries_inputs.<name>.<field>`.

## Typical uses

These sections hold the values that expressions read. `variables` are numbers that a model changes while it runs. `tables` are fixed lookups by one or two keys. `timeseries_inputs` are profiles over time, such as a tariff or a demand curve. `entities` describe the entity types: how they look and what holding them costs.

## Behaviour and rules

A variable is read as a bare name in an expression and written by an ASSIGN block. Its `initial` value is restored at the start of every replication. A table is read with `TABLE("name", key)` or with two keys for a 2-D table. The `key_mode` decides what happens between keys: `exact`, `step` or `linear`. A missing exact key is a run-time error unless the table has a `default`.

A time series is read with `TS("name")` for now, or with a second argument for another time. Its `interpolation` is `step` by default, which is exact for a rate. Past the last sample, `beyond` decides whether the last value holds, the series repeats, or the run stops with an error. Sample times must increase.

An entity type is named by the `e_type` of a CREATE block. A `holding_cost` charges each entity for the time it spends in the system, from its creation to its disposal, and only time after the warm-up counts.

## Fields

| Field | Type | Required | Default | Unit | Description |
|---|---|---|---|---|---|
| `name` | string | yes |  |  | The profile's name, the first argument of TS("name"). |
| `description` | string |  |  |  | What the profile holds; the run does not read it. |
| `values` | list of number | yes |  |  | One number per sample. |
| `times` | list of number |  |  | time (`time_unit`) | Sample times, strictly increasing; exclusive with "step". |
| `start` | number or string |  | `0.0` | time (`time_unit`) | Time of the first sample of a regular series. An ISO timestamp instead of a number dates the series against "simulation.calendar". |
| `timestamps` | list of string |  |  |  | Real ISO sample instants instead of "times"; converted once at build. |
| `step` | number |  |  | time (`time_unit`) | Spacing of a regular series; exclusive with "times". |
| `time_unit` | choice |  | `"base"` |  | Unit the sample times are expressed in. One of `base`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `weeks`, `months`, `years`. |
| `interpolation` | choice |  | `"step"` |  | step: piecewise constant (exact for a flow rate). linear: interpolate between samples. One of `step`, `linear`. |
| `beyond` | choice |  | `"hold"` |  | Past the last sample: hold the last value, repeat the series with its period, or refuse. One of `hold`, `repeat`, `error`. |
| `period` | number or choice |  |  | time (`time_unit`) | Cycle length "repeat" wraps on; defaults to step * len(values), or times[-1] - times[0]. "daily"/"weekly"/"yearly" need a calendar. |

A field of a nested object is described in the JSON Schema (`naga schema`).

## Example

```json
{"timeseries_inputs": [{"name": "Sun", "start": 0, "step": 1, "time_unit": "hours", "values": [0, 0.2, 0.8, 1.0]}]}
```

In the Python builder:

```python
from nagasim import build as nb
m = nb.Model()
m.add_timeseries_input(name='Sun', start=0, step=1, time_unit='hours', values=[0, 0.2, 0.8, 1.0])
```

## Used in

Bundled models: [Berth: shore power](../../gallery/energy.md), [Biogas digester, holder and CHP](../../gallery/energy.md), [Biogas plant (library assets)](../../gallery/energy.md), [Depot: PV, EV charging and heat pump](../../gallery/energy.md), [PV + battery sizing and dispatch](../../gallery/energy.md), [PV + battery site (library assets)](../../gallery/energy.md) and 4 more.

Guides: [Continuous quantities: levels, flows and time-series inputs](../../modelling-guide/continuous-quantities.md), [Model file format](../../model-file-format.md), [Dates and calendars](../../modelling-guide/dates-and-calendars.md), [Semantic diff](../../semantic-diff.md).

## See also

- [All sections](index.md), [Model file keys](../schema.md), [Model file format](../../model-file-format.md)
