About the Echoview Python source file

The Code operator and the Echoview Python source file

The Code operator executes the Python commands in the Echoview Python source file.

Each Echoview Python source file contains commands that

  • interface between Python and Echoview, and
  • characterize the Code operator's function.

You may create an Echoview Python source file from an empty text file. Refer to the OperatorBase class for the details. However, for convenience, we recommend you generate the default Echoview Python source file using the Code operator.

You can only specify one Echoview Python source file per Code operator.

Generating the default Echoview Python source file

  1. On a newly created Code operator, open the Variable Properties dialog box (press F8)
  2. On the Code page, find the Python source file filed, and click on New
  3. In the Windows dialog box specify the path and name for the Echoview Python source file, and click Save

Echoview creates the default Echoview Python source file, appends the .py extension to it, and opens the file in Windows Notepad (default).

You can change the default editor for the Echoview Python source file on the General page of the Echoview configuration dialog box.

Python source file indentation

The default Echoview Python source file uses tabs for Python code indentation.

You may choose to use spaces instead, but not mix both tabs and spaces.

File encoding

The default Echoview Python source file uses the UTF-8 file encoding system. Saving using a different encoding system can cause the Code operator to error.

Understanding the default Echoview Python source file

We will use the default Echoview Python source file to describe the commands that the Code operator requires to interface between Python and Echoview.

Here is a condensed version of the default Echoview Python source file, with the comments removed. The behavior is unchanged.

      from typing import List
      import echoview as ev
      import numpy as np

      class Operator(ev.OperatorBase):

          def eval(self, inputs: List[ev.OperandInput]):
              first_input = inputs[0]
              return first_input.measurement.data

Firstly, import List (from the typing module), and the echoview and numpy Python packages.

Next define the Operator class, deriving it from the OperatorBase class.

Finally, define the eval method within the Operator class. This method contains your Python command instructions for the Code operator.

In the case of the default Echoview Python source file, the line

      first_input = inputs[0]

assigns operand 1 to the Python variable first_input. Next,

      return first_input.measurement.data

communicates the ping sample data from Operand 1 to Echoview. Hence, the default Echoview Python source file simply programs the Code operator to return a copy of the ping sample values from Operand 1.

Executing an Echoview Python source file

Firstly, either specify the path to your Echoview Python source file, or generate a new Echoview Python source file on the Code page of the Variable Properties dialog box of the Code operator.

Then in Echoview, double-click on the Code operator dataflow object to execute the Echoview Python source file. This opens an echogram for the Code operator and displays the result.

A uniformly black echogram indicates an error.

See also

About the Code operator
Code operator
Using the Code operator