sub()

Expression: Sub

Call: sub(o1, o2):

Description

Returns the subtraction of to operands. Operands can be skalars or DataFrames (e.g. the output of another expression) but not signals (,yet). Thus, it is senseful to use sub() with clipped functions or values (got by value())

IO

  • Input
    • o1: first operand (can be skalar (e.g. int or float) or DataFrame with ‘x’ and ‘y’)
    • o2: seconds operand (can be skalar (e.g. int or float) or DataFrame with ‘x’ and ‘y’)
  • Output
    • Dataframe with columns ‘x’ and ‘y’.

Example

Clip the signal ‘v(inv_in)’ from 100us to 400us and subtract 2.

sub(
    clip(
	'v(inv_in)',
	'time',
	100u
	400u
    ),
    2
)

Example Picture Sub

Code

def sub(o1, o2):
    o1 = process_operator(o1)
    o2 = process_operator(o2)
    # Überprüfen, ob o1 und o2 DataFrames sind
    if isinstance(o1, pd.DataFrame) and isinstance(o2, pd.DataFrame):
        # Multiplizieren Sie nur die 'y'-Spalte, wenn beide DataFrames sind
        result = pd.DataFrame()
        result['x'] = o1['x']
        result['y'] = o1['y'] - o2['y']
    elif isinstance(o1, pd.DataFrame):
        # Wenn nur o1 ein DataFrame ist
        result = o1.copy()
        result['y'] -= o2
    elif isinstance(o2, pd.DataFrame):
        # Wenn nur o2 ein DataFrame ist
        result = o2.copy()
        result['y'] -= o1
    else:
        # Wenn beide Skalare sind
        #result = o1 - o2
        result = pd.DataFrame({'x': [0], 'y': o1 - o2})

    return result