maad.features.all_shape_features
- maad.features.all_shape_features(s, fs, rois, resolution='low', display=False, **kwargs)[source]
Computes shape and central frequency features from signal at specified time-frequency limits defined by regions of interest (ROIs).
- Parameters:
- s: ndarray
Singal to be analysed
- fs: int
Sampling frequency of the signal
- rois: pandas DataFrame
Time frequency limits for the analysis. Columns should have at least min_t, max_t, min_f, max_f. Can be computed with multiple detection methods, such as find_rois_cwt
- resolution: str or dict, default is ‘med’
Specify resolution of shape descriptors. Can be: ‘low’, ‘med’, ‘high’. Default is ‘low’. Alternatively, custom resolution can be provided using a dictionary with options to define the filter bank. Valid keys are: ntheta, bandwidth, frequency, gamma, npyr
- opt_spec: dictionnary, optional
Options for the spectrogram with keys, window length ‘nperseg’, window overlap in percentage ‘overlap’ and frequency limits ‘flims’ which is a list of 2 scalars : minimum and maximum boundary frequency values in Hertz
- display: boolean, optional, default is False
Flag. If display is True, plot results
- kwargs, optional. This parameter is used by plt.plot and savefig functions
- savefilenamestr, optional, default :’_spectro_overlaycentroid.png’
Postfix of the figure filename
- figsizetuple of integers, optional, default: (4,10)
width, height in inches.
- titlestring, optional, default‘Spectrogram’
title of the figure
- xlabelstring, optional, default‘Time [s]’
label of the horizontal axis
- ylabelstring, optional, default‘Amplitude [AU]’
label of the vertical axis
- cmapstring or Colormap object, optional, default is ‘gray’
See https://matplotlib.org/examples/color/colormaps_reference.html in order to get all the existing colormaps examples: ‘hsv’, ‘hot’, ‘bone’, ‘tab20c’, ‘jet’, ‘seismic’, ‘viridis’…
- vmin, vmaxscalar, optional, default: None
vmin and vmax are used in conjunction with norm to normalize luminance data. Note if you pass a norm instance, your settings for vmin and vmax will be ignored.
- dpiinteger, optional, default is 96
Dot per inch. For printed version, choose high dpi (i.e. dpi=300) => slow For screen version, choose low dpi (i.e. dpi=96) => fast
- formatstring, optional, default is ‘png’
Format to save the figure
… and more, see matplotlib
- Returns:
- feature_rois: pandas Dataframe
A dataframe with each column corresponding to a feature
Examples
>>> import maad >>> from maad.util import read_audacity_annot >>> from maad.sound import load >>> from maad.features import all_shape_features >>> s, fs = load('../data/spinetail.wav') >>> rois = read_audacity_annot('../data/spinetail.txt') >>> features = all_shape_features(s, fs, rois, resolution='low', display=True) number of rois : 18 >>> print(features.iloc[0]) label SP min_t 0.101385 min_f 6441.064453 max_t 0.36752 max_f 12296.577148 min_y 150 min_x 8 max_y 286 max_x 31 shp_001 0.160656 shp_002 0.155573 shp_003 0.064787 shp_004 0.066215 shp_005 0.158675 shp_006 0.125203 shp_007 0.044987 shp_008 0.043188 shp_009 0.218268 shp_010 0.158725 shp_011 0.043553 shp_012 0.031206 shp_013 0.268222 shp_014 0.21718 shp_015 0.059112 shp_016 0.038394 centroid_y 220.0 centroid_x 19.0 duration_x 135.999274 bandwidth_y 0.0 area_xy 12512 centroid_f 9474.609375 centroid_t 0.2322 duration_t 0.267029 bandwidth_f 5857.03125 area_tf 1564.0 Name: 0, dtype: object >>> features.columns Index(['label', 'min_t', 'min_f', 'max_t', 'max_f', 'min_y', 'min_x', 'max_y', 'max_x', 'shp_001', 'shp_002', 'shp_003', 'shp_004', 'shp_005', 'shp_006', 'shp_007', 'shp_008', 'shp_009', 'shp_010', 'shp_011', 'shp_012', 'shp_013', 'shp_014', 'shp_015', 'shp_016', 'centroid_y', 'centroid_x', 'duration_x', 'bandwidth_y', 'area_xy', 'centroid_f', 'centroid_t', 'duration_t', 'bandwidth_f', 'area_tf'], dtype='object')