Esempio n. 1
0
def normalized_power(arg, mask=None, value=0.0, **kwargs):
    """Normalized power

    Parameters
    ----------
    arg : array-like
        Power stream
    mask: array-like of bool, optional
        default=None, which means no masking
    value : number, optional
        Value to use for replacement, default=0.0
    type : {"xPower", "NP}
        Determines calculation method to use, default='xPower'

    Returns
    -------
    number
    """

    if kwargs.get('type', 'NP') == 'xPower':
        _rolling_mean = rolling_mean(arg, window=25, mask=mask, value=value, type='emwa')
    else:
        _rolling_mean = rolling_mean(arg, window=30, mask=mask, value=value)

    if type(_rolling_mean) == list:
        _rolling_mean = np.asarray(_rolling_mean, dtype=np.float)

    rv = np.mean(np.power(_rolling_mean, 4)) ** (1/4)

    return rv
Esempio n. 2
0
def normalized_power(arg, mask=None, value=0.0, **kwargs):
    """Normalized power

    Parameters
    ----------
    arg : array-like
        Power stream
    mask: array-like of bool, optional
        default=None, which means no masking
    value : number, optional
        Value to use for replacement, default=0.0
    type : {"xPower", "NP}
        Determines calculation method to use, default='xPower'

    Returns
    -------
    number
    """

    if kwargs.get('type', 'NP') == 'xPower':
        _rolling_mean = rolling_mean(arg,
                                     window=25,
                                     mask=mask,
                                     value=value,
                                     type='emwa')
    else:
        _rolling_mean = rolling_mean(arg, window=30, mask=mask, value=value)

    if type(_rolling_mean) == list:
        _rolling_mean = np.asarray(_rolling_mean, dtype=np.float)

    rv = np.mean(np.power(_rolling_mean, 4))**(1 / 4)

    return rv
Esempio n. 3
0
def best_interval(arg, window, mask=None, value=0.0, **kwargs):
    """Compute best interval of the stream

    Masking with replacement is controlled by keyword arguments

    Parameters
    ----------
    arg: array-like
    window : int
        Duration of the interval in seconds
    mask : array-like of bool, optional
        default=None, which means no masking
    value : number, optional
        Value to use for replacement, default=0.0

    Returns
    -------
    float
    """

    y = rolling_mean(arg, window=window, mask=mask, value=value, **kwargs)

    rv = np.max(y)

    return rv
Esempio n. 4
0
def best_interval(arg, window, mask=None, value=0.0, **kwargs):
    """Compute best interval of the stream

    Masking with replacement is controlled by keyword arguments

    Parameters
    ----------
    arg: array-like
    window : int
        Duration of the interval in seconds
    mask : array-like of bool, optional
        default=None, which means no masking
    value : number, optional
        Value to use for replacement, default=0.0

    Returns
    -------
    float
    """

    y = rolling_mean(arg, window=window, mask=mask, value=value, **kwargs)

    rv = np.max(y)

    return rv
Esempio n. 5
0
def test_rolling_mean_list():

    stream = [1, 2, 3, 4, 5]
    expected = [1, 1.5, 2.5, 3.5, 4.5]
    rv = streams.rolling_mean(stream, 2)

    assert type(rv) == list
    assert rv == expected
Esempio n. 6
0
def test_rolling_mean_real_data(test_stream):

    rv = streams.rolling_mean(test_stream['watts'],
                                 mask=test_stream['moving'],
                                 window=1)

    assert type(rv) == list
    assert rv == test_stream['watts']
Esempio n. 7
0
def test_rolling_mean_list_emwa():

    stream = list(np.ones(30))
    expected = list(np.ones(30))
    rv = streams.rolling_mean(stream, 2, type='ewma')

    assert type(rv) == list
    assert rv == expected
Esempio n. 8
0
def test_rolling_mean_list():

    stream = [1, 2, 3, 4, 5]
    expected = [1, 1.5, 2.5, 3.5, 4.5]
    rv = streams.rolling_mean(stream, 2)

    assert type(rv) == list
    assert rv == expected
Esempio n. 9
0
def test_rolling_mean_real_data(test_stream):

    rv = streams.rolling_mean(test_stream['watts'],
                              mask=test_stream['moving'],
                              window=1)

    assert type(rv) == list
    assert rv == test_stream['watts']
Esempio n. 10
0
def test_rolling_mean_list_emwa():

    stream = list(np.ones(30))
    expected = list(np.ones(30))
    rv = streams.rolling_mean(stream, 2, type='ewma')

    assert type(rv) == list
    assert rv == expected
Esempio n. 11
0
def test_rolling_mean_list_with_mask():

    stream = [1, 2, 3, 4, 5]
    mask = [True, True, False, True, True]
    expected = [1, 1.5, 1.0, 2.0, 4.5]
    rv = streams.rolling_mean(stream, window=2, mask=mask)

    assert type(rv) == list
    assert  rv == expected
Esempio n. 12
0
def test_rolling_mean_ndarray():

    stream = np.asarray([1, 2, 3, 4, 5])
    expected = np.asarray([1, 1.5, 2.5, 3.5, 4.5])

    rv = streams.rolling_mean(stream, 2)

    assert type(rv) == np.ndarray
    assert (rv == expected).all()
Esempio n. 13
0
def test_rolling_mean_with_mask_ndarray():

    stream = np.asarray([1, 2, 3, 4, 5])
    mask = np.asarray([True, True, False, True, True], dtype=bool)
    expected = np.asarray([1, 1.5, 1.0, 2.0, 4.5])
    rv = streams.rolling_mean(stream, window=2, mask=mask)

    assert type(rv) == np.ndarray
    assert  (rv == expected).all()
Esempio n. 14
0
def test_rolling_mean_list_with_mask():

    stream = [1, 2, 3, 4, 5]
    mask = [True, True, False, True, True]
    expected = [1, 1.5, 1.0, 2.0, 4.5]
    rv = streams.rolling_mean(stream, window=2, mask=mask)

    assert type(rv) == list
    assert rv == expected
Esempio n. 15
0
def test_rolling_mean_ndarray():

    stream = np.asarray([1, 2, 3, 4, 5])
    expected = np.asarray([1, 1.5, 2.5, 3.5, 4.5])

    rv = streams.rolling_mean(stream, 2)

    assert type(rv) == np.ndarray
    assert (rv == expected).all()
Esempio n. 16
0
def test_rolling_mean_with_mask_ndarray():

    stream = np.asarray([1, 2, 3, 4, 5])
    mask = np.asarray([True, True, False, True, True], dtype=bool)
    expected = np.asarray([1, 1.5, 1.0, 2.0, 4.5])
    rv = streams.rolling_mean(stream, window=2, mask=mask)

    assert type(rv) == np.ndarray
    assert (rv == expected).all()