Exemplo n.º 1
0
def lcs_coords_from_ts(
    ts: TimeSeries, time: Union[pd.DatetimeIndex, pint.Quantity]
) -> xr.DataArray:
    """Create translation coordinates from a TimeSeries at specific timesteps.

    Parameters
    ----------
    ts:
        TimeSeries that describes the coordinate motion as a 3D vector.
    time
        Timestamps used for interpolation.
        TODO: add support for pd.DateTimeindex as well

    Returns
    -------
    xarray.DataArray :
        A DataArray with correctly labeled dimensions to be used for LCS creation.

    """
    ts_data = ts.interp_time(time=time)
    # assign vector coordinates and convert to mm
    ts_data = ts_data.rename({"dim_1": "c"}).assign_coords({"c": ["x", "y", "z"]})
    ts_data.data = ts_data.data.to("mm").magnitude
    ts_data["time"] = pd.TimedeltaIndex(ts_data["time"].data)
    return ts_data
Exemplo n.º 2
0
    def test_interp_time_warning():
        """Test if a warning is emitted when interpolating already interpolated data."""
        ts = TimeSeries(data=Q_([1, 2, 3], "m"), time=Q_([0, 1, 2], "s"))
        with pytest.warns(None) as recorded_warnings:
            ts_interp = ts.interp_time(Q_([0.25, 0.5, 0.75, 1], "s"))
        assert not any(w.category == UserWarning for w in recorded_warnings)

        with pytest.warns(UserWarning):
            ts_interp.interp_time(Q_([0.4, 0.6], "s"))