Using Python Integration in Altair Activate to Access Data on PostgreSQL

João Marabisa
João Marabisa
Altair Employee
edited April 2023 in Altair HyperWorks

Abstract

In this article, it is described how to access sensor data on SQL databases using Python integration on Altair Activate.

Altair Activate is an open and flexible integration platform for systems simulation. Besides block-based modeling, it supports in the same environment different languages such as Open Matrix Language (OML), C, Python providing powerful possibilities for the users.

In this case, a block that supports Python language is used to access and manipulate data on PostgreSQL, that is a well-known object-relational database system.

In this case, the data came from real sensors, thus it is very noisy! Therefore, besides accessing and reading the data, a filter will be applied to analyze the data both in time and frequency domain.

image

Use Case

Several companies store the raw data acquired from sensors in a database, instead of having local files such as CSVs. It can help in terms of organizing data, saving local storage space, and even for security purposes.

Otherwise, accessing the database to get this data, then saving them locally, then manipulating this data (applying filters, doing FFTs) can be a nightmare for users once several tools could be involved on each process.

Below there is one example with a table data on PostgreSQL with acquired Accelerometer signals on the X, Y and Z axis (Ax, Ay, and Az respectively). As mentioned, the data are very noisy (blue lines) and a filter must be applied further to analyze the data.

image

Solution

Activate provides to the users the capability of accessing a SQL database, getting, and bringing the data (1) to its environment, filtering the data (2), and plotting (3) in a seamlessly way!


(1) There is a block called “PyCustomBlock” which is possible to insert Python codes with the desired libraries. In this case a “psycopg2” library is used to access, get, and manipulate the data on PostgreSQL. The data are brought to Activate and can be used in its environment.

image

(2) As mentioned, the data comes from Accelerometer sensors, it means that they are very noisy! In Activate there are different available ways to apply a filter based on each requirement. In this case a filter using transfer function block was used with custom parameters:

image

(3) Finally, it is possible to plot the data in different ways, firstly the different data were analyzed in time domain (the 3 sensors), zooming to see the filter acting:

image       

Besides that, a very nice capability on Activate was used to calculate the FFT in a few clicks to analyze the data in frequency domain based on the sampling frequency, as figure below (Sensor 1):

image

Conclusions

Activate provides a single interface for the users where is possible to perform different tasks such as PostgreSQL connection, Filtering and Plotting in the same environment.

Activate has a unique flexibility in terms of Python connectivity. It extends capabilities in terms of systems modeling, once Python already has several powerful libraries that can be integrated to the block diagram environment.

Finally, with a few clicks, users can transform a time-domain analysis to frequency-domain, helping to understand signal from accelerometers.