Convert Integer to Binary Signals

Recommended Posts

• Super Seeqer

If you have a signal in Seeq that is an integer representing an 8-bit 16-bit or 32-bit set of states here is some example code you can use to convert the integer signal into 8-16-32 separate 0/1 signals that can be used to define machine states elsewhere in the Seeq platform

Import Python packages

```from seeq import spy
import pandas as pd
import numpy as np```

`IntegerSignal = spy.search( <your method here> )`

Pull the signal for your time period of interest. This is a good place to add parameters such that this operation can be run on a schedule which is available in R52+

```IntegerSignalDF = spy.pull(IntegerSignal, start='2021-06-01', end='2021-06-03')
IntegerSignalDF```

Create a function to split your integer column into a number of different 1/0 columns

```# https://stackoverflow.com/questions/43738541/converting-one-int-to-multiple-bool-columns-in-pandas
def num2bin(nums, width):
return ((nums[:,None] & (1 << np.arange(width-1,-1,-1)))!=0).astype(int)```

Apply the function to your Integer Dataframe, you will also need to name the columns with the status's the represent. The num2bin function takes in the number of columns 8/16/32 as in an input

```statusExpanded = pd.DataFrame(num2bin(IntegerSignalDF.TestBinary.values,32),
index = IntegerSignalDF.index
,columns = ['Status 1',
'Status 2',
'Status 3',
'Status 4',
'Status 5',
'Status 6',
'Status 7',
'Status 8',
'Status 9',
'Status 10',
'Status 11',
'Status 12',
'Status 13',
'Status 14',
'Status 15',
'Status 16',
'Status 17',
'Status 18',
'Status 19',
'Status 20',
'Status 21',
'Status 22',
'Status 23',
'Status 24',
'Status 25',
'Status 26',
'Status 27',
'Status 28',
'Status 29',
'Status 30',
'Status 31',
'Status 32']
)```

Push the new signals back into your desired location inside Seeq

`spy.push(data = statusExpanded)`

Share on other sites

• 10 months later...

Here is another related post.

Create an account

Register a new account