delaynet.utils package#
Submodules#
delaynet.utils.bind_args module#
Function to bind args for the decorators of the connectivity and detrend functions.
- delaynet.utils.bind_args.bind_args(func: callable, args: list, kwargs: dict) BoundArguments[source]#
Bind the arguments to the parameters of the function.
This will automatically raise a TypeError if a required argument is missing or an unknown argument is passed.
If kwargs have a key
check_kwargswith valueFalse, the kwargs are not checked for availability. This is useful if you want to pass unused keyword.- Parameters:
- Returns:
The bound arguments.
- Return type:
BoundArguments
- Raises:
delaynet.utils.dict_lookup module#
Dict lookup function, used for metrics and detrending methods.
- delaynet.utils.dict_lookup.dict_lookup(lookup: dict) dict[source]#
Dict lookup function.
- Parameters:
lookup (dict) – The lookup dict.
- Returns:
The inverted lookup dict.
- Return type:
- Raises:
TypeError – If the lookup is not a dict.
- Example:
>>> dict_lookup({"a": 1, "b": 2, "c": 1}) {1: ["a", "c"], 2: ["b"]} >>> dict_lookup({"a": 1, "b": 2, "c": 1, "d": 2}) {1: ["a", "c"], 2: ["b", "d"]} >>> dict_lookup({}) {} >>> dict_lookup(123) Traceback (most recent call last): ... TypeError: Expected dict, got <class 'int'>.
delaynet.utils.lag_steps module#
Utility functions to handle lag steps.
- class delaynet.utils.lag_steps.Connectivity(*args, **kwargs)[source]#
Bases:
Protocol[P]A protocol for connectivity metrics.
Connectivity metrics are rigidly typed in their first three parameters: the time series and one lag step. The rest are optional keyword arguments.
- delaynet.utils.lag_steps.assure_lag_list(lag_steps: int | list[int]) list[int][source]#
Ensure that
lag_stepsis a list of lags.If
lag_stepsis an integer, it will be converted to a list containing integers from 1 tolag_steps. Iflag_stepsis already a list, it will be checked to ensure that all elements are integers.
- delaynet.utils.lag_steps.find_optimal_lag(metric_func: Connectivity, ts1, ts2, lag_steps: list, op=<built-in function min>, **kwargs)[source]#
Find the optimal value and lag for a given metric function.
The optimal value and lag are determined by applying a given operation to a list of values obtained by applying
metric_funcfor each lag inlag_steps. The operation can be min, max, or any other operation that takes a list of values and returns a single value. Ifmetric_funcreturns a p-value, the operator should be the minimum (default optional parameter).- Parameters:
metric_func (Connectivity) – Function to compute the metric for a given lag step. Accepts time series
ts1andts2, a lag steplag, and any additional keyword arguments.ts1 (numpy.ndarray) – First time series.
ts2 (numpy.ndarray) – Second time series.
lag_steps (list) – Time lags to consider. Needs to be a list of integers.
op (Callable) – Operator to find the optimal lag step (e.g., default
min()ormax()).kwargs – Additional keyword arguments to pass to the metric function.
- Returns:
Optimal metric value and corresponding lag step.
- Return type:
delaynet.utils.logging module#
Logging configuration for delaynet.
Module contents#
Utility functions for delaynet.