.. _`Calculator`: .. _`org.sysess.sympathy.data.table.calculatorgeneric`: Calculator ~~~~~~~~~~ .. image:: calculator.svg :width: 48 The Calculator nodes can perform calculations on any given input. Any type can by used as input and it is accessed by the keyword *arg*. These nodes do not support the ${} notation of older :ref:`Calculator Table` nodes. Tuples can be used either with the same datatypes e.g., (:ref:`Table`, :ref:`Table`), (:ref:`ADAF`, :ref:`ADAF`, :ref:`ADAF`), etc, or with different datatypes e.g., (:ref:`Table`, :ref:`ADAF`), (:ref:`ADAF`, :ref:`ADAFs`, :ref:`Tables`). Any combination is possible. The items in a tuple are accessed by index, like so: ``arg[0]``, ``arg[1]``, etc. Calculated signals can be accessed with the *res* keyword in the same way. Some examples:: - Table - ``arg.col('signal1').data`` - Tables - ``arg[0].col('signal1').data`` - ADAF - ``arg.sys['system0']['raster0']['signal0'].y`` for signal values and ``arg.sys['system0']['raster0']['signal0'].t`` for the timeseries - ADAFs - ``arg[0].sys['system0']['raster0']['signal0'].y`` for signal values and ``arg[0].sys['system0']['raster0']['signal0'].t`` for the timeseries - Text - ``arg.dtext`` for the text - Texts - ``arg[0].dtext`` for the text - Datasource - ``arg`` for Datasource object - Datasources - ``arg[0]`` for Datasource in Datasources - Tuple - Objects are accessed as ``arg[0]``, ``arg[1]``, ... Example calculations:: New signal = arg.col('Old signal').data + 1 area = arg.col('width').data * arg.col('height').data result = (arg.col('signal0').data == 2) & ca.change_up(arg.col('signal1).data) index = np.arange(len(arg.col('some signal').data)) sine = np.sin(arg.col('angle').data) The API of the incoming :ref:`data type` can be used in the calculator. For example you can use :ref:`tableapi` to get a list of a table's column names:: table_names = arg.column_names() Note that a dependency on a column is only created when a string literal is used, for example, ``arg.col('signal_name').data``. Iterating through a table's columns, like np.array([arg.col(name) for name in arg.column_names()]), does not. In the first expression, if 'signal_name' is missing, the node will fail with an error. The second one will run even if there are no columns in the input. *Input ports*: :port0: Generic Input *Output ports*: :port1: table Table with results from the calculations. *Configuration*: **List of calculations** (calc_list) List of calculations. **(no label)** (calc_attrs_dict) Calculation attributes as json dict-list-string! **Copy input** (copy_input) If enabled the incoming data will be copied to the output before running the calculations. This requires that the results will all have the same length. An exception will be raised if the lengths of the outgoing results differ. **Action on calculation failure** (fail_strategy) Decide how a failed calculation should be handled .. automodule:: node_calculator .. class:: CalculatorGenericNode Example flows ############# * :download:`CalculateForAllColumns.syx ` * :download:`Calculator.syx ` Plugins ####### * :ref:`StdPlugin`