Skip to content

drift_generator

generate_drift(data, drift_values=[1.1, 10.0, 0.1, 1.1])

Generates a drift array based on the number of rows in the input data and the specified drift values.

Parameters:

Name Type Description Default
data DataFrame or ndarray

The input data.

required
drift_values list of float

The drift values to use.

[1.1, 10.0, 0.1, 1.1]

Returns:

Type Description
ndarray

The generated drift array.

Examples:

>>> import numpy as np
>>> from spotRiver.drift.drift_generator import generate_drift
>>> data = np.array([[1, 2, 3], [4, 5, 6]])
>>> generate_drift(data, drift_values=[1.1, 10.0, 0.1, 1.1])
array([ 1.1, 10. ,  0.1,  1.1])
Source code in spotRiver/drift/drift_generator.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def generate_drift(data: pd.DataFrame, drift_values=[1.1, 10.0, 0.1, 1.1]) -> np.ndarray:
    """
    Generates a drift array based on the number of rows in the input data and the specified drift values.

    Args:
        data (pd.DataFrame or np.ndarray): The input data.
        drift_values (list of float): The drift values to use.

    Returns:
        (np.ndarray): The generated drift array.

    Examples:
        >>> import numpy as np
        >>> from spotRiver.drift.drift_generator import generate_drift
        >>> data = np.array([[1, 2, 3], [4, 5, 6]])
        >>> generate_drift(data, drift_values=[1.1, 10.0, 0.1, 1.1])
        array([ 1.1, 10. ,  0.1,  1.1])

    """
    num_rows = data.shape[0]
    num_drift_values = len(drift_values)
    quotient, remain = divmod(num_rows, num_drift_values)

    quotient_array = [value for value in drift_values for _ in range(quotient)]
    remain_array = np.full(remain, drift_values[-1], dtype=float)

    drift = np.concatenate([quotient_array, remain_array])
    return drift