Beispiel #1
0
def _resample_time(trj: TrajaDataFrame,
                   step_time: Union[float, int, str],
                   errors="coerce"):
    if not is_datetime_or_timedelta_dtype(trj.index):
        raise Exception(f"{trj.index.dtype} is not datetime or timedelta.")
    try:
        df = trj.resample(step_time).interpolate(method="spline", order=2)
    except ValueError as e:
        if len(e.args
               ) > 0 and "cannot reindex from a duplicate axis" in e.args[0]:
            if errors == "coerce":
                logger.warning("Duplicate time indices, keeping first")
                trj = trj.loc[~trj.index.duplicated(keep="first")]
                df = (trj.resample(step_time).bfill(limit=1).interpolate(
                    method="spline", order=2))
            else:
                logger.error("Error: duplicate time indices")
                raise ValueError("Duplicate values in indices")
    return df
Beispiel #2
0
def _resample_time(trj: TrajaDataFrame, step_time: Union[float, int]):
    if not is_datetime_or_timedelta_dtype(trj.index):
        raise Exception(f"{trj.index.dtype} is not datetime or timedelta.")
    return trj.resample(step_time).agg({"x": np.mean, "y": np.mean})