07-11-2013 01:50 PM
Is there a way of isolating statistical quantities of a data set (specifically looking for minimum maximum and average) via the band cursor and display those values WITHIN the view window of DIAdem 2011 (ie without flagging the data, making a copy of it, and then running the analysis)? Any help would be greatly appreciated.
Solved! Go to Solution.
07-11-2013 10:23 PM
Hi dc13,
See if your version of DIAdem has the example "Dynamic Display of Statistical Characteristic Values in DIAdem VIEW". It sounds like exactly what you're asking for. The example released first with DIAdem 11.0.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
07-12-2013 11:55 AM
Hi Brad,
That is almost exactly what I am looking for. However I do need to modify it a bit for my use. Thanks for the help.
As I am modifying I notice it will suit my needs almost 100%. However, I want the script to initialize for a data set I have in the data portal. I have tried numerous different configurations of path variable, but have been unsuccessful. Any insight into how I might achieve this?
07-19-2013 12:15 PM
Hi dc13,
Do you want to look at the statistical values of one curve or of multiple curves/channels?
What do you do next with those statistical values? Display them in a REPORT? Save them back to disk with the data? Copy and paste them to Excel or Notepad?
Brad Turpin
DIAdem Product Support Engineer
National Instruments
07-23-2013 10:30 AM
Hi Brad,
I actually called technical support and got my issue resolved. Thank you for guiding me to this example though. It was extremely helpful.
06-08-2016 08:12 AM
Hello dc13,
Could you post your solution? I would like to konw how to do this as well.
06-09-2016 04:32 PM
Hi Damian,
See if your version of DIAdem has the example "Dynamic Display of Statistical Characteristic Values in DIAdem VIEW". It's a really nice example you can use on your own data sets.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
07-18-2016 12:49 PM
Brad,
I wanted to follow up with you. That works great. Thanks for the suggestion.
07-02-2021 07:56 AM - edited 07-02-2021 07:58 AM
Thank you for your help. I post this to save others time in finding the script.
@ Damian_S: Your screenshot isn't helping - I don't get what you want to show (except success) 🙂
I was looking for the example, and had to search for it quite a while:
https://zone.ni.com/reference/en-XX/help/370858P-01/exploff/examples/view_statistic_init/
cause I got the German version of Diadem it is called "Dynamische Anzeige statistischer Kennwerte in DIAdem-VIEW" (index->Examples->"create scripts"(?)->"user dialogues"(?, = first sub-section)". You may search for "VIEW_Statistic".
' ----------------------------------------------------------------------------------------
' Name : ---
' Author : National Instruments Ireland Resources Limited
' Comment : ---
' ----------------------------------------------------------------------------------------
Option Explicit
If Not ItemInfoGet("sPathDocuments") Then
Call GlobalDim("sPathDocuments")
Call GlobalDim("sPathData")
End If
sPathData = ProgramDrv & "Examples\Data\"
sPathDocuments = ProgramDrv & "Examples\Documents\"
'-------------------------------------------------------------------------------
if not BarManager.ActionObjs.Exists( "VIEWStatisticActionObj") then
' Include function to copy ICO files
call ScriptInclude(sPathDocuments & "REPORT_Library")
' Register cursor Event procedures
call ScriptCmdAdd(CurrentScriptPath & "VIEW_Statistic_UserCMD.VBS")
' - ########## -
call PrepareViewOnlyForDemo
' - ########## -
call CheckAndCopyIconFiles(sPathDocuments)
call Init_VIEWStatisticSymbolExtensions
Call WndShow("VIEW","MAXIMIZE")
call msgbox("Stellen Sie in einem 2D-Achsensystem eine Kurve dar, wählen Sie einen Band-Cursor und aktivieren Sie über das neue Befehlssymbol die Statistik-Funktion.")
end if
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
sub PrepareViewOnlyForDemo
dim sDataPath, oArea
sDataPath = ProgramDrv & "Examples\Data\"
call Data.Root.Clear
call DataFileLoad(sDataPath & "Example_data.tdm", "TDM", "Load|ChnXYRelation")
call View.NewLayout
set oArea = View.ActiveSheet.Areas(1)
oArea.DisplayObjType = "CurveChart2D"
call oArea.DisplayObj.Curves2D.Add("", "[2]/[1]")
end sub
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
sub Init_VIEWStatisticSymbolExtensions
Dim sIconName, sToolTip, sCommand, oVIEWStatisticBar
set oVIEWStatisticBar = CreateActionObjBar
'------------------------------------------------
' Insert separator and Shut-Down-Command for VIEW
if not BarManager.Bars("VIEWMain").UsedActionObjs.Exists(oVIEWStatisticBar) then
call BarManager.Bars("VIEWMain").UsedActionObjs.Add("Separator")
call BarManager.Bars("VIEWMain").UsedActionObjs.Add(oVIEWStatisticBar)
end if
end sub
'-------------------------------------------------------------------------------
' Create new action object -----------------------------------------------------
'-------------------------------------------------------------------------------
function CreateActionObjBar
dim oActionObj, sVIEWStatisticActionObjID, sVIEWStatisticBarID, oToolBar
Dim sIconName, sToolTip, sCommand, oVIEWStatisticBar
sVIEWStatisticBarID = "VIEWStatisticBar"
sVIEWStatisticActionObjID = "VIEWStatisticActionObj"
if not BarManager.Bars.Exists(sVIEWStatisticBarID) then
set oToolBar = BarManager.Bars.Add(sVIEWStatisticBarID)
else
set oToolBar = BarManager.Bars.Item(sVIEWStatisticBarID)
end if
if (BarManager.ActionObjs.Exists(sVIEWStatisticActionObjID)) then
set oActionObj = BarManager.ActionObjs(sVIEWStatisticActionObjID)
else
set oActionObj = BarManager.ActionObjs.Add(sVIEWStatisticActionObjID, "CustomPopup")
oActionObj.Picture = "DIAdemVIEWStatistic.ico"
oActionObj.Tooltip = "VIEW-Statistik"
oActionObj.BarID = oToolBar.ID
end if
sIconName = "DIAdemVIEWStatistic.ico"
sToolTip = "VIEW-Statistik aktivieren"
sCommand = "call ItemInfoGet(""ProcessVIEW_Statistic"") : if ItemInfoType <> ""ScriptCommand"" then " & _
"call ScriptCmdAdd(ProgramDrv & ""Examples\Documents\"" & ""VIEW_Statistic_UserCMD.VBS"") end if : " & _
"call ScriptStart(""" & sPathDocuments & "VIEW_Statistic_Init"", ""VIEW_Statistic_Initialize"")"
'sCommand = "Call ScriptStart(""" & sPathDocuments & "VIEW_Statistic_Init"", ""VIEW_Statistic_Initialize"")"
call CreateActionButton("DIAdemVIEWStatistic", sIconName, sToolTip, sCommand, oToolBar)
sIconName = "expl_Delete.ico"
sToolTip = "VIEW-Statistik aktivieren und Befehlssymbol löschen"
sCommand = "Call ScriptStart(""" & sPathDocuments & "VIEW_Statistic_Init"", ""VIEW_StatisticBarRemove"")"
call CreateActionButton("DIAdemVIEWStatisticReset", sIconName, sToolTip, sCommand, oToolBar)
set CreateActionObjBar = oActionObj
end function
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
' New ActionButtonObject
' sID : Unique ID for new button
' sIconName : Icon that is displayed
' sToolTip : Note to be displayed
' sCommand : Command to be executed
'-------------------------------------------------------------------------------
sub CreateActionButton(sUniqueButton_ID, sIconName, sToolTip, sCommand, oToolBar)
dim oButtonObj, bActionObjExists
if (BarManager.ActionObjs.Exists(sUniqueButton_ID)) then
set oButtonObj = BarManager.ActionObjs(sUniqueButton_ID)
bActionObjExists = true
else
set oButtonObj = BarManager.ActionObjs.Add(sUniqueButton_ID, "CustomButton")
bActionObjExists = false
end if
oButtonObj.Picture = sIconName
oButtonObj.Tooltip = sToolTip
oButtonObj.OnClickCode.Code = sCommand
if not bActionObjExists then
oToolBar.UsedActionObjs.Add(oButtonObj)
end if
end sub
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
sub VIEW_StatisticBarRemove
if BarManager.ActionObjs.Exists("VIEWStatisticActionObj") then
call BarManager.ActionObjs.Remove("VIEWStatisticActionObj")
end if
if BarManager.ActionObjs.Exists("DIAdemVIEWStatistic") then
call BarManager.ActionObjs.Remove("DIAdemVIEWStatistic")
end if
if BarManager.ActionObjs.Exists("DIAdemVIEWStatisticReset") then
call BarManager.ActionObjs.Remove("DIAdemVIEWStatisticReset")
end if
if not SudNonModalDlgLst("Result_Dlg") Is Nothing then
call SudNonModalDlgLst("Result_Dlg").Cancel
end if
end sub
'-------------------------------------------------------------------------------
'###############################################################################
'-------------------------------------------------------------------------------
sub VIEW_Statistic_Initialize
dim sPathDocuments
Dim oSUDPara, iErrNo, sErrText
sPathDocuments = CurrentScriptPath
' Prepare statistics functions
call InitStatistic
' Prepare SUD dialog info texts
Call InitSUDParameter(oSUDPara)
' Select statistical characteristic values
if SUDDlgShow("VIEW_Statistic_Dlg",CurrentScriptPath & "VIEW_Statistic.SUD", oSUDPara) = "IDOk" then
' Create VIEW layout
call CheckVIEWLayout(oSUDPara, iErrNo)
if iErrNo = 0 then
' Activate event
call AddUserCommandToEvent("View.Events.OnCursorChanged", "ProcessVIEW_Statistic")
'View.Events.OnActiveSheetChanged = ""
' Open, initialize, and start non-modal dialog box
Dim oMySUD
if SudNonModalDlgLst("Result_Dlg") Is Nothing Then
'Dialog not yet created
set oMySUD = SUDDlgCreate("Result_Dlg",CurrentScriptPath & "VIEW_Statistic.SUD")
Else
'Dialog already created
Set oMySUD = SudNonModalDlgLst("Result_Dlg")
End If
call InitNonModalDlg(oMySUD, oSUDPara)
oMySUD.show
' Initialize non-modal SUD dialog box
Dim oMyCurve, xStart, xEnd, X1_Val, X2_Val, XMean_Val
Set oMyCurve = view.ActiveSheet.ActiveArea.DisplayObj.Curves2D.LeadingCurve
dim sFormatX
call GetStartEndPos(xStart, xEnd, X1_Val, X2_Val, XMean_Val, sFormatX)
Call CalcStatisticValues(oMyCurve.YChannelName, xStart, xEnd, X1_Val, X2_Val, XMean_Val, sFormatX)
' Activate event
call AddUserCommandToEvent("DIAdem.OnPanelChanged", "IfPanelChangedCloseSUD")
else
select case iErrNo
case 1 sErrText = "Es muss ein 2D-Achsensystem eingestellt sein."
case 2 sErrText = "Es müssen Kanäle eingetragen sein."
end select
msgbox sErrText & vbCRLF & vbCRLF & _
"Nach Anpassung bitte die Funktion neu starten."
end if
else
call msgbox("Sie haben den Dialog abgebrochen. DIAdem beendet das Script.")
end if
end sub
' ----------------------------------------------------------------------------------------
' Activate VIEW and create layout ---------------------------------------------------
' ----------------------------------------------------------------------------------------
sub CheckVIEWLayout(oSUDParameter, iErrorNo)
Dim dXPos1, dXPos2, oCurrSheet, oCurrArea
iErrorNo = 0 ' VIEW is OK
' Activate VIEW and define layout
Call WndShow("VIEW","SHOW")
set oCurrSheet = View.ActiveSheet
set oCurrArea = oCurrSheet.ActiveArea
if oCurrArea.DisplayObjType = "CurveChart2D" then
oCurrSheet.Cursor.Type = "Band"
oCurrSheet.Cursor.Mode = "GraphPoints"
if oCurrArea.DisplayObj.Curves2D.Count > 0 then
Call View.Refresh()
oCurrArea.DisplayObj.DoubleBuffered = true
else
iErrorNo = 2 ' no channel assigned
end if
else
iErrorNo = 1 ' wrong display type
end if
end sub
' ----------------------------------------------------------------------------------------
' Initialize statistics parameters ------------------------------------------------------
' ----------------------------------------------------------------------------------------
sub InitStatistic
StatSel(1) ="No" ' Current number
StatSel(2) ="No" ' Measured valeu sum
StatSel(3) ="No" ' Measured value square sum
StatSel(4) ="Yes" ' Minimum value
StatSel(5) ="Yes" ' Maximum value
StatSel(6) ="Yes" ' Arithmetic mean
StatSel(7) ="No" ' Quadratic mean
StatSel(8) ="No" ' Geometric mean
StatSel(9) ="No" ' Harmonic mean
StatSel(10) ="No" ' 0.25 quantile (lower quartile)
StatSel(11) ="No" ' 0.50 quantile (median)
StatSel(12) ="No" ' 0.75 quantile (upper quartile)
StatSel(13) ="No" ' Range
StatSel(14) ="No" ' Standard deviation
StatSel(15) ="No" ' Variance
StatSel(16) ="No" ' Variation coefficient
StatSel(17) ="No" ' Quartile distance
StatSel(18) ="No" ' Relative variation coefficient
StatSel(19) ="No" ' Average absolute deviation from mean
StatSel(20) ="No" ' Averge absolute deviation from median
StatSel(21) ="No" ' Skewness
StatSel(22) ="No" ' Kurtosis
StatSel(23) ="No" ' Standard error
end sub
' ----------------------------------------------------------------------------------------
' Define message text for SUD -------------------------------------------------------
' ----------------------------------------------------------------------------------------
Sub InitSUDParameter(ByRef oSUDParameter)
set oSUDParameter = New cSUDParaClass
oSUDParameter.sXChn = ""
oSUDParameter.sYChn = ""
oSUDParameter.sMsgTextArray(0) = "Es muss mindestens eine statistische Funktion ausgewählt werden."
oSUDParameter.sMsgTextArray(1) = "Es muss ein X-Kanal und ein Y-Kanal ausgewählt werden."
End Sub
' ----------------------------------------------------------------------------------------
' Class for script and SUD data exchange -----------------------------------------------
' ----------------------------------------------------------------------------------------
Class cSUDParaClass
Dim sXChn, sYChn, sMsgTextArray(2)
end Class
' ----------------------------------------------------------------------------------------
' Preparations for non-modal SUD dialog box --------------------------------------------
' ----------------------------------------------------------------------------------------
sub InitNonModalDlg(oMySUD, oSUD)
Dim iIdx, iCount
iCount = 0
iIdx = 1
oMySUD.Controls(iIdx).Text = "Kanal: " & oSUD.sYChn
iIdx = iIdx + 1
if StatSel( 2) = "Yes" then oMySUD.Controls(iIdx).Text = "Messwertsumme: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel( 3) = "Yes" then oMySUD.Controls(iIdx).Text = "Messwertquadratsumme: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel( 4) = "Yes" then oMySUD.Controls(iIdx).Text = "Minimalwert: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel( 5) = "Yes" then oMySUD.Controls(iIdx).Text = "Maximalwert: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel( 6) = "Yes" then oMySUD.Controls(iIdx).Text = "Arithmetisches Mittel: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel( 7) = "Yes" then oMySUD.Controls(iIdx).Text = "Quadratisches Mittel: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel( = "Yes" then oMySUD.Controls(iIdx).Text = "Geometrisches Mittel: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel( 9) = "Yes" Then oMySUD.Controls(iIdx).Text = "Harmonisches Mittel: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(10) = "Yes" then oMySUD.Controls(iIdx).Text = "0.25-Quantil: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(11) = "Yes" then oMySUD.Controls(iIdx).Text = "0.50-Quantil: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(12) = "Yes" then oMySUD.Controls(iIdx).Text = "0.75-Quantil: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(13) = "Yes" then oMySUD.Controls(iIdx).Text = "Spannweite: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(14) = "Yes" then oMySUD.Controls(iIdx).Text = "Standardabweichung: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(15) = "Yes" then oMySUD.Controls(iIdx).Text = "Varianz: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(16) = "Yes" then oMySUD.Controls(iIdx).Text = "Variationskoeffizient: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(17) = "Yes" then oMySUD.Controls(iIdx).Text = "Quartilabstand: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(18) = "Yes" then oMySUD.Controls(iIdx).Text = "Relativer Variationskoeffizient:" : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(19) = "Yes" then oMySUD.Controls(iIdx).Text = "Mittl. abs. Abw. vom Mittelwert:" : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(20) = "Yes" then oMySUD.Controls(iIdx).Text = "Mittl. abs. Abw. vom Median: " : iIdx = iIdx + 2 : iCount = iCount + 1
if StatSel(21) = "Yes" then oMySUD.Controls(iIdx).Text = "Schiefe: " : iIdx = iIdx + 2 : iCount = iCount + 1
If StatSel(22) = "Yes" then oMySUD.Controls(iIdx).Text = "Wölbung: " : iIdx = iIdx + 2 : iCount = iCount + 1
oMySUD.Controls("tXStartText").Text = "Beginn: "
oMySUD.Controls("tXStopText").Text = "Ende: "
oMySUD.Controls("tXMeanText").Text = "Mittelwert: "
oMySUD.Height = 52 + (iCount + 1) * 10
oMySUD.MinHeight = oMySUD.Height
oMySUD.Controls("Frame2").Height = oMySUD.Height - oMySUD.Controls("Frame2").Top - 2
dim iLoop
for iLoop = 1 to iCount
oMySUD.Controls("Text" & str(2 * iLoop - 1)).Visible = true
oMySUD.Controls("Text" & str(2 * iLoop)).Visible = true
next
End sub