maad.sound.load_spectrogram

maad.sound.load_spectrogram(filename, fs, duration, flims=None, flipud=True, verbose=False, display=False, **kwargs)[source]

Load an image from a file or an URL

Parameters:
filenamestring

Image file name, e.g. test.jpg or URL.

fsscalar

Sampling frequency of the audiogram (in Hz)

durationscalar

Duration of the audiogram (in s)

flimslist of 2 scalars [min, max], optional, default is None

flims corresponds to the min and max boundary frequency values

flipudboolean, optional, default is True

Vertical flip of the matrix (image)

verboseboolean, optional, default is False

if True, print message in terminal

displayboolean, optional, default is False

if True, display the image

kwargs, optional. This parameter is used by plt.plot
  • 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.

  • extentscalars (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.

  • 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:
Sxxndarray

The different color bands/channels are stored in the third dimension, such that a gray-image is MxN, an RGB-image MxNx3 and an RGBA-image MxNx4.

tn1d ndarray of floats

time vector (horizontal x-axis)

fn1d ndarray of floats

Frequency vector (vertical y-axis)

extentlist of scalars [left, right, bottom, top]

The location, in data-coordinates, of the lower-left and upper-right corners.

Examples

>>> import maad
>>> xenocanto_link = 'https://www.xeno-canto.org/sounds/uploaded/DTKJSKMKZD/ffts/XC445081-med.png'
>>> Sxx, tn, fn, ext = maad.sound.load_spectrogram(filename=xenocanto_link,                                                         fs=44100,                                                                       flims=[0,15000],                                                                duration = 10,                                                                  )
>>> print("The time resolution of the spectrogram is {} s and the frequency resolution is {} Hz".format(tn[1]-tn[0], fn[1]-fn[0]))
The time resolution of the spectrogram is 0.020876826722338204 s and the frequency resolution is 94.33962264150944 Hz
>>> import matplotlib.pyplot as plt
>>> ax, fig = maad.util.plot2d(Sxx,extent=ext)