1+ from datetime import datetime
12from enum import IntEnum
23from os import PathLike
34from typing import Any , BinaryIO , Optional , Union
45from pandas ._typing import Axes
56import numpy as np
67import pandas as pd
78
9+ """The reference epoch for UTC harp time."""
10+ REFERENCE_EPOCH = datetime (1904 , 1 , 1 )
11+
812
913class MessageType (IntEnum ):
1014 NA = 0
@@ -34,6 +38,7 @@ def read(
3438 dtype : Optional [np .dtype ] = None ,
3539 length : Optional [int ] = None ,
3640 columns : Optional [Axes ] = None ,
41+ epoch : Optional [datetime ] = None ,
3742 keep_type : bool = False ,
3843):
3944 """
@@ -48,6 +53,8 @@ def read(
4853 :param length: Expected number of elements in register payload. If specified,
4954 the payload length of the first message in the file is used for validation.
5055 :param columns: The optional column labels to use for the data values.
56+ :param epoch: Reference datetime at which time zero begins. If specified,
57+ the result data frame will have a datetime index.
5158 :param keep_type: Specifies whether to include a column with the message type.
5259 :return: A pandas data frame containing message data, sorted by time.
5360 """
@@ -74,9 +81,11 @@ def read(
7481 nrows , dtype = np .uint16 , buffer = data , offset = payloadoffset , strides = stride
7582 )
7683 payloadoffset += 2
77- seconds = micros * _SECONDS_PER_TICK + seconds
84+ time = micros * _SECONDS_PER_TICK + seconds
7885 payloadtype = payloadtype & ~ 0x10
79- index = pd .Series (seconds )
86+ if epoch is not None :
87+ time = epoch + pd .to_timedelta (time , "s" )
88+ index = pd .Series (time )
8089 index .name = "time"
8190
8291 payloadsize = stride - payloadoffset - 1
0 commit comments