InOutVar

@author: Marco Bonvini

class estimationpy.fmu_utils.in_out_var.InOutVar(pyfmi_var=None)

This class represents a generic input or output variable of a dynamic system. In case of state and parameter estimation both input and outputs of a system have the characteristic of having measurements associated to them. These measurements, together with other informations that can quantify their unsertanty, are used by the estimation algorithm.

This class can be seen as a wrapper around the class pyfmi.fmi.ScalarVariable with the addition of an object that represent a measurement time series. The time series can be directly defined as a pandas.Series object or with the convenience class estimationpy.fmu_utils.csv_reader.CsvReader.

Note

When dealing with real systems not all the output measurements can be measured. For example a translational mechanic system can have as outputs the position of a mass, it velocity, and its acceleration. However, in a real application one may only have access to one of these measurements. The class uses a boolean flag to define whether an output is actually being measured and thus can be used by a state estimation algorithm.
__init__(pyfmi_var=None)

Consttuctor for the class InOutVar. The constructor takes as input parameter an object of type pyfmi.fmi.ScalarVariable that contains the information about the variable. The method initializes an empty CsvReader object and an empty pandas.Series object that can be futher defined. The method also initializes the covariance \(\sigma^2\) associated to this variable to be 1.0, and the flag measOut = False.

The class provide, the CsvReader class associated to the input (that contains the data), a dictionary called dataSeries = {“time”: [], “data”: []} that contains the two arrays that represent the data series (that are read from the csv file).

The integer index is used when the data values are read using the function ReadFromDataSeries, while cov is the covariance associated to the data series.

Parameters:pyfmi_var (pyfmi.fmi.ScalarVariable) – the pyfmi object representing a variable.
get_covariance()

This method returns the covariance of the InOutVar object.

Returns:the covariance of the variable.
Return type:float
get_csv_reader()

This method returns a reference to the CsvReader object associated to the input/output variable.

Returns:the reference to the CsvReader object.
Return type:estimationpy.fmu_utils.csv_reader.CsvReader
get_data_series()

This method returns the data series associated to this input/output variable. The dat aseries can be either specified by a CSV file by means of a Csvreader object, or directly from a pandas.Series object.

Returns:the pandas.Series associated to this variable.
Return type:pandas.Series
get_object()

Get the object associated to the pyfmi.ScalarVariable associated to this input/output variable.

Returns:the pyfmi variable object reference by this variable.
Return type:pyfmi.fmi.ScalarVariable
is_measured_output()

This method returns the value of the boolean flag that describe if the variable is a measured output.

Returns:a boolean value that indicates if this variable is a measured output.
Return type:bool
read_data_series()

This method reads the data series associated to this input/output variable. The method checks if the CsvReader object has a valid file name associated to it. If not it looks if the data series has already been specified and is a not empty pandas.Series. The method returns True if the data is read, False otherwise.

Returns:True if the method is able to read the data from either the CsvReader obejct of the pandas.Series. False otherwise.
Return type:bool
read_from_data_series(ix)

This method reads and return the value associated to the input/output variable at the time specified by the parameter ix. The parameter ix needs to be a vaid index that belongs to a pandas.tseries.index.DatetimeIndex. If the index ix is not one of the indexes of the pandas.Series the method performs a linear interpolation between the two closest values to compute the value.

Parameters:ix – the time stamp for which providing the value.
Returns:the value that is read from the pandas.Series associated to the variable. if the index is out of range the method returns False.
Return type:float, bool
read_value_in_fmu(fmu)

This method reads the value of a variable/parameter assumes in a specific FMU object.

Parameters:fmu (FmuModel) – an object representing an FMU model in PyFMI.
Returns:The value of the variable represented by an instance of this class. The method returns None is the type of the variable is not recognized as one of the available ones (Real, Integer, Boolean, Enumeration, String).
Return type:float, None
set_covariance(cov)

This method sets the covariance associated to an instance of the class InOutVar that is used by the state and parameter estimation algorithm.

Parameters:cov (float) – The value to be used as initial value in the estimation algorithm. The value must be positive.
Returns:True if the value has been set corectly, False otherwise.
Return type:bool
set_csv_reader(reader)

This method associates an object of type estimationpy.fmu_utils.csv_reader.CsvReader to this input/output variable. The CsvReder will be used to read data by the state and parameter estimation algorithm.

Parameters:reader (estimationpy.fmu_utils.csv_reader.CsvReader) – The CsvReader object to associate to this variable.
Raises TypeError:
 The method raises an exception if the type of the argument reader is not correct.
set_data_series(series)

This function sets a data series instead of reading it from the CSV file. The data series has to be a pandas.Series object that is indexed with a pandas.tseries.index.DatetimeIndex.

Parameters:series (pandas.Series) – the time series to be associated to this input/output variable.
Raises TypeError:
 The method raise an error if the parameter series is not of the right type or it’s a pandas.Series not indexed with a pandas.tseries.index.DatetimeIndex.
set_measured_output(flag=True)

This method set the flag that indicates if the variable represents a measured output.

Parameters:flag (bool) – flag that indicates whether this variable is a measured output or not.
set_object(pyfmi_var)

This method sets the variable associated to the object of class InOutVar.

Parameters:pyfmi_var (pyfmi.fmi.ScalarVariable) – The variable associated to the input/output represented by the object.
Raises TypeError:
 The method raises an exception if the parameter is not of the proper type.