resurfemg.helper_functions.math_operations module¶
Copyright 2022 Netherlands eScience Center and University of Twente Licensed under the Apache License, version 2.0. See LICENSE for details.
This file contains functions for math operations to support the functions in ReSurfEMG
- class resurfemg.helper_functions.math_operations.Range(start, end)¶
Bases:
RangeBase
Utility class for working with ranges (intervals).¶
- param start:
Start of the range
- type start:
~int
- param end:
End of the range
- type end:
~int
- intersects(other)¶
Returns True if this range intersects other range.¶
- param other:
Another range to compare this one to
- type other:
~resurfemg.helper_functions.Range
- returns:
True if this range intersects another range
- rtype:
bool
- precedes(other)¶
Returns True if this range precedes other range.
- Parameters:
other (Range) – Another range to compare this one to
- Returns:
True if this range strictly precedes another range
- Return type:
- resurfemg.helper_functions.math_operations.bell_curve(x, a, b, c)¶
This function calculates a bell curve on the samples of x, shifted by b, amplified by a for a standard amplitude of 1. ————————————————————————— :param x: x values to calculate the bell_curve for :type x: ~numpy.ndarray :param a: amplitude of the bell-curve :type a: ~float :param b: time shift of the bell-curve along the x-axis. :type b: ~float :param c: steepness factor of bell-curve. :type c: ~float
- Returns:
bell curve
- Return type:
- resurfemg.helper_functions.math_operations.delay_embedding(data, emb_dim, lag=1)¶
The following code is adapted from openly licensed code written by Christopher Schölzel in his package nolds (NOnLinear measures for Dynamical Systems).It performs a time-delay embedding of a time series ————————————————————————— :param data: array-like :type data: array :param emb_dim: the embedded dimension :type emb_dim: int :param lag: the lag between elements in the embedded vectors :type lag: int
- Returns matrix_vectors:
the embedded vectors
- Rtype matrix_vectors:
~nd.array
- resurfemg.helper_functions.math_operations.derivative(signal, fs, window_s=None)¶
This function calculates the first derivative of a signal. If window_s is given, the signal is smoothed before derivative calculation. ————————————————————————— :param signal: signal to calculate the derivate over :type signal: ~numpy.ndarray :param fs: sampling rate :type fs: int :param window_s: centralised averaging window length in samples :type window_s: int
- Returns dsignal_dt:
The 1st derivative of the signal length len(signal)-1.
- Rtype dsignal_dt:
~numpy.ndarray
- resurfemg.helper_functions.math_operations.intersections(left, right)¶
This function works over two arrays, left and right, and allows a picking based on intersections. It only takes ranges on the left that intersect ranges on the right. ————————————————————————— :param left: List of ranges :type left: List[Range] :param right: List of ranges :type right: List[Range]
- Returns result:
Ranges from the left that intersect ranges from the right.
- Rtype result:
List[Range]
- resurfemg.helper_functions.math_operations.merge(left, right)¶
Merge two lists based linear order.¶
- param left:
First list
- type left:
List
- param right:
Second list
- type right:
List
- returns output:
Merged lists
- rtpe output:
List
- resurfemg.helper_functions.math_operations.ranges_of(array)¶
This function is made to work with
Range
class objects, such that is selects ranges and returns tuples of boundaries. ————————————————————————— :param array: array :type array: ~numpy.ndarray- Returns:
range_return
- Return type:
- resurfemg.helper_functions.math_operations.raw_overlap_percent(signal1, signal2)¶
This function takes two binary 0 or 1 signal arrays and gives the percentage of overlap. ————————————————————————— :param signal1: Binary signal 1 :type signal1: ~numpy.ndarray :param rsignal2: Binary signal 2 :type rsignal2: ~numpy.ndarray
- Returns _raw_overlap_percent:
Raw overlap percent
- Rtype _raw_overlap_percent:
float
- resurfemg.helper_functions.math_operations.running_smoother(array)¶
This is the smoother to use in time calculations¶
- param array:
array to be smoothed
- type array:
~numpy.ndarray
- returns smoothed_array:
smoothed array
- rtype smoothed_array:
~numpy.ndarray
- resurfemg.helper_functions.math_operations.save_preprocessed(array, out_fname, force)¶
This function is written to be called by the cli module. It stores arrays in a directory. ————————————————————————— :param array: array to be stored :type array: ~nd.array :param out_fname: output file name :type out_fname: str :param force: force writing the file :type force: bool
- Returns:
None
- Return type:
None
- resurfemg.helper_functions.math_operations.scale_arrays(array, maximum, minimum)¶
This function will scale all arrays along the vertical axis to have an absolute maximum value of the maximum parameter ————————————————————————— :param array: Original signal array with any number iflayers :type array: ~numpy.ndarray :param maximum: the absolute maximum below which the new array exists :type maximum: float :param minimum: the absolute maximum below which the new array exists :type minimum: float
- Returns reformed:
a new array with absolute max of maximum
- Rtype reformed:
~numpy.ndarray
- resurfemg.helper_functions.math_operations.slices_jump_slider(array_sample, slice_len, jump)¶
This function produces continuous sequential slices over an array of a certain length spaced out by a ‘jump’. The function yields, does not return these slices. ————————————————————————— :param array_sample: array containing the signal :type array_sample: ~numpy.ndarray :param slice_len: the length of window on the array :type slice_len: int :param jump: the amount by which the window is moved at iteration :type jump: int
- Returns:
Actually yields, no return
- Return type:
- resurfemg.helper_functions.math_operations.slices_slider(array_sample, slice_len)¶
This function produces continuous sequential slices over an array of a certain length. The inputs are the following - array_sample, the signal and slice_len - the window which you wish to slide with. The function yields, does not return these slices. ————————————————————————— :param array_sample: array containing the signal :type array_sample: ~numpy.ndarray :param slice_len: the length of window on the array :type slice_len: int
- Returns:
Actually yields, no return
- Return type:
- resurfemg.helper_functions.math_operations.zero_one_for_jumps_base(array, cut_off)¶
This function takes an array and makes it binary (0, 1) based on a cut-off value. ————————————————————————— :param array: An array :type array: ~numpy.ndarray :param cut_off: The number defining a cut-off line for binarization :type cut_off: float
- Returns array_list:
Binarized list that can be turned into array
- Rtype array_list:
list