TransientDataTableSetup

Qualified name: transient_data_table.scripting_api.transient_data_table_setup.TransientDataTableSetup

class transient_data_table.scripting_api.transient_data_table_setup.TransientDataTableSetup(item)[source]

Bases: DataTableSetup

API class for handling transient data tables.

In order to create a transient data table using the API perform the following:

Example

>>> from more.api import ApiGateway
>>> simulation_setup = ApiGateway(proj=proj).create_simulation_setup()
>>> data_table_setup = simulation_setup \
...    .create_data_table_setup(data_table_type_name='Transient data table')

In order to get an API setup object for a transient data table that already exists:

Example

>>> from more.api import ApiGateway
>>> simulation_setup = ApiGateway(proj=proj).create_simulation_setup()
>>> data_table_setup = simulation_setup.get_data_table_setup(name='Example data table') # The data table must already exist

The following examples assume that a TransientDataTableSetup class exists as created by one of the above methods.

Methods

export_data

Exports a data to a given location as a .mat file

get_column_index

Get the index of a column with a given name

get_column_name

Get the name of the column from the index

get_data

Returns the data table data

get_name

import_data

Imports data from a .mat file to the data table

set_column_name

Set the name of the column

set_data

Sets the data table data

set_interpolation_method

Sets the interpolation method

set_name

Changes the name of the simresults

Attributes

available_interpolation_method_names

Returns the available interpolation method names

property available_interpolation_method_names: List[str]

Returns the available interpolation method names

Example

>>> print(f'Available interpolation methods are: "{data_table_setup.available_interpolation_method_names}"')
Available interpolation methods are: "['hold', 'nearest']"
Returns:

methods – The available interpolation methods

Return type:

List[str]

export_data(path: str | PathLike) TransientDataTableSetup[source]

Exports a data to a given location as a .mat file

Example

>>> import tempfile
>>> import os
>>> with tempfile.TemporaryDirectory(prefix='more_') as tmp_dir:
...     data_path = os.path.join(tmp_dir, 'data.mat')
...     data_table_setup.export_data(path=data_path)
<...>
Parameters:

path – A string of PathLike with the path to the desired export location

Returns:

This object

Return type:

self

get_column_index(name: str) int[source]

Get the index of a column with a given name

Example

>>> var_val, data_val = np.array([0, 0.3, 0.6]), np.array([[0, 1e-3, 2e-3], [1, 2, 3]])
>>> data_table_setup = data_table_setup \
...     .set_data(var=var_val, data=data_val)
>>> data_table_setup = data_table_setup.set_column_name(index=1, new_name='Second column')
>>> data_table_setup.get_column_index(name='Second column')
1
Parameters:

name (str) – The name of the column for which to returen the index

Returns:

column_index – The index of the column with the given name

Return type:

int

Raises:
  • NameNotFoundError – Raised if a column with such a name does not exist

  • TypeError – Raised if the given parameter is not a string

get_column_name(index: int) str[source]

Get the name of the column from the index

Example

>>> var_val, data_val = np.array([0, 0.3, 0.6]), np.array([[0, 1e-3, 2e-3], [1, 2, 3]])
>>> data_table_setup = data_table_setup \
...     .set_data(var=var_val, data=data_val)
>>> data_table_setup = data_table_setup.set_column_name(index=1, new_name='Second column')
>>> data_table_setup.get_column_name(index=1)
'Second column'
Parameters:

index – The index of the column for which teh name is requested

Returns:

column_name – the name of the column

Return type:

str

Raises:
  • TypeError – Raised if the index is not an integer

  • IndexNotFoundError – Raised if the given index is not in range

get_data() VarAndData[source]

Returns the data table data

Example

>>> var, data = data_table_setup.get_data()
Returns:

Var and data in the form of a named tuple containing the data points and the data itself from the data table with shapes (n), (n, m) respectively

Return type:

data tuple

import_data(path: str | PathLike) TransientDataTableSetup[source]

Imports data from a .mat file to the data table

Example

>>> import tempfile
>>> import os
>>> with tempfile.TemporaryDirectory(prefix='more_') as tmp_dir:
...     data_path = os.path.join(tmp_dir, 'data.mat')
...     data_table_setup_1 = data_table_setup_1.export_data(path=data_path)
...     data_table_setup_2 = data_table_setup_2.import_data(path=data_path)
Parameters:

path – A string of PathLike with the path to the desired export location

Returns:

This object

Return type:

self

Raises:

FileNotFoundError – Raised if the file with the given name was not found

set_column_name(index: int, new_name: str) TransientDataTableSetup[source]

Set the name of the column

Example

>>> import numpy as np
>>> var_val, data_val = np.array([0, 0.3, 0.6]), np.array([[0, 1e-3, 2e-3], [1, 2, 3]])
>>> data_table_setup = data_table_setup \
...     .set_data(var=var_val, data=data_val)
>>> data_table_setup = data_table_setup.set_column_name(index=1, new_name='Second column')
Parameters:
  • index – The index of the column whose name is to be changed

  • new_name – The new name to apply

Returns:

This object

Return type:

self

Raises:
  • IndexNotFoundError – Raised if the given index is out of range for the given data table

  • TypeError – Raised if one of the parameters has the wrong type

set_data(var: ndarray, data: ndarray) TransientDataTableSetup[source]

Sets the data table data

Example

>>> import numpy as np
>>> var_val, data_val = np.array([0, 0.3, 0.6]), np.array([[0, 1e-3, 2e-3], [1, 2, 3]])
>>> data_table_setup = data_table_setup \
...     .set_data(var=var_val, data=data_val)
Parameters:
  • var (np.ndarray) – A 1D array of shape (n, ) representing the data points of the array, with ‘n’ being the number of rows in the table. The table will grow or shrink to accomodate this size.

  • data (np.ndarray) –

    A 2D array of shape (m, n) with ‘n’ being the number of rows, and ‘m’ being the number of data-carrying

    columns in the table.

Returns:

This object

Return type:

self

Raises:
  • TypeError – Raised it either var or data are not numpy arrays

  • ValueError – Raised if the provided var or data shapes are not compatible

set_interpolation_method(method_name: str) TransientDataTableSetup[source]

Sets the interpolation method

Example

>>> import numpy as np
>>> var_val, data_val = np.array([0, 0.3, 0.6]), np.array([[0, 1e-3, 2e-3], [1, 2, 3]])
>>> data_table_setup = data_table_setup \
...     .set_data(var=var_val, data=data_val)
>>> data_table_setup = data_table_setup.set_interpolation_method(method_name='linear')
Parameters:

method_name – The name of the interpolation method

Returns:

This object

Return type:

self

Raises:
  • TypeError – Raised it the interpolation method name is not a string

  • NameNotFoundError – Raised if the given interpolation method name does not exist

  • NotCompatibleError – Raised if the interpolation method exists, but is not compatible with the data

set_name(name: str, resolve_duplicate_name: bool = False) DataTableSetup[source]

Changes the name of the simresults

Example

>>> data_table_setup.set_name('new_name')
<more...>
>>> second_data_table_setup.set_name(name='new_name', resolve_duplicate_name=True).get_name()
'new_name 1'
Parameters:
  • resolve_duplicate_name (bool) – Whether to automatically assign a new name when the chosen one is already taken

  • name (str) – The new name

Returns:

This object

Return type:

self

Raises:
  • TypeError – Raised if the given name is not a string

  • NameNotUniqueError – Raised if the given name is not unique