operations

This module consists of a pre-defined functions that are imported into tag for convenient use in VirtualTag objects.

class pype_schema.operations.Constant(value, parent_id=None)[source]

Representation for a constant value that is not in the SCADA system.

Only need for Algebraic mode since lambda expressions support constant values directly.

Parameters:

value (float) – The value of this constant at all timesteps

Variables:
  • id (str) –

  • value (float) – The value of this constant at all timesteps

pype_schema.operations.binary_helper(operation, unit, prev_unit, totalized_mix=False)[source]

Helper for parsing operations and checking units of binary operations

Parameters:
  • operation ([“+”, “-”, “”, “/”]*) – Function to apply when combining tags. Supported functions are “+”, “-”, “*”, and “/”.

  • unit (Unit) – Units for the right side of the operation, represented as a Pint unit.

  • prev_unit (Unit) – Units for the left side of the operation, represented as a Pint unit.

  • totalized_mix (bool) – Skip unit checking when there is a mix of totalized and detotalized variables. Default is False

Raises:
  • ValueError – When units are incompatible for addition or subtraction. When operation is unsupported.

  • UserWarning – When a mix of totalized and detotalized variables makes it impossible to verify unit compatibility

Returns:

Resulting Pint Unit from combining the unit and prev_unit according to operation

Return type:

Unit

pype_schema.operations.get_change(variable, delta_t=1, split=False)[source]

Converts cumulative value to rate-of-change value using finite differences Note: assumes rate of change at time t is equal to the difference between the value at time t+1 and t

Parameters:
  • variable (pandas.Series, numpy.ndarray) – variable to convert

  • delta_t (int) – Time difference between two consecutive values of the variable (default is 1)

  • split (bool) – Whether to split the variable into a negative change and a positive change

Returns:

Rate of change variable or tuple of netative, positive rate of change variable

Return type:

tuple, pandas.Series or numpy.ndarray

pype_schema.operations.unary_helper(data, un_op)[source]

Transform the given data according to the VirtualTag’s unary operator

Parameters:
  • data (list, array, or Series) – a list, numpy array, or pandas Series of data to apply a unary operation to

  • un_op ([“noop”, “delta”, “<<”, “>>”, “~”, “-“]) –

    Supported operations are:

    “noop” : null operator, useful when skipping tags in a list of unary operations.

    “delta” : calculate the difference between the current timestep and previous timestep

    “<<” : shift all data left one timestep, so that the last time step will be NaN

    “>>” : shift all data right one timestep, so that the first time step will be NaN

    “~” : Boolean not

    “-” : unary negation

    Note that “delta”, “<<”, and “>>” return a timeseries padded with NaN so that it is the same length as input data

Returns:

numpy array of dataset trannsformed by unary operation

Return type:

list, array, or Series