utils package
Subpackages
utils.draw module
Utility functions for drawing figures
utils.functions module
Utility functions used for analysis
- unique(input_list: list) list[source]
Extract unique strings from the list in the order they appear
- Parameters:
input_list (list) –
- Return type:
list of unique, ordered string
- find_str(string: str, pattern: str) list[source]
Find all indices of patterns in a string
- Parameters:
string (str) – input string
pattern (str) – string pattern to search
- Returns:
ind – list of starting indices
- Return type:
list
- list_files(dir: str, ext: str) list[source]
Return the list of files in the current directory
- Parameters:
dir (path) –
ext (str) – file extension (e.g., .wav, .rhd etc)
- Returns:
files
- Return type:
list
- myround(x: int, base=5) int[source]
Round to the next multiple of the base
- Parameters:
x (int) – input value
base (int) – base value (5 by default)
- Return type:
int
- extract_ind(timestamp: ndarray, range: list)[source]
Extract timestamp indices from array from the specified range
- Parameters:
timestamp (np.ndarray) –
range (list) – [start end]
- Returns:
ind (np.ndarray) – index of the array
array (np.ndarray) – array within the range
- normalize(array: ndarray) ndarray[source]
Normalizes an array by its average and sd
- Parameters:
array (np.ndarray) – Input array
- Return type:
np.ndarray
utils.save module
Utility functions to make output directories & save output files
- make_dir(parent_path, *dir_name, add_date=True)[source]
Make a new directory
- Parameters:
parent_path (path) –
dir_name (str) – (optional), if not exists, files will be saved in parent_dir
add_date (bool) – make a sub-dir with a date
- Returns:
save_path
- Return type:
path
- save_fig(fig, save_path, name, fig_ext='.png', view_folder=False, dpi=None) None[source]
Save figure
- Parameters:
fig (figure object) –
save_path (path) – directory path to save figures
name (str) – name of the figure
fig_ext (str) – figure extension (e.g., ‘.pdf’ for vector output), ‘.png’ by default
view_folder (bool) – open the folder where the figure is saved
dpi (int) – increase the value for enhanced resolution
utils.spect module
Utility functions for drawing spectrograms
Spectrogram adapted from code by Kyle Kastner and Tim Sainburg https://github.com/timsainb/python_spectrograms_and_inversion
by David Nicholson https://github.com/NickleDave/vak
- spectrogram(dat, samp_freq, fft_size=512, step_size=64, thresh=None, transform_type=None, freq_range=None)[source]
creates a spectrogram
- Parameters:
dat (numpy.ndarray) – audio signal
samp_freq (int) – sampling frequency in Hz
fft_size (int) – size of window for Fast Fourier transform, number of time bins.
step_size (int) – step size for Fast Fourier transform
transform_type (str) – one of {‘log_spect’, ‘log_spect_plus_one’}. ‘log_spect’ transforms the spectrogram to log(spectrogram), and ‘log_spect_plus_one’ does the same thing but adds one to each element. Default is None. If None, no transform is applied.
thresh (int) – threshold minimum power for log spectrogram
freq_range (tuple) – of two elements, lower and higher frequencies.
- Returns:
spect (numpy.ndarray) – spectrogram
freqbins (numpy.ndarray) – vector of centers of frequency bins from spectrogram
utils.stats module
Utility functions for statistical testing