How to Read Time Data from CI Data Files in Python & Matlab
Introduction
The ATFX API consists of two DLL files that can be integrated with custom software to directly read and extract data from an ATFX file. This post will show a simple Python & Matlab code example in extracting and creating a DateTimeNano object that has accuracy in nanoseconds.
The DateTimeNano class is a subclass of the DateTime class from Microsoft with additional properties and functions to extend the accuracy of DateTime to nanoseconds.
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 ATFX API manual and the provided C#, Python & Matlab Demo code. The package can be downloaded from our Programming Corner.
Extracting and Creating Time Data with Accuracy in Nanoseconds for Python
To create a DateTimeNano object from the ATFX file, the recording property CreateTime and a class, NVHMeasurement, to access NanoSecondElapsed are needed to put into the constructor. For Python, it is not going to accept just NVHMeasurement.NanoSecondElapsed as its datatype is int and not uint32. To cast to UInt32, the following import is needed, from System import * and the following call, UInt32().
The code sample below demonstrates the creation process and several of the new properties in the DateTimeNano class, such as ms_us_ns which shows Milisecond, Microsecond and Nanosecond in 000/000/000 format.
recordingPath = "C:\\Users\\KevinCheng\\Downloads\\gps test example\\" #OpenRecording(string, out IRecording) recording = ODSNVHATFXMLRecording(recordingPathTS) bGPS = nvhMeasurement.GPSEnabled if not String.IsNullOrEmpty(nvhRec.Environment.TimeZone):
print("Created Time (Local): ", nvhRec.RecordingProperty.CreateTime) dateTimeNano = DateTimeNano(nvhRec.RecordingProperty.CreateTime, UInt32(nvhMeasurement.NanoSecondElapsed)) |
Extracting and Creating Time Data with Accuracy in Nanoseconds for Matlab
To create a DateTimeNano object from the ATFX file, the recording property CreateTime and a class, NVHMeasurement, to access NanoSecondElapsed are needed to put into the constructor.
The below code sample shows the creation process and several of the new properties in the DateTimeNano class, such as ms_us_ns which shows Milisecond, Microsecond and Nanosecond in 000/000/000 format.
%create a atfx recording instance dateTimeNano = Common.DateTimeNano(rec.RecordingProperty.CreateTime, rec.Measurement.NanoSecondElapsed) |