Skip to content

Commit

Permalink
add time_to_ts method
Browse files Browse the repository at this point in the history
  • Loading branch information
qian-chu committed Oct 7, 2024
1 parent e34af35 commit fbeab47
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pyneon/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def is_uniformly_sampled(self) -> bool:

def time_to_ts(self, time: Union[Number, np.ndarray]) -> np.ndarray:
"""Convert time(s) in seconds to timestamp(s) in nanoseconds."""
time
time = np.array([time])
return np.array([self.ts[np.absolute(self.times - t).argmin()] for t in time])

def crop(
self,
Expand Down
3 changes: 1 addition & 2 deletions pyneon/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .sample_data import get_sample_data
from .utils import time_to_ts

__all__ = ["get_sample_data", "time_to_ts"]
__all__ = ["get_sample_data"]
7 changes: 0 additions & 7 deletions pyneon/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import pandas as pd
from typing import Union
from numbers import Number


def time_to_ts(time: Number, data: pd.DataFrame):
if "time [s]" not in data.columns or "timestamp [ns]" not in data.columns:
raise ValueError('Dataframe must have columns "time [s]" and "timestamp [ns]"')
ts = data.loc[(data["time [s]"] - time).abs().idxmin(), "timestamp [ns]"]
return ts

0 comments on commit fbeab47

Please sign in to comment.