6
6
import os .path
7
7
from io import StringIO
8
8
from typing import Any
9
+ from typing import Optional
9
10
10
- import numpy as np
11
11
import numpy .typing as npt
12
12
import pandas as pd # type: ignore
13
13
from pandas ._typing import FilePathOrBuffer # type: ignore
20
20
21
21
def read_trajectory_summary_as_dataframe (
22
22
filepath_or_buffer : FilePathOrBuffer ,
23
- camel_case_column_names : bool = False ,
24
- avro_compatible : bool = False ,
23
+ camel_case_column_names : Optional [bool ] = False ,
24
+ avro_compatible : Optional [bool ] = False ,
25
+ avro_long_beginning_utc_time : Optional [bool ] = True ,
25
26
) -> pd .DataFrame :
26
27
"""
27
28
Reads a trajectory summary file into a Pandas DataFrame.
@@ -30,6 +31,9 @@ def read_trajectory_summary_as_dataframe(
30
31
:param camel_case_column_names: If True, column names will be camel cased e.g. m_deg
31
32
:param avro_compatible: If True, the rows in the dataframe will match the avsc
32
33
schema with row.to_dict().
34
+ :param avro_long_beginning_utc_time: If True, the time column will be converted from
35
+ a datetime object to an int64 epoch time which is compatible with the long
36
+ timestamp-micros avro type.
33
37
34
38
:return: Pandas DataFrame of the trajectory summary file.
35
39
"""
@@ -78,12 +82,16 @@ def read_trajectory_summary_as_dataframe(
78
82
79
83
if avro_compatible :
80
84
camel_case_column_names = True
81
- trajectory_df ["Beginning (UTC Time)" ] = trajectory_df [
82
- "Beginning (UTC Time)"
83
- ].astype (np .int64 ) / int (1e6 )
84
- trajectory_df ["Beginning (UTC Time)" ] = trajectory_df [
85
- "Beginning (UTC Time)"
86
- ].astype (np .int64 )
85
+
86
+ if avro_long_beginning_utc_time :
87
+ # convert datetime nano to micro epoch and round to int
88
+ trajectory_df ["Beginning (UTC Time)" ] = (
89
+ trajectory_df ["Beginning (UTC Time)" ].astype ("int64" ) / 1e3
90
+ )
91
+ trajectory_df ["Beginning (UTC Time)" ] = (
92
+ trajectory_df ["Beginning (UTC Time)" ].round (0 ).astype ("int64" )
93
+ )
94
+
87
95
trajectory_df ["IAU (code)" ] = trajectory_df ["IAU (code)" ].astype ("unicode" )
88
96
trajectory_df ["Schema (version)" ] = trajectory_df ["Schema (version)" ].astype (
89
97
"unicode"
0 commit comments