Cross-correlation

The cross_correlation plugin contains functions and visualizations to analyze the cross-correlation between two time series.

Currently the following functions are available:

  • ccf: Compute the cross-correlation function for two time series.

  • prewhiten: Prewhiten time series using an autoregressive model.

  • fit_response: Fit Pastas response function to the scaled cross-correlation function.

The following plots are available:

  • plot_corr: Plot the cross-correlation result (ccf(x, y)) between two time series.

  • plot_ccf_overview: Plot an overview of the cross-correlation between two time series.

Example

See the Examples section for more information on how to use the reservoirs plugin.

API

plot_ccf_overview(x, y, nlags=None, tmin=None, tmax=None, axes=None)[source]

Plot an overview of the cross-correlation between two time series.

Parameters:
  • x (pd.Series) – Time series 1

  • y (pd.Series) – Time series 2

  • nlags (int, optional) – number of lags to return cross-correlations for, by default None which uses number of lags equal to len(x).

  • tmin (str or pd.Timestamp, optional) – tmin for both time series, by default None

  • tmax (str or pd.Timestamp, optional) – tmax for both time series, by default None

  • axes (Axes mosaic, optional) – if provided, use axes from previous plot

Returns:

axes – return axes of subplots mosaic

Return type:

Axes mosaic

plot_corr(corr, ax=None, vlines_kwargs=None, **kwargs)[source]

Helper function for the statsmodels _plot_corr function.

Parameters:
  • corr (pd.Series or pd.DataFrame) – the correlation result to plot

  • ax (plt.Axes, optional) – axes to plot on, by default None

  • vlines_kwargs (dict, optional) – keyword arguments for the vlines function, by default None

Returns:

axes with the plot

Return type:

plt.Axes