Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Features include:
- Skewness, kurtosis
- Power spectra metrics
- Entropy measures
- Detrended Fluctuation Analysis (DFA)
- Kendall tau statistics to quantify trends
- Deep learning classifiers for bifurcation prediction ([Bury et al. 2021](https://www.pnas.org/doi/10.1073/pnas.2106140118))
- Visualization tools
Expand All @@ -37,7 +38,7 @@ Features include:

## Install

Requires Python 3.8–3.11. Install via:
Requires Python 3.9–3.12. Install via:

```bash
pip install --upgrade pip
Expand Down
44 changes: 44 additions & 0 deletions ewstools/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,50 @@ def entropy_func(series):
self.ews[col] = df_entropy[col]
# self.ews = pd.merge(self.ews, df_entropy, how="left", on="time")


def compute_dfa(self, rolling_window=0.25, order=1):
"""
Compute DFA scaling exponent over a rolling window.
If residuals have not been computed, computation will be
performed over state variable.
Output is stored in the self.ews dataframe.

Parameters
----------
rolling_window : float
Length of rolling window used to compute DFA exponent. Can be
specified as an absolute value or as a proportion of the length
of the data being analysed. Default is 0.25.
order : int
Polynomial detrending order within DFA (1 = linear). Default
is 1.

Returns
-------
None.

"""
if self.transition:
df_pre = self.state[self.state.index <= self.transition]
else:
df_pre = self.state
if 0 < rolling_window <= 1:
rw_absolute = int(rolling_window * len(df_pre))
else:
rw_absolute = rolling_window
if 'residuals' in df_pre.columns:
dfa_values = (
df_pre['residuals']
.rolling(window=rw_absolute)
.apply(func=lambda x: helpers.dfa(x, order=order), raw=True)
)
else:
dfa_values = (
df_pre['state']
.rolling(window=rw_absolute)
.apply(func=lambda x: helpers.dfa(x, order=order), raw=True)
)
self.ews['dfa'] = dfa_values
def compute_ktau(self, tmin="earliest", tmax="latest"):
"""
Compute kendall tau values of CSD-based EWS.
Expand Down
Loading
Loading