resurfemg.helper_functions.helper_functions 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 general functions to support the functions in this repository
- class resurfemg.helper_functions.helper_functions.Range(start, end)¶
Bases:
RangeBase
Utility class for working with ranges (intervals). :ivar start: Start of the range :type start: ~number.Number :ivar end: End of the range :type end: ~number.Number
- intersects(other)¶
Returns
True
if this range intersectsother
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 precedesother
range. :param other: Another range to compare this one to :type other: ~resurfemg.helper_functions.Range :returns:True
if this range strictly precedes another range :rtype: bool
- resurfemg.helper_functions.helper_functions.count_decision_array(decision_array)¶
This is a function that, practically speaking, counts events on a time series array that has been reduced down to a binary (0, 1) output. It counts changes then divides by two. :param decision_array: Array. :type decisions_array: ~numpy.ndarray :returns: Number of events :rtype: float
- resurfemg.helper_functions.helper_functions.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 :rtype: ~nd.array
- resurfemg.helper_functions.helper_functions.distance_matrix(array_a, array_b)¶
- resurfemg.helper_functions.helper_functions.intersections(left, right)¶
This function works over two arrays,
left
andright
, 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: Ranges from theleft
that intersect ranges from theright
. :rtype: List[Range]
- resurfemg.helper_functions.helper_functions.merge(left, right)¶
Mergey function
- resurfemg.helper_functions.helper_functions.preprocess(file_directory, our_chosen_leads, algorithm, processed, force=False)¶
This function is written to be called by the cli module. The cli module supports command line pre-processing. This function is currently written to accomodate Poly5 files types. It can be refactored later.
- resurfemg.helper_functions.helper_functions.ranges_of(array)¶
This function is made to work with
Range
class objects, such that is selects ranges and returns tuples of boundaries. :param my_own_array: array :type my_own_array: ~numpy.ndarray :return: range_return :rtype: tuple
- resurfemg.helper_functions.helper_functions.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 :rtype: float
- resurfemg.helper_functions.helper_functions.relative_levenshtein(signal1, signal2)¶
Here we take two arrays, and create an edit distance based on Levelshtien edit distance The distance is then normalized between 0 and one regardless of signal length
- resurfemg.helper_functions.helper_functions.save_preprocessed(array, out_fname, force)¶
This function is written to be called by the cli module. It stores arrays in a directory.
- resurfemg.helper_functions.helper_functions.scale_arrays(array, maximumn, minimumn)¶
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 maximumn: the absolute maximum below which the new array exists :type maximumn: float :param minimumn: the absolute maximum below which the new array exists :type minimumn: float :returns: reformed, a new array with absolute max of maximum :rtype: ~numpy.ndarray
- resurfemg.helper_functions.helper_functions.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 :rtype: ~numpy.ndarray
- resurfemg.helper_functions.helper_functions.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 andslice_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 :rtype: ~numpy.ndarray
- resurfemg.helper_functions.helper_functions.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: Binarized list that can be turned into array :rtype: list