Karana.KUtils#

Simulation utilities such as data logging and data plotting.

Submodules#

Classes#

H5Writer

@class H5Writer Logs data to an HDF5 file. The data to be logged is

PacketTableConfig

@class PacketTableConfig Define the columns and associated update

Package Contents#

class Karana.KUtils.H5Writer(filename: str)#

Bases: Karana.Core.Base

@class H5Writer Logs data to an HDF5 file. The data to be logged is configured via `PacketTableConfig`s.

static create(filename: str) H5Writer#

Create an H5Writer class.

Parameter filename:

The name of the h5 file to create.

Returns:

A ks_ptr to the newly created instance of H5Writer.

activateTable(name: str) None#

Activate the table with the given name.

Parameter name:

The name of the table to activate.

activeTableNames() list[str]#

Get a vector of the active table names.

Returns:

A vector of the active table names.

createTable(config: PacketTableConfig) None#

Create a packet table to log.

This creates the table and adds it to the active tables. Activate tables will have a data entry added whenever log is called. To deactivate a table use the deactivateTable method. The name of the tame will be the same as the name of the PacketTableConfig.

Parameter config:

The config that specifies the data of the packet table.

deactivateTable(name: str) None#

Deactivate the table with the given name.

Parameter name:

The name of the table to deactivate.

log() None#

Log data for all the active tables.

logTable(name: str) None#

Create a log entry for just the given table.

This will log the table regardless of whether it is active or not.

Parameter name:

The name of the table to log.

tableNames() list[str]#

Get a vector of all the table names.

Returns:

A vector of the table names.

class Karana.KUtils.PacketTableConfig(name: str)#

Bases: Karana.Core.LockingBase

@class PacketTableConfig Define the columns and associated update functions for a PacketTable. The PacketTable is the table that stores data in the H5 log file.

static create(name: str) PacketTableConfig#

Create a packet table config.

Parameter name:

Name of the table. A / will be interpreted as a new group. Groups will be added as needed.

Returns:

A ks_ptr to the newly created instance of PacketTableConfig.

addData(name: str, f: collections.abc.Callable[[], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]], vector_size: SupportsInt, as_scalars: bool = False) None#
addData(name: str, f: collections.abc.Callable[[], Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]], matrix_rows: SupportsInt, matrix_cols: SupportsInt, as_scalars: bool = False) None

Add data to the table via function.

Parameter name:

The name of the column in the table.

Parameter f:

The function that produces the data (dynamic matrix). This matrix must always be the same size.

Parameter matrix_rows:

The number of rows in the matrix that the function produces. This matrix must always be the same size.

Parameter matrix_cols:

The number of columns in the matrix that the function produces. This matrix must always be the same size.

Parameter as_scalars:

Rather than using one column for the matrix, use multiple. This logs each matrix component as a scalar. The column names will be appended with a _X_Y where “X” and “Y” are integers that correspond with the row and index of the element in the matrix.

addDataFloat(name: str, f: collections.abc.Callable[[], float]) None#

Add data to the table via function.

Parameter name:

The name of the column in the table.

Parameter f:

The function that produces the data.

addDataInt(name: str, f: collections.abc.Callable[[], int]) None#

Add data to the table via function.

Parameter name:

The name of the column in the table.

Parameter f:

The function that produces the data.

fillBuf() None#

Fill the buffer by calling all the functions.