maad.util.overlay_centroid
- maad.util.overlay_centroid(im_ref, centroid, savefig=None, **kwargs)[source]
Overlay centroids on the original spectrogram
- Parameters:
- Sxx2D array
Spectrogram
- centroid: pandas DataFrame
DataFrame with centroid descriptors (centroid_f, centroid_t) Do format_features(rois,tn,fn) before using overlay_centroid to be sure that the format of the DataFrame is correct
- savefigstring, optional, default is None
Root filename (with full path) is required to save the figures. Postfix is added to the root filename.
- kwargs, optional. This parameter is used by plt.plot and savefig functions
- savefilenamestr, optional, default :’_spectro_overlaycentroid.png’
Postfix of the figure filename
- extentlist of scalars [left, right, bottom, top], optional, default: None
The location, in data-coordinates, of the lower-left and upper-right corners. If None, the image is positioned such that the pixel centers fall on zero-based (row, column) indices.
- 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:
- ax
axis object (see matplotlib)
- fig
figure object (see matplotlib)
Examples
Get centroid from the whole power spectrogram
>>> from maad.sound import load, spectrogram >>> from maad.features import centroid_features >>> from maad.util import (power2dB, format_features, overlay_rois, plot2d, overlay_centroid)
Load audio and compute spectrogram
>>> s, fs = load('../data/spinetail.wav') >>> Sxx,tn,fn,ext = spectrogram(s, fs, db_range=80) >>> Sxx = power2dB(Sxx, db_range=80)
Load annotations and plot
>>> from maad.util import read_audacity_annot >>> rois = read_audacity_annot('../data/spinetail.txt') >>> rois = format_features(rois, tn, fn) >>> ax, fig = plot2d (Sxx, extent=ext) >>> ax, fig = overlay_rois(Sxx,rois, extent=ext, ax=ax, fig=fig)
Compute the centroid of each rois, format to get results in the temporal and spectral domain and overlay the centroids.
>>> centroid = centroid_features(Sxx, rois) >>> centroid = format_features(centroid, tn, fn) >>> ax, fig = overlay_centroid(Sxx,centroid, extent=ext, ax=ax, fig=fig)