libICEpost.src.base.dataStructures.Tabulation.BaseTabulation ============================================================ .. py:module:: libICEpost.src.base.dataStructures.Tabulation.BaseTabulation .. autoapi-nested-parse:: @author: F. Ramognino Last update: 12/06/2023 Classes ------- .. autoapisummary:: libICEpost.src.base.dataStructures.Tabulation.BaseTabulation.BaseTabulation Functions --------- .. autoapisummary:: libICEpost.src.base.dataStructures.Tabulation.BaseTabulation.getInput libICEpost.src.base.dataStructures.Tabulation.BaseTabulation.tableIndex Module Contents --------------- .. py:function:: getInput(table: BaseTabulation, index: int | Iterable[int]) -> dict[str, float] Get the input values at a slice of the table. :param table: The table to access. :type table: BaseTabulation :param index: The index to access. :type index: int | Iterable[int] :returns: float]: A tuple with a dictionary mapping the names of input-variables to corresponding values :rtype: dict[str .. py:function:: tableIndex(table: BaseTabulation, index: int | Iterable[int] | slice) -> tuple[int] | Iterable[tuple[int, Ellipsis]] Compute the location of an index inside a table. Getting the index, returns a list of the indices of each input-variable. :param table: The table to access. :type table: BaseTabulation :param index: The index to access. :type index: int | Iterable[int] | slice :returns: The index/indices: - If int is given, returns tuple[int]. - If slice or Iterable[int] is given, returns Iterable[tuple[int,...]]. :rtype: tuple[int] | Iterable[tuple[int,...]] .. rubric:: 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)] .. py:class:: BaseTabulation Bases: :py:obj:`libICEpost.src.base.Utilities.Utilities` Class used for storing and handling a tabulation from a structured grid in an n-dimensional space of input-variables. .. py:attribute:: _order :type: list[str] The order in which the input variables are nested .. py:method:: from_pandas(data: pandas.DataFrame, order: Iterable[str], *args, **kwargs) -> Self :classmethod: :abstractmethod: Construct a tabulation from a pandas.DataFrame with n+x columns where n is len(order). :param data: The data-frame to use. :type data: DataFrame :param order: The order in which the input variables are nested. :type order: Iterable[str] :param \*\*kwargs: Additional arguments to pass to the constructor. :returns: The tabulation. :rtype: Self .. py:attribute:: fromPandas .. py:property:: order :type: list[str] The order in which variables are nested. :returns: list[str] .. py:property:: ranges :abstractmethod: Get a dict containing the data ranges in the tabulation (read-only). .. py:property:: ndim :type: int :abstractmethod: Returns the number of dimentsions of the table. .. py:property:: shape :type: tuple[int] :abstractmethod: The shape, i.e., how many sampling points are used for each input-variable. .. py:property:: size :type: int :abstractmethod: Returns the number of data-points stored in the table. .. py:attribute:: _computeIndex .. py:attribute:: getInput .. py:method:: insertDimension(variable: str, value: float, index: int = None, *, inplace: bool = False) -> BaseTabulation | None :abstractmethod: 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. :param table: The table to modify. :type table: BaseTabulation :param variable: The name of the variable to insert. :type variable: str :param value: The value for the range of the corresponding variable. :type value: float :param index: The index where to insert the variable in nesting order. If None, append the variable at the end. Defaults to None. :type index: int, optional :param inplace: If True, the operation is performed in-place. Defaults to False. :type inplace: bool, optional :returns: The table with the inserted dimension if inplace is False, None otherwise. :rtype: BaseTabulation|None .. rubric:: 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]} ``` .. py:method:: slice(*, slices: Iterable[slice | Iterable[int] | int] = None, ranges: dict[str, float | Iterable[float]] = None, inplace: bool = False) -> BaseTabulation | None :abstractmethod: Extract a table with sliced data. Can access in two ways: 1) by slicer 2) sub-set of interpolation points. Keyword arguments also accepred. :param slices: The slicers for each input-variable. :type slices: Iterable[slice|Iterable[int]|int] :param ranges: Ranges of sliced table. Defaults to None. :type ranges: dict[str,float|Iterable[float]], optional :param inplace: If True, the operation is performed in-place. Defaults to False. :type inplace: bool, optional :returns: The sliced table if inplace is False, None otherwise. :rtype: Self|None .. py:method:: clip(ranges: dict[str, tuple[float | None, float | None]] = None, *, inplace: bool = False, **kwargs) -> BaseTabulation | None :abstractmethod: 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. :param ranges: The ranges to clip for each input-variable. If min or max is None, the range is unbounded. :type ranges: dict[str,tuple[float|None,float|None]], optional :param inplace: If True, the operation is performed in-place. Defaults to False. :type inplace: bool, optional :param \*\*kwargs: Can access also by keyword arguments. :returns: The clipped table if inplace is False, None otherwise. :rtype: Self|None .. py:method:: concat(*tables: BaseTabulation, inplace: bool = False, fillValue: float = None, overwrite: bool = False) -> BaseTabulation | None :abstractmethod: 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. :param \*tables: The tables to append. :type \*tables: BaseTabulation :param inplace: If True, the operation is performed in-place. Defaults to False. :type inplace: bool, optional :param fillValue: The value to fill missing sampling points. Defaults to None. :type fillValue: float, optional :param overwrite: 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. :type overwrite: bool, optional :returns: The concatenated table if inplace is False, None otherwise. :rtype: Self|None .. py:method:: squeeze(inplace: bool = False) -> BaseTabulation | None :abstractmethod: Remove dimensions with only 1 data-point. :param inplace: If True, the operation is performed in-place. Defaults to False. :type inplace: bool, optional :returns: The squeezed tabulation if inplace is False, None otherwise. :rtype: Self|None .. py:method:: to_pandas() -> pandas.DataFrame :abstractmethod: Convert the tabulation to a pandas.DataFrame. :returns: The data-frame. :rtype: DataFrame .. py:attribute:: toPandas .. py:method:: plot(*args, **kwargs) -> matplotlib.pyplot.Axes :abstractmethod: Plot the tabulation. .. py:method:: plotHeatmap(*args, **kwargs) -> matplotlib.pyplot.Axes :abstractmethod: Plot a heatmap of the tabulation. .. py:method:: __call__(*args, **kwargs) -> float | numpy.ndarray[float] :abstractmethod: Interpolate the table at a given point(s). .. py:method:: __getitem__(index: int | Iterable[int] | slice) -> Any | Iterable[Any] :abstractmethod: Get an element in the table. :param index: 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. :type index: int | Iterable[int] | slice | Iterable[slice] :returns: The value(s) stored in the table. :rtype: Any | Iterable[Any] .. py:method:: __setitem__(index: int | Iterable[int] | slice | tuple[int | Iterable[int] | slice], value: float | numpy.ndarray[float]) -> None :abstractmethod: 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. .. py:method:: __eq__(value) -> bool :abstractmethod: .. py:method:: __iter__() Iterator :returns: Self .. py:method:: __len__() -> int Returns the number of data-points stored in the table. .. py:method:: __add__(table: BaseTabulation) -> BaseTabulation Concatenate two tables. Alias for 'concat'. .. py:method:: __iadd__(table: BaseTabulation) -> BaseTabulation Concatenate two tables in-place. Alias for 'concat'. .. py:method:: __repr__() -> str :abstractmethod: .. py:method:: __str__() -> str :abstractmethod: