Time#

class Time(start=None, stop=None, dt=None, unit=None, pars=None, parent=None, name=None, init=True, sim=None)[source]#

Bases: prettyobj

Handle time vectors for both simulations and modules.

Parameters:
  • start (float/str/date) – the start date for the simulation/module

  • stop (float/str/date) – the end date for the simulation/module

  • dt (float) – the step size, in units of “unit”

  • unit (str) – the time unit; choices are “day”, “week”, “month”, “year”, or “unitless”

  • pars (dict) – if provided, populate parameter values from this dictionary

  • parent (obj) – if provided, populate missing parameter values from a ‘parent” Time instance

  • name (str) – if provided, name the Time object

  • init (bool) – whether or not to immediately initialize the Time object

  • sim (bool/Sim) – if True, initializes as a sim-specific Time instance; if a Sim instance, initialize the absolute time vector

The Time object, after initialization, has the following attributes:

  • ti (int): the current timestep

  • dt_year (float): the timestep in units of years

  • npts (int): the number of timesteps

  • tvec (array): time starting at 0, in self units (e.g. [0, 0.1, 0.2, ... 10.0] if start=0, stop=10, dt=0.1)

  • absvec (array): time relative to sim start, in units of sim units (e.g. [366, 373, 380, ...] if sim-start=2001, start=2002, sim-unit=’day’, unit=’week’)

  • yearvec (array): time represented as floating-point years (e.g. [2000, 2000.1, 2000.2, ... 2010.0] if start=2000, stop=2010, dt=0.1)

  • datevec (array): time represented as an array of ss.date objects (e.g. [<2000.01.01>, <2000.02.07>, ... <2010.01.01>] if start=2000, stop=2010, dt=0.1)

  • timevec (array): the “native” time vector, which always matches one of tvec, yearvec, or datevec

Examples:

t1 = ss.Time(start=2000, stop=2020, dt=1.0, unit='year') # Years, numeric units
t2 = ss.Time(start='2021-01-01', stop='2021-04-04', dt=2.0, unit='day') # Days, date units

Attributes

is_numeric

Check whether the fundamental simulation unit is numeric (as opposed to date-based)

is_unitless

ready

Check if all parameters are in place to be initialized

Methods

property ready#

Check if all parameters are in place to be initialized

property is_numeric#

Check whether the fundamental simulation unit is numeric (as opposed to date-based)

update(pars=None, parent=None, reset=True, force=None, **kwargs)[source]#

Reconcile different ways of supplying inputs

init(sim=None)[source]#

Initialize all vectors

make_abstvec(sim)[source]#

Convert the current time vector into sim units

now(key=None)[source]#

Get the current simulation time

Parameters:

which (str) – which type of time to get: default (None), “year”, “date”, “tvec”, or “str”

Examples:

t = ss.Time(start='2021-01-01', stop='2022-02-02', dt=1, unit='week')
t.ti = 25
t.now() # Returns <2021-06-25>
t.now('date') # Returns <2021-06-25>
t.now('year') # Returns 2021.479
t.now('str') # Returns '2021-06-25'