07-15-2022 03:30 AM
Hello,
I'm looking for a way to merge two channels from different channel groups.
The channel groups have their own date/time channel.
Here is a example of those two channels.
How can I merge them into one channel by time/date?
In Python with pandas you can achieve this with a join, is this also possible in DIAdem?
Thank you!
07-18-2022 01:56 AM
Hi blume,
As far as I know, the JOIN method is only applicable for strings. DIAdem channels do not provide such a function.
With such a question one must distinguish different conditions, in order to calculate the data physically correctly.
However, this can only be clarified exactly with the data itself.
Greetings
Walter
07-18-2022 02:52 AM
Hi Walter,
thanks for your response.
To clarify which conditions must be distinguished, I attached a example file containing two channel groups.
Can you help me merge these two channels?
Greetings
blume
07-18-2022 04:48 AM
Hi blume,
Here is a very fast script to join both channel pairs.
dim oGroupChns, oChnX1, oChnX2, oChnY1, oChnY2, oResultChnX, oResultChnY
dim iStartPos1,iStartPos2, iStopPos1, iStopPos2
' declare channel values
set oGroupChns = Data.Root.ChannelGroups(1).Channels
set oChnX1 = oGroupChns("Zeit")
set oChnX2 = oGroupChns("Zeit1")
set oChnY1 = oGroupChns("ComGM_Motorspeed")
set oChnY2 = oGroupChns("ComGM_Motorspeed1")
' extract relevant values for the first channel pair
ChnEventList1 = ChnEventDetectionWindow(oChnX1, oChnY1, 1, 500000, 0, 0)
Call ChnEventCreateFilteredTrueChn(oChnX1, ChnEventList1, oChnX1, NOVALUE)
Call ChnEventCreateFilteredTrueChn(oChnY1, ChnEventList1, oChnY1, NOVALUE)
Call ChnNovHandle(oChnX1, oChnY1, "Delete", "XY", True, False, 0)
' extract relevant values for the second channel pair
ChnEventList1 = ChnEventDetectionWindow(oChnX2, oChnY2, 1, 500000, 0, 0)
Call ChnEventCreateFilteredTrueChn(oChnX2, ChnEventList1, oChnX2, NOVALUE)
Call ChnEventCreateFilteredTrueChn(oChnY2, ChnEventList1, oChnY2, NOVALUE)
Call ChnNovHandle(oChnX2, oChnY2, "Delete", "XY", True, False, 0)
' concatenate both X channels
Set oResultChnX = ChnConcatenateChannels(oChnX1, oChnX2, False, False, False)
' concatenate both Y channels
Set oResultChnY = ChnConcatenateChannels(oChnY1, oChnY2, False, False, False)
oResultChnX(1).Name = "JoinedChnX"
oResultChnY(1).Name = "JoinedChnY"
' sort both channels time related
call ChnMultipleSortExt(oResultChnX(1), oResultChnY(1), "Up", "UpperCase", true)
Greetings
Walter
07-18-2022 06:33 AM
Hi Walter,
thank you very much for your response.
I'm sorry to bother you again, but how can I use this script when I have more y-channels?
I attached another example.csv file with more y-channels.
Sorry and thank you again!
Greetings
blume
07-18-2022 07:10 AM
Hi blume,
here is my suggestion for this.
dim oGroupChns, oChnX1, oChnX2, oChnY1, oChnY2, oResultChnX, oResultChnY
dim iStartPos1,iStartPos2, iStopPos1, iStopPos2
dim oResGroup, oResGroupChns, oResChnX1, oResChnX2, oResChnY1, oResChnY2
' declare channel values
set oGroupChns = Data.Root.ChannelGroups(1).Channels
set oChnX1 = oGroupChns("Zeit")
set oChnY1 = oGroupChns("ComGM_Motorspeed")
set oChnX2 = oGroupChns("Zeit_1")
set oChnY2 = oGroupChns("ComGM_Motorspeed_1")
set oResGroup = Data.Root.ChannelGroups.Add("Result_" & oChnY1.Name)
set oResGroupChns = oResGroup.Channels
set oResChnX1 = oResGroupChns.AddChannel(oChnX1)
set oResChnY1 = oResGroupChns.AddChannel(oChnY1)
set oResChnX2 = oResGroupChns.AddChannel(oChnX2)
set oResChnY2 = oResGroupChns.AddChannel(oChnY2)
call oResGroup.Activate
call JoinChannels(oResChnX1, oResChnX2, oResChnY1, oResChnY2)
set oChnY1 = oGroupChns("ComGM_AbsSollDrehzahl")
set oChnY2 = oGroupChns("ComGM_AbsSollDrehzahl_1")
set oResGroup = Data.Root.ChannelGroups.Add("Result_" & oChnY1.Name)
set oResGroupChns = oResGroup.Channels
set oResChnX1 = oResGroupChns.AddChannel(oChnX1)
set oResChnY1 = oResGroupChns.AddChannel(oChnY1)
set oResChnX2 = oResGroupChns.AddChannel(oChnX2)
set oResChnY2 = oResGroupChns.AddChannel(oChnY2)
call oResGroup.Activate
call JoinChannels(oResChnX1, oResChnX2, oResChnY1, oResChnY2)
set oChnY1 = oGroupChns("ComGM_BattVolt")
set oChnY2 = oGroupChns("ComGM_BattVolt_1")
set oResGroup = Data.Root.ChannelGroups.Add("Result_" & oChnY1.Name)
set oResGroupChns = oResGroup.Channels
set oResChnX1 = oResGroupChns.AddChannel(oChnX1)
set oResChnY1 = oResGroupChns.AddChannel(oChnY1)
set oResChnX2 = oResGroupChns.AddChannel(oChnX2)
set oResChnY2 = oResGroupChns.AddChannel(oChnY2)
call oResGroup.Activate
call JoinChannels(oResChnX1, oResChnX2, oResChnY1, oResChnY2)
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
sub JoinChannels(oChnX1, oChnX2, oChnY1, oChnY2)
' extract relevant values for the first channel pair
ChnEventList1 = ChnEventDetectionWindow(oChnX1, oChnY1, 1, 500000, 0, 0)
Call ChnEventCreateFilteredTrueChn(oChnX1, ChnEventList1, oChnX1, NOVALUE)
Call ChnEventCreateFilteredTrueChn(oChnY1, ChnEventList1, oChnY1, NOVALUE)
Call ChnNovHandle(oChnX1, oChnY1, "Delete", "XY", True, False, 0)
' extract relevant values for the second channel pair
ChnEventList1 = ChnEventDetectionWindow(oChnX2, oChnY2, 1, 500000, 0, 0)
Call ChnEventCreateFilteredTrueChn(oChnX2, ChnEventList1, oChnX2, NOVALUE)
Call ChnEventCreateFilteredTrueChn(oChnY2, ChnEventList1, oChnY2, NOVALUE)
Call ChnNovHandle(oChnX2, oChnY2, "Delete", "XY", True, False, 0)
' concatenate both X channels
Set oResultChnX = ChnConcatenateChannels(oChnX1, oChnX2, False, False, False)
' concatenate both Y channels
Set oResultChnY = ChnConcatenateChannels(oChnY1, oChnY2, False, False, False)
oResultChnX(1).Name = "Joined_" & oChnY1.Name & "_Time"
oResultChnY(1).Name = "Joined_" & oChnY1.Name
' sort both channels time related
call ChnMultipleSortExt(oResultChnX(1), oResultChnY(1), "Up", "UpperCase", true)
end sub
Greetings
Walter
07-18-2022 08:27 AM
Hi Walter,
In your solution, each newly created joined channel has its own time channel.
Is it possible to get only one time channel for all joined channels?
Greetings
blume