07-29-2021 03:38 AM
I am trying to use the calculator function in a python script because I want to use CTNV to remove max and min values from a channel. I can get it to work by using VBS but it doesn't work in Python. For example the formula below will run in VBS but not in Python. What am I doing wrong?
VBS
Call Calculate("Ch(""[1]/ESP_v_Signal"") = 1")
Python
strRef = "[1]/ESP_v_Signal"
dd.Calculate('Ch(""+strRef+"") = 1')
Solved! Go to Solution.
07-30-2021 04:00 AM
Please have a look at this example:
VBS:
Dim sFormula, aSymbol(2), aValues(2) sFormula = "R1 = A / B" aSymbol(1) = "A" aSymbol(2) = "B" aValues(1) = 2 aValues(2) = 3 Call Calculate (sFormula, aSymbol, aValues) Call MsgboxDisp(R1)
Python:
sFormula = "R1 = A / B" aSymbol[1] = "A" aSymbol[2] = "B" aValues[1] = 2 aValues[2] = 3 dd.Calculate (sFormula, aSymbol, aValues) dd.MsgboxDisp(dd.R1)
Greetings
Walter
07-30-2021 06:21 AM
Hi Walter,
I have tried implementing the example from the Diadem help but it still isn't working for my Python code below
aSymbol = []
aValues = []
sFormula = 'Ch(""[1]/Result"") = A / B'
aSymbol.append("A")
aSymbol.append("B")
aValues.append(dd.Data.GetChannel("[1]/[1]"))
aValues.append(dd.Data.GetChannel("[1]/[2]"))
dd.Calculate(sFormula, aSymbol, aValues)
07-30-2021 06:55 AM
You are right, I didn't test is.
This here works on my side, tested in DIAdem 2021:
oChnA = dd.Data.GetChannel("[1]/[2]") oChnB = dd.Data.GetChannel("[1]/[3]") oRes = dd.Data.Root.ActiveChannelGroup.Channels.Add("Result",dd.DataTypeChnFloat64 ) aSymbol = [] aValues = [] sFormula = "R = A / B" aSymbol = ["R", "A", "B"] aValues = [oRes, oChnA, oChnB] dd.Calculate(sFormula, aSymbol, aValues)
07-30-2021 07:15 AM
Thanks that has solved the problem! 😀
My code using CTNV in the formula in case it helps anyone else
oChnA = dd.Data.GetChannel("[1]/[1]")
oChnB = dd.Data.GetChannel("[1]/[2]")
oRes = dd.Data.GetChannel("[1]/[3]")
aSymbol = []
aValues = []
sFormula = "R = A + CTNV(A>800)"
aSymbol = ["R", "A", "B"]
aValues = [oRes, oChnA, oChnB]
dd.Calculate(sFormula, aSymbol, aValues)