Skip to content

Commit 155188e

Browse files
authored
Merge pull request #12 from harp-tech/gl-dev
Allow creating datetime index from reference epoch
2 parents 4a2f9e4 + 98159e2 commit 155188e

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

harp/io.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
from datetime import datetime
12
from enum import IntEnum
23
from os import PathLike
34
from typing import Any, BinaryIO, Optional, Union
45
from pandas._typing import Axes
56
import numpy as np
67
import pandas as pd
78

9+
"""The reference epoch for UTC harp time."""
10+
REFERENCE_EPOCH = datetime(1904, 1, 1)
11+
812

913
class 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

Comments
 (0)