Unable to use UnwrapAngle() and Evaluate() in the same query in Grafana


I’m trying to create “advanced” dashboards; which means using the “advanced” functions of the OpenHistorian connector plugin.
I manage to use the Evaluate() function to build a graph that shows the apparent power :
Evaluate(0, {sqrt((active power PMU1)²+(reactive power PMU1)²)}, queries …).
Now I want to build a graph that displays the angle deviations over time between multiple PMUs.
To start, I started by using the UnwrapAngle() function which works fine :

The next step consists in carrying out a subtraction between these two series obtained; with a ‘slice’ parameter at 0 so that it is performed on each value obtained over time. To do that, I’ve tried the following query :
Evaluate(0, {P-R}, P=UnwrapAngle([units = Degrees], PMU1_NAME:V+_V1.ANG); R=UnwrapAngle([units = Degrees], PMU2_NAME:V+_V1.ANG));

This query returns a code “500 internal server error” :

Surprisingly, when I remove the ‘UnwrapAngle()’ function from the Evaluate query, it seems to work :

Evaluate(0, {P-R}, P=PMU1_NAME:V+_V1.ANG; R=PMU2_NAME:V+_V1.ANG);

The UnwrapAngle function description tells that it can be used to to make the values mathematically comparable ; but I don’t understand why I can’t use it with the Evaluate() function.
Bug or limitation (or syntax error …) ?

The end goal is to construct a ‘reference angle’ value which would be the average of all the PMU unwrapped V+ angles I have; then display a line graph for each PMU of [Reference unwrap V+ angle value] - [unwrap V+ angle value of PMU xx] over time. But if I can’t do this calculation between 2 PMU unwrap V+ angle; I’m not sure that it’s possible to make.

Thank you very much for the help ;



1 Like

Try this:

UnwrapAngle(Degrees, Evaluate(0, {P-R}, 

Hello @Korunekosama : I have been facing exactly the same issue! Could you share the calculation you did in Grafana? The code is done directly in the Grafana/dataSource:openHistorian/Query/FilterExpression/TextEditor? Thanks!

Hello Ricardo,
What do you exactly need to do ? Calculated the angle difference between two PMU V+ angles (or more PMU V+ angles related to a specified referenced one) ?
Or calculate the average of all your unwrapped PMU angles ; and use this value as a reference to calculate the delta with each PMU V+ angle ?

Hey, I’m looking to calculate angle difference between two angles but avoiding the “jumps” we face in the 180 - 0deg border. Also, takin the opportunity, to know how to plot all the angles againts a global reference. Is it possible to do this in Grafana or does it requires some analytics inside openHistorian? Thanks in advance!

Hello !
I don’t use the UnwrapAngle() function because when measurements have occasional data gaps, the calculated UnwrapAngle values ​​can give results below -180 or above +180; as you say (especially when you select significant time ranges of several hours to display):

I now use the following request in the Grafana text editor :
Label('PMU_1_Name', evaluate(0, {if(abs(b-a) > 180, if(sign(b-a) < 0, b-a+360, b-a-360), b-a)}, a=FILTER ActiveMeasurements WHERE PointTag LIKE '%:V+_V1.ANG%' AND PointTag LIKE '%$PMU1%'; b=FILTER ActiveMeasurements WHERE PointTag LIKE '%:V+_V1.ANG%' AND PointTag LIKE '%PMU_1_Name%'));

  • PMU_1_Name il the short/friendly name of the PMU I want the angle to be compared to my reference Angle
  • $PMU1 is the variable name I use to set/select my reference PMU.

I’ve got one request of that type for each PMU_x_Name I want to be shown on my graph.
This is what I’ve got :

Hope this can help you !

1 Like

Thanks for the tip! This has been a good inspiration using the function evaluate, I’m exploring more options now to plot the angle diff in the way the operator can use in real-life.
I implemented your equation and works fine:

Hello !
Glad that it works fine. Note that I found the ‘equation’ on this reference page gsf/Source/Documentation/GrafanaFunctions.md at master · GridProtectionAlliance/gsf (github.com)
It’s one of the examples given by GPA for the EVALUATE() function :

This reference web page has been a great help for me in building my dashboards.