6.5. pypfilt.time¶
Two pre-defined simulation time scales are provided.
-
class
pypfilt.time.
Scalar
(np_dtype=None)¶ A dimensionless time scale.
-
__init__
(np_dtype=None)¶ Parameters: np_dtype – The data type used for serialisation; the default is np.float64
.
-
set_period
(start, end, steps_per_unit)¶ Define the simulation period and time-step size.
Parameters: - start (float) – The start of the simulation period.
- end (float) – The end of the simulation period.
- steps_per_unit (int) – The number of time-steps per day.
Raises: ValueError – if
start
and/orend
are not floats, or ifsteps_per_unit
is not a positive integer.
-
with_observation_tables
(ctx, obs_tables)¶ Return a generator that yields a sequence of tuples that contain: the time-step number, the current time, and a list of observations.
Parameters: - ctx (pypfilt.Context) – The simulation context.
- obs_tables (Dict[str, numpy.ndarray]) – The observation data tables.
-
with_observation_tables_from_time
(ctx, obs_tables, start)¶ Return a generator that yields a sequence of tuples that contain: the time-step number, the current time, and a list of observations.
Parameters: - ctx (pypfilt.Context) – The simulation context.
- obs_tables (Dict[str, numpy.ndarray]) – The observation data tables.
- start – The starting time (set to
None
to use the start of the simulation period).
-
-
class
pypfilt.time.
Datetime
(fmt=None, date_fmt=None)¶ A
datetime
scale where the time unit is days.-
__init__
(fmt=None, date_fmt=None)¶ Parameters: - fmt – The format string used to serialise
datetime
objects; the default is'%Y-%m-%d %H:%M:%S'
. - date_fmt – The format string used to read
date
objects; the default is'%Y-%m-%d'
.
- fmt – The format string used to serialise
-
set_period
(start, end, steps_per_unit)¶ Define the simulation period and time-step size.
Parameters: - start (datetime.datetime) – The start of the simulation period.
- end (datetime.datetime) – The end of the simulation period.
- steps_per_unit (int) – The number of time-steps per day.
Raises: ValueError – if
start
and/orend
are notdatetime.datetime
instances, or ifsteps_per_unit
is not a positive integer.
-
with_observation_tables
(ctx, obs_tables)¶ Return a generator that yields a sequence of tuples that contain: the time-step number, the current time, and a list of observations.
Parameters: - ctx (pypfilt.Context) – The simulation context.
- obs_tables (Dict[str, numpy.ndarray]) – The observation data tables.
-
with_observation_tables_from_time
(ctx, obs_tables, start)¶ Return a generator that yields a sequence of tuples that contain: the time-step number, the current time, and a list of observations.
Parameters: - ctx (pypfilt.Context) – The simulation context.
- obs_tables (Dict[str, numpy.ndarray]) – The observation data tables.
- start – The starting time (set to
None
to use the start of the simulation period).
-
6.5.1. Custom time scales¶
If neither of the above time scales is suitable, you can define a custom time scale, which should derive the following base class and define the methods listed here:
-
class
pypfilt.time.
Time
¶ The base class for simulation time scales, which defines the minimal set of methods that are required.
-
dtype
(name)¶ Define the dtype for columns that store times.
-
native_dtype
()¶ Define the Python type used to represent times in NumPy arrays.
-
is_instance
(value)¶ Return whether
value
is an instance of the native time type.
-
to_dtype
(time)¶ Convert from time to a dtype value.
-
from_dtype
(dval)¶ Convert from a dtype value to time.
-
to_unicode
(time)¶ Convert from time to a Unicode string.
This is used to define group names in HDF5 files, and for logging.
-
from_unicode
(val)¶ Convert from a Unicode string to time.
This is used to parse group names in HDF5 files.
-
column
(name)¶ Return a tuple that can be used with
read_table()
to convert a column into time values.
-
steps
()¶ Return a generator that yields a sequence of time-step numbers and times (represented as tuples) that span the simulation period.
The first time-step should be numbered 1 and occur at a time that is one time-step after the beginning of the simulation period.
-
step_count
()¶ Return the number of time-steps required for the simulation period.
-
step_of
(time)¶ Return the time-step number that corresponds to the specified time.
-
add_scalar
(time, scalar)¶ Add a scalar quantity to the specified time.
-
time_of_obs
(obs)¶ Return the time associated with an observation.
-