DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Slow calculate function

Hello,

 

I need a faster way to calculate formulas with sine and cosine, with highly sampled input signals (2048Hz).

 

Example:

Call Calculate("ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_UPP_MX_CALC"")=ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_UPP_MXY_A"")*cos(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MXY_CALC"")))+ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_UPP_MYX_A"")*cos(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MYX_CALC"")))")

 

Any suggestions?

 

Thanks,

Jacques

 

 

0 Kudos
Message 1 of 2
(912 Views)

Hello,

 

I tried to use arrays with a GetValuesBlock, loop through the arrays for the calculation, and then store the result back in a channel with a SetValuesBlock, but it's only marginally faster.

 

I then tried to use Python and numpy arrays, with DIAdem 2020 (hence Python 3.7)

from DIAdem import Application as dd

if False:
    import DIAdem_CodeCompletion as dd

# --------------------------------------------------------------------
# -- Beginning of user code --

import numpy as np

aMX = np.array(dd.Data.Root.ChannelGroups(1).Channels("MX").GetValuesBlock())
aMZ = np.array(dd.Data.Root.ChannelGroups(1).Channels("MZ").GetValuesBlock())
aAziMX = np.array(dd.Data.Root.ChannelGroups(2).Channels("ANG_MX_CALC").GetValuesBlock())
aAziMZ = np.array(dd.Data.Root.ChannelGroups(2).Channels("ANG_MZ_CALC").GetValuesBlock())


aHCX = -aMX*np.sin(np.radians(aAziMX)) - aMZ*np.sin(np.radians(aAziMZ))
aHCZ = -aMX*np.cos(np.radians(aAziMX)) - aMZ*np.cos(np.radians(aAziMZ))


dd.Data.Root.ChannelGroups(1).Channels.Add("HCX_CALC",dd.DataTypeChnFloat64,1).SetValuesBlock(aHCX.tolist())
dd.Data.Root.ChannelGroups(1).Channels.Add("HCZ_CALC",dd.DataTypeChnFloat64,1).SetValuesBlock(aHCZ.tolist())

print("done")

 

It is about 5 times faster, which is good.

I think what takes time is to store the channel data in a numpy array.

Is the method I use the correct method? Is there a faster way?

 

When trying the same calculation with PyCharm (Python 3.10) and npTDMS module, everything is much faster, almost instantaneous. However, we would rather stick to DIAdem (soon 2023, hopefully), for now.

 

Thanks,

Jacques

 

 

 

Message 2 of 2
(858 Views)