File size: 1,493 Bytes
f7fb447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np

from aira.engine.filtering import moving_average_filter


def w_channel_preprocess(
    w_channel: np.ndarray, window_size: int, analysis_length: float, sample_rate: float
) -> np.ndarray:
    """_summary_

    Parameters
    ----------
    w_channel : np.ndarray
        _description_
    window_size : int
        _description_
    analysis_length : float
        _description_
    sample_rate : float
        _description_

    Returns
    -------
    np.ndarray
        _description_
    """
    w_channel_cropped = np.abs(
        analysis_crop_1d(w_channel, analysis_length, sample_rate)
    )
    w_channel_filtered = moving_average_filter(w_channel_cropped, int(window_size / 2))
    w_channel_filtered /= np.max(w_channel_filtered)
    return w_channel_filtered


def analysis_crop_1d(
    array: np.ndarray,
    analysis_length: float,
    sample_rate: int,
):
    """_summary_

    Parameters
    ----------
    analysis_length : float
        _description_
    sample_rate : int
        _description_
    array : np.ndarray
        _description_

    Returns
    -------
    _type_
        _description_
    """
    # Get analysis length max index
    analysis_length_idx = int(analysis_length * sample_rate)

    # Slice from intensity max to analysis length from intensity max
    earliest_peak_index = np.argmax(np.abs(array))
    array_cropped = array[
        earliest_peak_index : earliest_peak_index + analysis_length_idx
    ]

    return array_cropped