libICEpost.src.base.dataStructures.Tabulation.BaseTabulation
@author: F. Ramognino <federico.ramognino@polimi.it> Last update: 12/06/2023
Classes
Class used for storing and handling a tabulation from a structured grid in an n-dimensional space of input-variables. |
Functions
|
Get the input values at a slice of the table. |
|
Compute the location of an index inside a table. Getting the index, returns a list of the indices of each input-variable. |
Module Contents
- libICEpost.src.base.dataStructures.Tabulation.BaseTabulation.getInput(table: BaseTabulation, index: int | Iterable[int]) dict[str, float][source]
Get the input values at a slice of the table.
- Parameters:
table (BaseTabulation) – The table to access.
index (int | Iterable[int]) – The index to access.
- Returns:
float]: A tuple with a dictionary mapping the names of input-variables to corresponding values
- Return type:
dict[str
- libICEpost.src.base.dataStructures.Tabulation.BaseTabulation.tableIndex(table: BaseTabulation, index: int | Iterable[int] | slice) tuple[int] | Iterable[tuple[int, Ellipsis]][source]
Compute the location of an index inside a table. Getting the index, returns a list of the indices of each input-variable.
- Parameters:
table (BaseTabulation) – The table to access.
index (int | Iterable[int] | slice) – The index to access.
- Returns:
- The index/indices:
If int is given, returns tuple[int].
If slice or Iterable[int] is given, returns Iterable[tuple[int,…]].
- Return type:
tuple[int] | Iterable[tuple[int,…]]
Example
>>> table.shape (2, 3, 4) >>> table._computeIndex(12) (1, 0, 0) >>> table._computeIndex([0, 1, 2]) [(0, 0, 0), (0, 0, 1), (0, 0, 2)] >>> table._computeIndex(slice(0, 3)) [(0, 0, 0), (0, 0, 1), (0, 0, 2)]
- class libICEpost.src.base.dataStructures.Tabulation.BaseTabulation.BaseTabulation[source]
Bases:
libICEpost.src.base.Utilities.UtilitiesClass used for storing and handling a tabulation from a structured grid in an n-dimensional space of input-variables.
- _order: list[str]
The order in which the input variables are nested
- classmethod from_pandas(data: pandas.DataFrame, order: Iterable[str], *args, **kwargs) Self[source]
- Abstractmethod:
Construct a tabulation from a pandas.DataFrame with n+x columns where n is len(order).
- Parameters:
data (DataFrame) – The data-frame to use.
order (Iterable[str]) – The order in which the input variables are nested.
**kwargs – Additional arguments to pass to the constructor.
- Returns:
The tabulation.
- Return type:
Self
- fromPandas
- property order: list[str]
The order in which variables are nested.
- Returns:
list[str]
- abstract property ranges
Get a dict containing the data ranges in the tabulation (read-only).
- property ndim: int
- Abstractmethod:
Returns the number of dimentsions of the table.
- property shape: tuple[int]
- Abstractmethod:
The shape, i.e., how many sampling points are used for each input-variable.
- property size: int
- Abstractmethod:
Returns the number of data-points stored in the table.
- _computeIndex
- getInput
- abstractmethod insertDimension(*, variable: str, value: float, index: int = None, inplace: bool = False) BaseTabulation | None[source]
Insert an axis to the dimension-set of the table with a single value. This is useful to merge two tables with respect to an additional variable.
- Parameters:
table (BaseTabulation) – The table to modify.
variable (str) – The name of the variable to insert.
value (float) – The value for the range of the corresponding variable.
index (int, optional) – The index where to insert the variable in nesting order. If None, append the variable at the end. Defaults to None.
inplace (bool, optional) – If True, the operation is performed in-place. Defaults to False.
- Returns:
The table with the inserted dimension if inplace is False, None otherwise.
- Return type:
BaseTabulation|None
Example
Create a table with two variables:
` >>> tab1 = Tabulation([1, 2, 3, 4], {"x":[0, 1], "y":[0, 1]}, ["x", "y"]) >>> tab1.insertDimension("z", 0.0, 1) >>> tab1.ranges {"x":[0, 1], "z":[0.0], "y":[0, 1]} `Create a second table with the same variables:` >>> tab2 = Tabulation([5, 6, 7, 8], {"x":[0, 1], "y":[0, 1]}, ["x", "y"]) >>> tab2.insertDimension("z", 1.0, 1) >>> tab2.ranges {"x":[0, 1], "z":[1.0], "y":[0, 1]} `Concatenate the two tables:
` >>> tab1.concat(tab2, inplace=True) >>> tab1.ranges {"x":[0, 1], "z":[0.0, 1.0], "y":[0, 1]} `
- abstractmethod slice(*, slices: Iterable[slice | Iterable[int] | int] = None, ranges: dict[str, float | Iterable[float]] = None, inplace: bool = False) BaseTabulation | None[source]
- Extract a table with sliced data. Can access in two ways:
by slicer
sub-set of interpolation points. Keyword arguments also accepred.
- Parameters:
slices (Iterable[slice|Iterable[int]|int]) – The slicers for each input-variable.
ranges (dict[str,float|Iterable[float]], optional) – Ranges of sliced table. Defaults to None.
inplace (bool, optional) – If True, the operation is performed in-place. Defaults to False.
- Returns:
The sliced table if inplace is False, None otherwise.
- Return type:
Self|None
- abstractmethod clip(ranges: dict[str, tuple[float | None, float | None]] = None, *, inplace: bool = False, **kwargs) BaseTabulation | None[source]
Clip the table to the given ranges. The ranges are given as a dictionary with the variable names as keys and a tuple with the minimum and maximum values.
- Parameters:
ranges (dict[str,tuple[float|None,float|None]], optional) – The ranges to clip for each input-variable. If min or max is None, the range is unbounded.
inplace (bool, optional) – If True, the operation is performed in-place. Defaults to False.
**kwargs – Can access also by keyword arguments.
- Returns:
The clipped table if inplace is False, None otherwise.
- Return type:
Self|None
- abstractmethod concat(*tables: BaseTabulation, inplace: bool = False, fillValue: float = None, overwrite: bool = False) BaseTabulation | None[source]
Extend the table with the data of other tables. The tables must have the same variables but not necessarily in the same order. The data of the second table is appended to the data of the first table, preserving the order of the variables.
If fillValue is not given, the ranges of the second table must be consistent with those of the first table in the variables that are not concatenated. If fillValue is given, the missing sampling points are filled with the given value.
- Parameters:
*tables (BaseTabulation) – The tables to append.
inplace (bool, optional) – If True, the operation is performed in-place. Defaults to False.
fillValue (float, optional) – The value to fill missing sampling points. Defaults to None.
overwrite (bool, optional) – If True, overwrite the data of the first table with the data of the second table in overlapping regions. Otherwise raise an error. Defaults to False.
- Returns:
The concatenated table if inplace is False, None otherwise.
- Return type:
Self|None
- abstractmethod squeeze(inplace: bool = False) BaseTabulation | None[source]
Remove dimensions with only 1 data-point.
- Parameters:
inplace (bool, optional) – If True, the operation is performed in-place. Defaults to False.
- Returns:
The squeezed tabulation if inplace is False, None otherwise.
- Return type:
Self|None
- abstractmethod to_pandas() pandas.DataFrame[source]
Convert the tabulation to a pandas.DataFrame.
- Returns:
The data-frame.
- Return type:
DataFrame
- toPandas
- abstractmethod plotHeatmap(*args, **kwargs) matplotlib.pyplot.Axes[source]
Plot a heatmap of the tabulation.
- abstractmethod __call__(*args, **kwargs) float | numpy.ndarray[float][source]
Interpolate the table at a given point(s).
- abstractmethod __getitem__(index: int | Iterable[int] | slice) Any | Iterable[Any][source]
Get an element in the table.
- Parameters:
index (int | Iterable[int] | slice | Iterable[slice]) – Either: - An index to access the table (flattened). - A tuple of the x,y,z,… indices to access the table. - A slice to access the table (flattened). - A tuple of slices to access the table.
- Returns:
The value(s) stored in the table.
- Return type:
Any | Iterable[Any]
- abstractmethod __setitem__(index: int | Iterable[int] | slice | tuple[int | Iterable[int] | slice], value: float | numpy.ndarray[float]) None[source]
Set the interpolation values at a slice of the table through np.ndarray.__setitem__ but: - If int|Iterable[int]|slice is given, set the value at the index/indices in the flattened dataset. - If tuple[int|Iterable[int]|slice] is given, set the value at the index/indices in the nested dataset.
- __add__(table: BaseTabulation) BaseTabulation[source]
Concatenate two tables. Alias for ‘concat’.
- __iadd__(table: BaseTabulation) BaseTabulation[source]
Concatenate two tables in-place. Alias for ‘concat’.