Compute utils
detect_header_keywords(fname, keywords)
¶
Detect if the first line of a file contains any of the provided keywords. This is used to check for whether headers are present in a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fname
|
The fpath to the file |
required | |
keywords
|
A string or list of strings representing keywords to search for. |
required |
Returns:
Type | Description |
---|---|
True if any of the keywords are found, False otherwise. |
Source code in magenpy/utils/compute_utils.py
generate_overlapping_windows(seq, window_size, step_size, min_window_size=1)
¶
Generate overlapping windows of a fixed size over a sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq
|
A numpy array of sorted values |
required | |
window_size
|
The size of each window. |
required | |
step_size
|
The step size between each window. If step_size < window_size, windows will overlap. |
required | |
min_window_size
|
The minimum size of a window. Windows smaller than this size will be discarded. |
1
|
Returns:
Type | Description |
---|---|
A numpy array of start and end indices of each window. |
Source code in magenpy/utils/compute_utils.py
generate_slice_dictionary(vec)
¶
This utility function takes a sorted vector (e.g. numpy array), identifies the unique elements and generates a dictionary of slices delineating the start and end positions of each element in the vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vec
|
A numpy array |
required |
Returns:
Type | Description |
---|---|
A dictionary of slices |
Source code in magenpy/utils/compute_utils.py
intersect_arrays(arr1, arr2, return_index=False)
¶
This utility function takes two arrays and returns the shared elements (intersection) between them. If return_index is set to True, it returns the index of shared elements in the first array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr1
|
The first array |
required | |
arr2
|
The second array |
required | |
return_index
|
Return the index of shared elements in the first array |
False
|
Returns:
Type | Description |
---|---|
A numpy array of shared elements or their indices |
Source code in magenpy/utils/compute_utils.py
is_numeric(obj)
¶
Check if a python object is numeric. This function handles numpy arrays and scalars.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
A python object |
required |
Returns:
Type | Description |
---|---|
True if the object is numeric, False otherwise. |
Source code in magenpy/utils/compute_utils.py
iterable(arg)
¶
Check if an object is iterable, but not a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arg
|
A python object. |
required |
Returns:
Type | Description |
---|---|
True if the object is iterable, False otherwise. |