madmom.utils¶
Utility package.
-
madmom.utils.
suppress_warnings
(function)[source]¶ Decorate the given function to suppress any warnings.
Parameters: function : function
Function to be decorated.
Returns: decorated function
Decorated function.
-
madmom.utils.
filter_files
(files, suffix)[source]¶ Filter the list to contain only files matching the given suffix.
Parameters: files : list
List of files to be filtered.
suffix : str
Return only files matching this suffix.
Returns: list
List of files.
-
madmom.utils.
search_path
(path, recursion_depth=0)[source]¶ Returns a list of files in a directory (recursively).
Parameters: path : str or list
Directory to be searched.
recursion_depth : int, optional
Recursively search sub-directories up to this depth.
Returns: list
List of files.
-
madmom.utils.
search_files
(files, suffix=None, recursion_depth=0)[source]¶ Returns the files matching the given suffix.
Parameters: files : str or list
File, path or a list thereof to be searched / filtered.
suffix : str, optional
Return only files matching this suffix.
recursion_depth : int, optional
Recursively search sub-directories up to this depth.
Returns: list
List of files.
Notes
The list of returned files is sorted.
-
madmom.utils.
strip_suffix
(filename, suffix=None)[source]¶ Strip off the suffix of the given filename or string.
Parameters: filename : str
Filename or string to strip.
suffix : str, optional
Suffix to be stripped off (e.g. ‘.txt’ including the dot).
Returns: str
Filename or string without suffix.
-
madmom.utils.
match_file
(filename, match_list, suffix=None, match_suffix=None, match_exactly=True)[source]¶ Match a filename or string against a list of other filenames or strings.
Parameters: filename : str
Filename or string to match.
match_list : list
Match to this list of filenames or strings.
suffix : str, optional
Suffix of filename to be ignored.
match_suffix : str, optional
Match only files from match_list with this suffix.
match_exactly : bool, optional
Matches must be exact, i.e. have the same base name.
Returns: list
List of matched files.
Notes
Asterisks “*” can be used to match any string or suffix.
-
madmom.utils.
load_events
(*args, **kwargs)[source]¶ Load a events from a text file, one floating point number per line.
Parameters: filename : str or file handle
File to load the events from.
Returns: numpy array
Events.
Notes
Comments (lines starting with ‘#’) and additional columns are ignored, i.e. only the first column is returned.
-
madmom.utils.
write_events
(events, filename, fmt='%.3f', delimiter='\t', header='')[source]¶ Write events to a text file, one event per line.
Parameters: events : numpy array
Events to be written to file.
filename : str or file handle
File to write the events to.
fmt : str, optional
How to format the events.
delimiter : str, optional
String or character separating multiple columns.
header : str, optional
Header to be written (as a comment).
Returns: numpy array
Events.
Notes
This function is just a wrapper to
np.savetxt
, but reorders the arguments in a way it can be used as anprocessors.OutputProcessor
.
-
madmom.utils.
combine_events
(events, delta, combine='mean')[source]¶ Combine all events within a certain range.
Parameters: events : list or numpy array
Events to be combined.
delta : float
Combination delta. All events within this delta are combined.
combine : {‘mean’, ‘left’, ‘right’}
How to combine two adjacent events:
- ‘mean’: replace by the mean of the two events
- ‘left’: replace by the left of the two events
- ‘right’: replace by the right of the two events
Returns: numpy array
Combined events.
-
madmom.utils.
quantize_events
(events, fps, length=None, shift=None)[source]¶ Quantize the events with the given resolution.
Parameters: events : numpy array
Events to be quantized.
fps : float
Quantize with fps frames per second.
length : int, optional
Length of the returned array.
shift : float, optional
Shift the events by this value before quantisation
Returns: numpy array
Quantized events.
-
class
madmom.utils.
OverrideDefaultListAction
(sep=None, *args, **kwargs)[source]¶ An argparse action that works similarly to the regular ‘append’ action. The default value is deleted when a new value is specified. The ‘append’ action would append the new value to the default.
Parameters: sep : str, optional
Separator to be used if multiple values should be parsed from a list.
-
madmom.utils.
segment_axis
(signal, frame_size, hop_size, axis=None, end='cut', end_value=0)[source]¶ Generate a new array that chops the given array along the given axis into (overlapping) frames.
Parameters: signal : numpy array
Signal.
frame_size : int
Size of each frame [samples].
hop_size : int
Hop size between adjacent frames [samples].
axis : int, optional
Axis to operate on; if ‘None’, operate on the flattened array.
end : {‘cut’, ‘wrap’, ‘pad’}, optional
What to do with the last frame, if the array is not evenly divisible into pieces; possible values:
- ‘cut’ simply discard the extra values,
- ‘wrap’ copy values from the beginning of the array,
- ‘pad’ pad with a constant value.
end_value : float, optional
Value used to pad if end is ‘pad’.
Returns: numpy array, shape (num_frames, frame_size)
Array with overlapping frames
Notes
The array is not copied unless necessary (either because it is unevenly strided and being flattened or because end is set to ‘pad’ or ‘wrap’).
The returned array is always of type np.ndarray.
Examples
>>> segment_axis(np.arange(10), 4, 2) array([[0, 1, 2, 3], [2, 3, 4, 5], [4, 5, 6, 7], [6, 7, 8, 9]])