Skip to content
Closed
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyspi"
version = "2.0.0"
version = "2.0.1"
authors = [
{ name ="Oliver M. Cliff", email="oliver.m.cliff@gmail.com"},
]
Expand Down
19 changes: 9 additions & 10 deletions pyspi/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Calculator:
"""Compute all pairwise interactions.

The calculator takes in a multivariate time-series dataset, computes and stores all pairwise interactions for the dataset.
The calculator takes in a multivariate time-series dataset (MTS), computes and stores all pairwise interactions for the dataset.
It uses a YAML configuration file that can be modified in order to compute a reduced set of pairwise methods.

Example:
Expand All @@ -27,26 +27,25 @@ class Calculator:

Args:
dataset (:class:`~pyspi.data.Data`, array_like, optional):
The multivariate time series of M processes and T observations, defaults to None.
The multivariate time series of M processes and T observations, default=None.
name (str, optional):
The name of the calculator. Mainly used for printing the results but can be useful if you have multiple instances, defaults to None.
The name of the calculator. Mainly used for printing the results but can be useful if you have multiple instances, default=None.
labels (array_like, optional):
Any set of strings by which you want to label the calculator. This can be useful later for classification purposes, defaults to None.
Any set of strings by which you want to label the calculator. This can be useful later for classification purposes, default=None.
subset (str, optional):
A pre-configured subset of SPIs to use. Options are "all", "fast", "sonnet", or "fabfour", defaults to "all".
A pre-configured subset of SPIs to use. Options are "all", "fast", "sonnet", or "fabfour", default="all".
configfile (str, optional):
The location of the YAML configuration file for a user-defined subset. See :ref:`Using a reduced SPI set`, defaults to :code:`'</path/to/pyspi>/pyspi/config.yaml'`
detrend (bool, optional):
If True, detrend the dataset along the time axis before normalising (if enabled), defaults to True.
If True, detrend each time series in the MTS dataset individually along the time axis, default=False.
normalise (bool, optional):
If True, z-score normalise the dataset along the time axis before computing SPIs, defaults to True.
Detrending (if enabled) is always applied before normalisation.
If True, z-score normalise each time series in the MTS dataset individually along the time axis, default=True.
"""
_optional_dependencies = None

def __init__(
self, dataset=None, name=None, labels=None, subset="all", configfile=None,
detrend=True, normalise=True
detrend=False, normalise=True
):
self._spis = {}
self._excluded_spis = list()
Expand Down Expand Up @@ -511,7 +510,7 @@ def init_from_list(self, datasets, names, labels, **kwargs):
self.add_calculator(calc)

def init_from_yaml(
self, document, detrend=True, normalise=True, n_processes=None, n_observations=None, **kwargs
self, document, detrend=False, normalise=True, n_processes=None, n_observations=None, **kwargs
):
datasets = []
names = []
Expand Down
25 changes: 12 additions & 13 deletions pyspi/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,29 @@ class Data:

Args:
data (array_like, optional):
2-dimensional array with raw data, defaults to None.
2-dimensional array with raw data, default=None.
dim_order (str, optional):
Order of dimensions, accepts two combinations of the characters 'p', and 's' for processes and observations, defaults to 'ps'.
Order of dimensions, accepts two combinations of the characters 'p', and 's' for processes and observations, default='ps'.
detrend (bool, optional):
If True, detrend the dataset along the time axis before normalising (if enabled), defaults to True.
If True, detrend each time series in the MTS dataset individually along the time axis, default=False.
normalise (bool, optional):
If True, z-score normalise the dataset along the time axis before computing SPIs, defaults to True.
Detrending (if enabled) is always applied before normalisation.
If True, z-score normalise each time series in the MTS dataset individually along the time axis, default=True.
name (str, optional):
Name of the dataset
procnames (list, optional):
List of process names with length the number of processes, defaults to None.
List of process names with length the number of processes, default=None.
n_processes (int, optional):
Truncates data to this many processes, defaults to None.
Truncates data to this many processes, default=None.
n_observations (int, optional):
Truncates data to this many observations, defaults to None.
Truncates data to this many observations, default=None.

"""

def __init__(
self,
data=None,
dim_order="ps",
detrend=True,
detrend=False,
normalise=True,
name=None,
procnames=None,
Expand Down Expand Up @@ -183,19 +182,19 @@ def set_data(
data = data[:, :n_observations]

if self.detrend:
print(Fore.GREEN + "[1/2] De-trending the dataset...")
print(Fore.GREEN + "[1/2] Detrending time series in the dataset...")
try:
data = detrend(data, axis=1)
except ValueError as err:
print(f"Could not detrend data: {err}")
else:
print(Fore.RED + "[1/2] Skipping detrending of the dataset...")
print(Fore.RED + "[1/2] Skipping detrending of time series in the dataset...")

if self.normalise:
print(Fore.GREEN + "[2/2] Normalising (z-scoring) the dataset...\n")
print(Fore.GREEN + "[2/2] Normalising (z-scoring) each time series in the dataset...\n")
data = zscore(data, axis=1, nan_policy="omit", ddof=1)
else:
print(Fore.RED + "[2/2] Skipping normalisation of the dataset...\n")
print(Fore.RED + "[2/2] Skipping normalisation of time series in the dataset...\n")

nans = np.isnan(data)
if nans.any():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
'data/standard_normal.npy',
'data/cml7.npy']},
include_package_data=True,
version='2.0.0',
version='2.0.1',
description='Library for pairwise analysis of time series data.',
author='Oliver M. Cliff',
author_email='oliver.m.cliff@gmail.com',
Expand Down
Binary file modified tests/CML7_benchmark_tables.pkl
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/generate_benchmark_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_benchmark_tables(calc_list):

for i in range(10):
np.random.seed(42)
calc = Calculator(dataset=dataset, detrend=True, normalise=True)
calc = Calculator(dataset=dataset)
calc.compute()
store_calcs.append(calc)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_SPIs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def compute_new_tables():
benchmark_dataset = load_benchmark_dataset()
# Compute new tables on the benchmark dataset
np.random.seed(42)
calc = Calculator(dataset=benchmark_dataset, normalise=True, detrend=True)
calc = Calculator(dataset=benchmark_dataset)
calc.compute()
table_dict = dict()
for spi in calc.spis:
Expand Down