Example Using No Python Modules or Functions

Problem Definition

In this example, we want to perform gross error detection on a signal "Signal" and clip the values to a range between 0 and 600.

Expression

To solve this, we create the following Python expression.

0 if Signal.value<0 else (600 if Signal.value>600 else Signal.value)
Python DatatypeNameDescription
Expression InputsSingleFloatSignalRepresents the signal value.
Expression ResultSingleFloat Not Applicable Represents the resulting expression value, with extreme outliers clipped.

Python Modules to Import for this Expression

None

(Only modules contained on the list of supported modules are available for this expression.)

Constructing the JSON

Using the created expression, we construct the following JSON. For more information, refer to Constructing the JSON Configuration.
"script":"0 if Signal.value<0 else (600 if Signal.value>600 else Signal.value)", "parameters":[
{
"name":" Signal",
"source":{"address":"Simulation00001", "dataType":"SingleFloat"}
}
]
}

Note that the address parameter is stipulated in the context of the chosen collector, which must be on the list of collectors supporting Python Expression Tags.

In this example, we have used the Simulation Collector. Your collector might use a different source address.

We then transform the above into a minified JSON string:
{"script":"0 if Signal.value < 0 else (600 if Signal.value > 600 else Signal.value)","parameters":
[{"name":"Signal","source":{"address":"Simulation00001",dataType":"SingleFloat"}}]}

Adding the Expression Tag to Historian

For this example, we choose to add a Python Expression tag to the Historian using the File Collector to import a CSV file. (We could also have added the tag via the Historian Excel Add-In.)

The file contents look like this:
[Tag]
Tagname,CollectorName,CalcType,SourceAddress,DataType,DescriptionGEDSignalTag,SimulationCollector,PythonExpr,
"{""script"":""0 if Signal.value < 0 else (600 if Signal.value > 600 else Signal.value)"",""parameters"":
[{""name"":""Signal"",""source"":{""address"":""Simulation00001"",""dataType"":""SingleFloat""}}]}",
SingleFloat,Python Expression Tag example
Note the following:
  • The CalcType header is included and set to PythonExpr.
  • The Source Address is set to the minified JSON created in the previous step.
  • The CollectorName is set to SimulationCollector, which is a Simulation Collector. Your collector might be called by a different name.
  • The quotation marks within the JSON string are escaped with other quotation marks.

We then import the file, following the instructions specified in File Collector.