myo_helper/myo_helper.py
def window_emg(window_len, window_inc, emg, move, rep, which_moves=None, which_reps=None,
               emg_dtype=np.float32, y_dtype=np.int8, r_dtype=np.int8):
    """Window the EMG data explicitly.

    If using which_moves then y_data will be indices into which_moves rather than the original movement label; this is
    to fix issues in some machine learning libraries such as Tensorflow which have issues using sparse categorical
    cross-entropy and non-sequential labels."""
    nb_obs = emg.shape[0]
    nb_channels = emg.shape[1]

    # Locate valid window end indices (window must be window_len long and window_inc away from last)
    targets = np.array(range(window_len - 1, nb_obs, window_inc))

    # Reduce targets by allowed movements
    if which_moves is not None:
        targets = targets[np.in1d(move[targets], which_moves)]

    # Reduce targets by allowed repetitions
    if which_reps is not None:
        targets = targets[np.in1d(rep[targets], which_reps)]

    x_data = np.zeros([targets.shape[0], window_len, nb_channels, 1], dtype=emg_dtype)
    y_data = np.zeros([targets.shape[0], ], dtype=y_dtype)
    r_data = np.zeros([targets.shape[0], ], dtype=r_dtype)

    for i, win_end in enumerate(targets):
        win_start = win_end - (window_len - 1)
        x_data[i, :, :, 0] = emg[win_start:win_end + 1, :]  # Include end
        y_data[i] = move[win_end]
        r_data[i] = rep[win_end]

    if which_moves is not None:
        y_data_tmp = np.copy(y_data)
        for i, label in enumerate(which_moves):
            y_data[np.where(y_data_tmp == label)] = i

    return x_data, y_data, r_data
Window the EMG data explicitly.

    If using which_moves then y_data will be indices into which_moves rather than the original movement label; this is
    to fix issues in some machine learning libraries such as Tensorflow which have issues using sparse categorical
    cross-entropy and non-sequential labels.
Window the EMG data explicitly.
If using which_moves then y_data will be indices into which_moves rather than the original movement label; this is
to fix issues in some machine learning libraries such as Tensorflow which have issues using sparse categorical
cross-entropy and non-sequential labels.
Window the EMG data explicitly . If using which_moves then y_data will be indices into which_moves rather than the original movement label ; this is to fix issues in some machine learning libraries such as Tensorflow which have issues using sparse categorical cross - entropy and non - sequential labels .
def window_emg(window_len, window_inc, emg, move, rep, which_moves=None, which_reps=None,
               emg_dtype=np.float32, y_dtype=np.int8, r_dtype=np.int8):
    nb_obs = emg.shape[0]
    nb_channels = emg.shape[1]
    targets = np.array(range(window_len - 1, nb_obs, window_inc))
    if which_moves is not None:
        targets = targets[np.in1d(move[targets], which_moves)]
    if which_reps is not None:
        targets = targets[np.in1d(rep[targets], which_reps)]
    x_data = np.zeros([targets.shape[0], window_len, nb_channels, 1], dtype=emg_dtype)
    y_data = np.zeros([targets.shape[0], ], dtype=y_dtype)
    r_data = np.zeros([targets.shape[0], ], dtype=r_dtype)
    for i, win_end in enumerate(targets):
        win_start = win_end - (window_len - 1)
        x_data[i, :, :, 0] = emg[win_start:win_end + 1, :]  
        y_data[i] = move[win_end]
        r_data[i] = rep[win_end]
    if which_moves is not None:
        y_data_tmp = np.copy(y_data)
        for i, label in enumerate(which_moves):
            y_data[np.where(y_data_tmp == label)] = i
    return x_data, y_data, r_data
def window_emg ( window_len , window_inc , emg , move , rep , which_moves = None , which_reps = None , emg_dtype = np . float32 , y_dtype = np . int8 , r_dtype = np . int8 ) : nb_obs = emg . shape [ 0 ] nb_channels = emg . shape [ 1 ] targets = np . array ( range ( window_len - 1 , nb_obs , window_inc ) ) if which_moves is not None : targets = targets [ np . in1d ( move [ targets ] , which_moves ) ] if which_reps is not None : targets = targets [ np . in1d ( rep [ targets ] , which_reps ) ] x_data = np . zeros ( [ targets . shape [ 0 ] , window_len , nb_channels , 1 ] , dtype = emg_dtype ) y_data = np . zeros ( [ targets . shape [ 0 ] , ] , dtype = y_dtype ) r_data = np . zeros ( [ targets . shape [ 0 ] , ] , dtype = r_dtype ) for i , win_end in enumerate ( targets ) : win_start = win_end - ( window_len - 1 ) x_data [ i , : , : , 0 ] = emg [ win_start : win_end + 1 , : ] y_data [ i ] = move [ win_end ] r_data [ i ] = rep [ win_end ] if which_moves is not None : y_data_tmp = np . copy ( y_data ) for i , label in enumerate ( which_moves ) : y_data [ np . where ( y_data_tmp == label ) ] = i return x_data , y_data , r_data
Window the EMG data explicitly.
Window the EMG data explicitly .
"""Window the EMG data explicitly.

    If using which_moves then y_data will be indices into which_moves rather than the original movement label; this is
    to fix issues in some machine learning libraries such as Tensorflow which have issues using sparse categorical
    cross-entropy and non-sequential labels.""" # Locate valid window end indices (window must be window_len long and window_inc away from last)
 # Reduce targets by allowed movements
 # Reduce targets by allowed repetitions
 # Include end

window_len
window_inc
emg
move
rep
which_moves
which_reps
emg_dtype
y_dtype
r_dtype