Representation of Time Series¶
The timeseries
module provides a representation of time
series with methods to compute derivatives and definite integrals,
resample time series, in particular to regular time intervals, smooth
them, and combine overlapping time series into one.
- class postcactus.timeseries.TimeSeries(t, y)¶
This class represents real or complex valued time series.
Constructor.
- Parameters
t (1D numpy array or list.) – Sampling times, need to be strictly increasing.
y (1D numpy array or list.) – Data samples, can be real or complex valued.
- clip(tmin=None, tmax=None)¶
Throws away data outside the time intarval [tmin, tmax]. if tmin or tmax are not specified or None, it does not remove anything from this side.
- Parameters
tmin (float or None) – Left boundary cut interval or None.
tmax (float or None) – Right boundary cut interval or None.
- cont_phase()¶
Compute the complex phase of a complex-valued signal such that no phase wrap-arounds occur, i.e. if the input is continous, so is the output.
- Returns
Continuous complex phase.
- Return type
- deriv(order)¶
Compute derivative of order<=5 using splines.
- Parameters
order (int) – Order of differentiation.
- Returns
Differential.
- Return type
- finite_values()¶
Filter out infinite values. :returns: Time series with finit values only. :rtype:
TimeSeries
- gaussian_filter(tsmooth, deriv=0)¶
Smooth timeseries with gaussian filter. If deriv>0, smoothed derivatige is computed by convolution with gaussian kernel derivative.
- integrate(a=None, b=None)¶
Compute the definite integral over the interval [a,b] using spline representations. If lower and/or upper bound is not specified, use boundary of the timeseries.
- Parameters
a (float or None) – Lower integration bound or None.
b (float or None) – Upper integration bound or None.
- is_complex()¶
- Returns
Wether the data is complex-valued.
- Return type
bool
- length()¶
- Returns
The length of the covered time interval.
- new_time_unit(utime)¶
Rescales the time.
- Parameters
utime (float) – Factor by which to divide times.
- phase_avg_freq(tavg)¶
Compute the average frequency corresponding to the average phase velocity.
- phase_avg_vel(tavg)¶
Compute the average phase velocity over periods tavg.
- phase_vel()¶
Compute the phase velocity, i.e. the time derivative of the complex phase.
- regular_sample()¶
Resamples the timeseries to regularly spaced times, with the same number of points. :returns: Regularly resampled time series. :rtype:
TimeSeries
- remove_mean()¶
Remove the mean value from the data.
- resampled(tn, ext=0)¶
Resamples the timeseries to new times tn.
- Parameters
tn (1D numpy array or list of float.) – New sample times.
ext (0 for extrapolation, 1 for returning zero, 2 for ValueError.) – How to handle points outside the time interval.
- Returns
Resampled time series.
- Return type
- save(fname)¶
Saves into simple ascii format with 2 collumns (t,y) for real valued data and 3 collumns (t, Re(y), Im(y)) for complex valued data.
- Parameters
fname (str) – File name.
- smoothed(tsm, fwin=<function ones>)¶
Smooth the data by convoluting with a window function.
- Parameters
fwin – The window function.
tsm (float) – Smoothing length.
- Returns
Smoothed timeseries.
- Return type
- tmax()¶
- Returns
The final time.
- tmin()¶
- Returns
The starting time.
- postcactus.timeseries.combine_ts(series, prefer_late=True)¶
Combine several overlapping time series into one. In intervals covered by two or more time series, which data is used depends on the parameter prefer_late.
- Parameters
series (list of
TimeSeries
) – The timeseries to combine.prefer_late – Prefer data that starts later for overlapping segments
- Returns
The combined time series.
- Return type
- postcactus.timeseries.sample_common(ts)¶
Resamples a list of timeseries to the largest time interval covered by all timeseries, using regularly spaced time. The number of sample points is the maximum over all time series.
- Parameters
ts (list of
TimeSeries
) – The timeseries to resample.- Returns
The resampled time series.
- Return type
list of
TimeSeries