libICEpost.src.base.dataStructures.EngineData.EngineData

@author: F. Ramognino <federico.ramognino@polimi.it> Last update: 12/06/2023

Attributes

_reservedMethds

Classes

EngineData

Database for engine data. Wraps a pandas DataFrame class and adds

Functions

is_valid_variable_name(name)

Module Contents

libICEpost.src.base.dataStructures.EngineData.EngineData.is_valid_variable_name(name)[source]
class libICEpost.src.base.dataStructures.EngineData.EngineData.EngineData[source]

Bases: libICEpost.src.base.Utilities.Utilities

Database for engine data. Wraps a pandas DataFrame class and adds some useful I/O methods and defines interpolators of the varibles to easily access data at generic instants.

_interpolators: set[str]

Names of all the interpolators avaliable

property columns

The columns in the DataFrame.

Returns:

Index[str]

property index

The index list of the DataFrame.

Returns:

Index

property loc

Access a group of rows and columns by label(s) or a boolean array. Calls ‘loc’ propertie of the DataFrame.

property iloc

Purely integer-location based indexing for selection by position. Calls ‘iloc’ propertie of the DataFrame.

_data
__len__()[source]
__str__()[source]
__repr__()[source]
__getitem__(*item) pandas.Series | pandas.DataFrame[source]
__setitem__(key, item) None[source]
__getattribute__(name: str) os.Any[source]
__delitem__(item)[source]
__call__() pandas.DataFrame[source]

Access the DataFrame instance that stores the data. :returns: The DataFrame instance that stores the data. :rtype: pd.DataFrame

loadFile(fileName: str, varName: str, /, *, CACol: int = 0, varCol: int = 1, CAOff: float = 0.0, varOff: float = 0.0, CAscale: float = 1.0, varScale: float = 1.0, skipRows: int = 0, maxRows: int = None, interpolate: bool = True, comments: str = '#', verbose: bool = True, delimiter: str = None, default: float = float('nan')) Self[source]

Load a file containing the time-series of a variable. If data were already loaded, the CA range must be consistent (sub-arrays are also permitted; excess data will be truncated). Note: use delimiter=’,’ to load CSV files. Automatically removes duplicate times.

Parameters:
  • fileName (str) – Source file

  • varName (str) – Name of variable in data structure

  • CACol (int, optional) – Column of CA list. Defaults to 0.

  • varCol (int, optional) – Column of data list. Defaults to 1.

  • CAOff (float, optional) – Offset to sum to CA range. Defaults to 0.0.

  • varOff (float, optional) – Offset to sum to variable range. Defaults to 0.0.

  • CAscale (float, optional) – Scaling factor to apply to CA range. Defaults to 1.0.

  • varScale (float, optional) – Scaling factor to apply to variable range. Defaults to 1.0.

  • skipRows (int, optional) – Number of raws to skip at beginning of file. Defaults to 0.

  • maxRows (int, optional) – Maximum number of raws to use. Defaults to None.

  • interpolate (bool, optional) – Interpolate the data-set at existing CA range (used to load non-consistent data). Defaults to True.

  • comments (str, optional) – Character to use to detect comment lines. Defaults to ‘#’.

  • verbose (bool, optional) – Print info/warnings. Defaults to True.

  • delimiter (str, optional) – Delimiter for the columns (defaults to whitespace). Defaults to None.

  • default (float, optional) – Default value to add in out-of-range values. Defaults to float(“nan”).

Returns:

self.

Return type:

Self

loadArray(data: collections.abc.Iterable, varName: str, verbose: bool = True, default: float = float('nan'), interpolate: bool = False, dataFormat: Literal['column', 'row'] = 'column') Self[source]

Load an array into the table. Automatically removes duplicate times.

Parameters:
  • data (collections.abc.Iterable) – Container of shape [N,2] (column) or [2,N] (row), depending on ‘dataFormat’ value, with first column/row the CA range and second the variable time-series to load.

  • varName (str) – Name of variable in data structure

  • verbose (bool, optional) – If need to print loading information. Defaults to True.

  • default (float, optional) – Default value for out-of-range elements. Defaults to float(“nan”).

  • interpolate (bool, optional) – Interpolate the data-set at existing CA range (used to load non-consistent data). Defaults to False.

  • dataFormat (str, Literal[&quot;column&quot;, &quot;row&quot;], optional) – Format of data: ‘column’ -> [N,2] ‘row’ -> [2,N]

Returns:

self.

Return type:

Self

Examples

Creating a ‘EngineData’ instance >>> ed = EngineData()

Loading from list containing two lists for CA and variable (by row) >>> ed = EngineData() >>> data = [[1, 2, 3, 4, 5], [11, 12, 13, 14, 15]] >>> ed.loadArray(data, “var1”, dataFormat=”row”)

CA var1

0 1 11 1 2 12 2 3 13 3 4 14 4 5 15

Loading second variable from list of (CA,var) pairs (order by column) without interpolation >>> data = [(3, 3), (4, 3.5), (5, 2.4), (6, 5.2), (7, 3.14)] >>> ed.loadArray(data, “var2”, dataFormat=”column”)

CA var1 var2

0 1 11.0 NaN 1 2 12.0 NaN 2 3 13.0 3.00 3 4 14.0 3.50 4 5 15.0 2.40 5 6 NaN 5.20 6 7 NaN 3.14

Extend the interval of var2 from a pandas.DataFrame with data by column, suppressing the warning for orverwriting. >>> from pandas import DataFrame as df >>> data = df({“CA”:[8, 9, 10, 11], “var”:[2, 1, 0, -1]}) >>> ed.loadArray(data, “var2”, dataFormat=”column”, verbose=False)

CA var1 var2

0 1 11.0 NaN 1 2 12.0 NaN 2 3 13.0 3.00 3 4 14.0 3.50 4 5 15.0 2.40 5 6 NaN 5.20 6 7 NaN 3.14 7 8 NaN 2.00 8 9 NaN 1.00 9 10 NaN 0.00 10 11 NaN -1.00

Load a variable var3 from numpy ndarray and interpolate >>> import numpy as np >>> data = np.array([[-5.5, 5.5],[2.3, 5.4]]) >>> ed.loadArray(data, “var3”, dataFormat=”row”, interpolate=True)

CA var1 var2 var3

0 -5.5 NaN NaN 2.300000 1 1.0 11.0 NaN 4.131818 2 2.0 12.0 NaN 4.413636 3 3.0 13.0 3.00 4.695455 4 4.0 14.0 3.50 4.977273 5 5.0 15.0 2.40 5.259091 6 5.5 NaN 3.80 5.400000 7 6.0 NaN 5.20 NaN 8 7.0 NaN 3.14 NaN 9 8.0 NaN 2.00 NaN 10 9.0 NaN 1.00 NaN 11 10.0 NaN 0.00 NaN 12 11.0 NaN -1.00 NaN

_createInterpolator(varName: str)[source]

varName: str

Create the interpolator for a variable and defines the method varName(CA) which returns the interpolated value of variable ‘varName’ at instant ‘CA’ from the data in self._data

write(fileName: str, overwrite: bool = False, sep: str = ' ')[source]
fileName: str

Name of the file where to write the data structure

overwrite: bool (False)

Allow to overwrite file if existing

sep: str (‘’)

Separator

Write data to a file

plot(*args, **kwargs)[source]

Plotting the data stored in the table. It refers to the the ‘plot’ method of the DataFrame storing the data

Returns:

The axes of the plot(s).

Return type:

matplotlib.Axes|numpy.ndarray[matplotlib.Axes]

libICEpost.src.base.dataStructures.EngineData.EngineData._reservedMethds