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\\"
recordingPathTS = recordingPath + "(1).atfx"

#OpenRecording(string, out IRecording)
# openRecordSucceed is required for the OpenRecording as it is the returned boolean

openRecordSucceed, recording = RecordingManager.Manager.OpenRecording(recordingPathTS, None)

recording = ODSNVHATFXMLRecording(recordingPathTS)
nvhRec = recording
nvhMeasurement = nvhRec.Measurement
nvhEnvironment = nvhRec.Environment

bGPS = nvhMeasurement.GPSEnabled
if bGPS:
    print("GPS Enabled: ", bGPS)
    print("Longitude: ", nvhMeasurement.Longitude)
    print("Latitude: ", nvhMeasurement.Latitude)
    print("Altitude: ", nvhMeasurement.Altitude)
    print("Nanoseconds Elapsed: ", nvhMeasurement.NanoSecondElapsed)

if not String.IsNullOrEmpty(nvhRec.Environment.TimeZone):
    print("Time Zone: ", nvhRec.Environment.TimeZone)

print("Created Time (Local): ", nvhRec.RecordingProperty.CreateTime)
print("Created Time (UTC): ", nvhRec.Environment.GetUTCTime(nvhRec.RecordingProperty.CreateTime))

dateTimeNano = DateTimeNano(nvhRec.RecordingProperty.CreateTime, UInt32(nvhMeasurement.NanoSecondElapsed))
print("DateTimeNano Created: ", dateTimeNano)

Extracting and Creating Time Data with Accuracy in Nanoseconds for Python

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
atfxFilePath = "C:\Users\KevinCheng\Downloads\gps test example\{4499520}_REC_{20220419}(1).atfx";
rec = EDM.Recording.ODSNVHATFXMLRecording(atfxFilePath);
% array to contain boolean return and the actual out IRecording parameter
[openRecordSucceed, recording] = EDM.Recording.RecordingManager.Manager.OpenRecording(atfxFilePath);

dateTimeNano = Common.DateTimeNano(rec.RecordingProperty.CreateTime, rec.Measurement.NanoSecondElapsed)
disp(System.String.Format("DateTimeNano Object:",dateTimeNano));

Extracting and Creating Time Data with Accuracy in Nanoseconds for Matlab