upstage_des.data_utils package#
Submodules#
upstage_des.data_utils.data_recorder module#
Class for custom recording of things.
- class DataRecorder#
Bases:
UpstageBase
An UpstageBase subclass to help with data recording.
- record_data(data: Any, copy: bool = False) None #
Record any data at this time for retrieval later.
The data recorded should be immutable or unchanging to preserve the values of the data at a given time. E.g. don’t supply an Actor or other objects that change. Dictionaries or dataclasses are fine as long as they are not used anywhere else.
A deepcopy parameter is supplied to get around this, but it may not work with all entities or objects.
- Parameters:
data (Any) – Any object or data to record.
copy (bool, optional) – Whether to attempt a deepcopy. Defaults to False.
- get_recorded_data() list[tuple[float, Any]] #
Return all data recorded with record_data or DataRecorder.
- Returns:
The data.
- Return type:
list[tuple[float, Any]]
- record_data(data: Any, copy: bool = False) None #
Record any data at this time for retrieval later.
The data recorded should be immutable or unchanging to preserve the values of the data at a given time. E.g. don’t supply an Actor or other objects that change. Dictionaries or dataclasses are fine as long as they are not used anywhere else.
A deepcopy parameter is supplied to get around this, but it may not work with all entities or objects.
This function must be run inside an environment context.
- Parameters:
data (Any) – Any object or data to record.
copy (bool, optional) – Whether to attempt a deepcopy. Defaults to False.
upstage_des.data_utils.data_utils module#
Utilities for gathering all recorded simulation data.
- create_location_table() tuple[list[tuple[str, str, str, float, float, float, float, str | None]], list[str]] #
Create a data table of every location UPSTAGE has recorded.
Assumes that all location types are the same.
This uses the current environment context.
Usage:
>>> import pandas as pd >>> with UP.EnvironmentContext() as env: >>> ... >>> env.run() >>> table, cols = create_location_table() >>> df = pd.DataFrame(table, cols)
- Returns:
Data table list[str]]: Column names.
- Return type:
list[LOCATION_DATA_ROW]
- create_table(skip_locations: bool = True, save_static: bool = False) tuple[list[tuple[str, str, str, float, Any, str | None]], list[str]] #
Create a data table of everything UPSTAGE has recorded.
This uses the current environment context.
- The data columns are:
Time, Entity Name, Entity Type, State Name, State Value
For SelfMonitoring<> resources that are not part of an actor, the name is pulled from the name entry to the resource. The Entity Type is the class name, and the State Name is “Resource State”.
Usage:
>>> import pandas as pd >>> with UP.EnvironmentContext() as env: >>> ... >>> env.run() >>> table, cols = create_table() >>> df = pd.DataFrame(table, cols)
- Parameters:
skip_locations (bool, optional) – If location states should be ignored. Defaults to True.
save_static (bool, optional) – If non-recording states are saved. Defaults to False.
- Returns:
Data table list[str]]: Column names.
- Return type:
list[STATE_DATA_ROW]
Module contents#
Utilities for data processing.