Getting Started

Getting Started#

Warning

Use Development Setup until public release.

This package can be installed from PyPI using pip:

pip install delaynet

This will automatically install all the necessary dependencies as specified in the pyproject.toml file. It is recommended to use a virtual environment, e.g., using conda, mamba or micromamba (they can be used interchangeably). delaynet can be installed from the conda-forge channel.

conda create -n delay_net -c conda-forge python
conda activate delay_net
conda install -c conda-forge delaynet

Usage#

The package can be used as a library. The most common functions are exposed in the top-level namespace, e.g. detrend() and connectivity(). For example:

import delaynet as dn

ts_detrend = dn.detrend(ts, method='Z-Score')
conn = dn.connectivity(ts1, ts2, metric='Granger Causality')

To quickly find the string specifiers for these functions, use the show_detrending_methods() and show_connectivity_metrics() functions. These are case-insensitive. Each documentation of these methods can be found in a respective submodule, delaynet.detrending_methods or delaynet.connectivities.

dn.show_detrending_methods()
dn.show_connectivity_metrics()
Available detrending methods:

Detrending method: delta
Aliases:
 - delta
 - dt

Detrending method: identity
Aliases:
 - identity
 - id

Detrending method: second_difference
Aliases:
 - second difference
 - 2dt
 - second_difference

Detrending method: z_score
Aliases:
 - z-score
 - zs
 - zscore
 - z_score


Available connectivity metrics:

Metric: random_patterns
Aliases:
 - continuous ordinal patterns
 - cop
 - random_patterns

Metric: gt_multi_lag
Aliases:
 - granger causality
 - gc
 - gt_multi_lag

Metric: gravity
Aliases:
 - gravity
 - gv

Metric: linear_correlation
Aliases:
 - linear correlation
 - lc
 - linear_correlation

Metric: mutual_information
Aliases:
 - mutual information
 - mi
 - mutual_information

Metric: rank_correlation
Aliases:
 - rank correlation
 - rc
 - rank_correlation

Metric: transfer_entropy
Aliases:
 - transfer entropy
 - te
 - transfer_entropy

For more insight into the package, read the Guide or the API Reference.

Development Setup#

For development, we recommend using micromamba to create a virtual environment (conda or mamba also work) and installing the package in editable mode. After cloning the repository, navigate to the root folder and create the environment with the desired python version and the dependencies.

micromamba create -n delay_net -c conda-forge python
micromamba activate delay_net

To let micromamba handle the dependencies, use the requirements files

micromamba install -f requirements.txt
pip install --no-build-isolation --no-deps -e .

Alternatively, if you prefer to use pip instead of micromamba, installing the package in editable mode will also install the development dependencies.

pip install -e ".[all]"

Now, the package can be imported and used in the python environment, from anywhere on the system, if the environment is activated. For new changes, the repository only needs to be updated, but the package does not need to be reinstalled.

Testing#

The package can be tested using pytest and coverage. To run the tests, execute the following command:

pytest --cov delaynet/ tests/

Pre-Commit#

The project uses pre-commit for code formatting and linting. They are installed with the development dependencies. To install and run the pre-commit hooks, use:

pre-commit run --all-files