How to read and convert a CI Data File signal to Pandas dataframe
Introduction
The CI Data File Reader API consists of two DLL files that can be integrated with custom software to directly read and extract data from an ATFX file. This article will demonstrate how to read various signals from an ATFX file and convert them into a Pandas Dataframe following a specific format.
For a simple way to import the C# dll files and open an ATFX file in Python & Matlab, please refer to the How to Read CI Data Files in Python and / or How to Read CI Data Files in Matlab article.
For more detailed information on how to implement the following code sections and properties in a class, please refer to the CI Data File Reader manual and the provided C#, Python & Matlab Demo code. The package can be downloaded from our Programming Corner.
The following Python script uses two packages, numpy and pandas, that can be installed using the following commands in the operating system command prompt or integrated development environment software terminal.
pip install numpy
pip install pandas
Reading and Converting to Pandas Dataframe
The following python script can be found in: Convert_to_Pandas_Dataframe.py.
The import modules for the script are below.
#---Pythonnet clr import clr.AddReference(parentPath + "CI.ATFX.Reader.dll") import numpy as np #---C# .NET imports & dll imports |
The next function takes in the ATFX file path, extracts the signals, converts and outputs to a pandas dataframe.
The function initially starts by opening the ATFX file, obtaining the signal list, and setting up some starting variables.
# Function for converting signals from an ATFX file into a pandas dataframe in a specific order below: # Get a list of signals PREFIX = 'EoT ' |
Signal list filtering can filter drive or time domain signals from the list. It can also keep any frequency domain signals while filtering out specified signals, such as H(f).
# Find the specific signal in the signal list |
Once the signals are filtered, next is obtaining the signal frame data, then converting the System.Double[] object into a numpy array and assigning it to a pandas dataframe.
# Get the signal frame and if the ATFX file is from a Swept Sine test then use (EU)RMS # if the signal is profile(f), get the Frequency column and profile(f) column and assign them at the beginning of the dataframe |
After the signal list has been filtered and the pandas dataframe contains the necessary data, next is the proper ordering of the columns in the dataframe which is as follows:
Frequency, profile(f), control(f), HighAbort, HighAlarm, LowAlarm, LowAbort, APS / Spectrum (Table), APS / Spectrum (Ch#)
# Set up the proper order by getting the specific columns of the first dataframe and assigning to a new dataframe |
The main run block of the script is below with an example screenshot.
# Change file path here to whereever signal or recording files are |