def interpolate(self, new_time, derivative_order=0, out=None): new_time = np.asarray(new_time) if new_time.ndim != 1: raise ValueError(f"New time array must have exactly 1 dimension; it has {new_time.ndim}.") new_shape = self.shape[:-2] + (new_time.size, self.shape[-1]) if out is not None: out = np.asarray(out) if out.shape != new_shape: raise ValueError( f"Output array should have shape {new_shape} for consistency with new time array and modes array" ) if out.dtype != np.complex: raise ValueError(f"Output array should have dtype `complex`; it has dtype {out.dtype}") result = out or np.empty(new_shape, dtype=complex) if derivative_order > 3: raise ValueError( f"{type(self)} interpolation uses CubicSpline, and cannot take a derivative of order {derivative_order}" ) spline = CubicSpline(self.u, self.view(np.ndarray), axis=-2) if derivative_order < 0: spline = spline.antiderivative(-derivative_order) elif 0 < derivative_order <= 3: spline = spline.derivative(derivative_order) result[:] = spline(new_time) metadata = self._metadata.copy() metadata["time"] = new_time return type(self)(result, **metadata)
def calculate_position_with_time(x, speed): poly = CubicSpline(x, speed, bc_type="natural") antiderivative = poly.antiderivative() return antiderivative(x)