value()

Expression: Give a value from signal

Call:
	value(signal_y, signal_x, x_value)
or
	value(df, x_value)

Description

Gets the y-value of an x-value of a signal or expression.

IO

  • Input
    • signal_y: name of y-signal
    • signal_x: name of x-signal (usually ’time')
    • df: Dataframe with columns ‘x’ and ‘y’ that contains a signal
  • Output
    • Dataframe with columns ‘x’ and ‘y’ with both containing rolling_average

Example

Get the value of the signal ‘v(inv_in)’ at ’time’ of 400 microseconds

value(
	'v(inv_in)',
	'time',
	400u
)

Example Picture value

Code

def value(*args):
    if len(args) == 3:
        x = process_operator(args[1])
        y = process_operator(args[0])
        x_index = args[2]

    elif len(args) == 2:
        if isinstance(args[0], pd.DataFrame):
            x = args[0]['x']
            y = args[0]['y']
            x_index = args[1]
        else:
            return pd.DataFrame()
    else:
        return pd.DataFrame()
    index = x.tolist()
    values = y.tolist()
    if isinstance(x_index, pd.DataFrame):
        x_index = x_index['y'][0]
    data_dict = {'x': [x_index], 'y': [np.interp(x_index, index, values)]}
    df_out = pd.DataFrame(data_dict)
    return df_out