maad.features.all_spectral_alpha_indices

maad.features.all_spectral_alpha_indices(Sxx_power, tn, fn, flim_low=[0, 1000], flim_mid=[1000, 10000], flim_hi=[10000, 20000], verbose=False, display=False, **kwargs)[source]

Computes the acoustic indices in spectral (spectrum (1d) or spectrogram (2d)) domain.

Parameters:
Sxx_power2D array of floats

Power spectrogram to process (taken directly from maad.sound.spectrogram)

tn1d ndarray of floats

time vector (horizontal x-axis)

fn1d ndarray of floats

Frequency vector (vertical y-axis)

flim_lowtupple, optional, default is (0,1000)

Low frequency band in Hz

flim_midtupple, optional, default is (1000,10000)

mid frequency band in Hz

flim_hitupple, optional, default is (10000,20000)

high frequency band in Hz

verboseboolean, default is False

print indices on the default terminal

displayboolean, default is False

Display graphs

kwargsarguments for functions:
  • spectral_leq

  • frequency_entropy

  • soundscape_index

  • bioacoustics_index

  • acoustic_diversity_index

  • acoustic_eveness_index

  • spectral_cover

  • spectral_activity

  • spectral_events

  • tfsd

  • region_of_interest_index

For soundscape_index, bioacoustics_index, acoustic_diversity_index, acoustic_eveness_index

R_compatiblestring, optional, default is “soundecology”

if ‘soundecology’, the result is similar to the package SoundEcology in R. Otherwise, the result is specific to maad

For LEQf calculation

gaininteger

Total gain applied to the sound (preamplifer + amplifier)

Vadcscalar, optional, default is 2Vpp (=>+/-1V)

Maximal voltage (peak to peak) converted by the analog to digital convertor ADC

sensitivityfloat, optional, default is -35 (dB/V)

Sensitivity of the microphone

dBrefinteger, optional, default is 94 (dBSPL)

Pressure sound level used for the calibration of the microphone (usually 94dB, sometimes 114dB)

pReffloat

Sound pressure reference in the medium (air : 20e-6, water : 1e-6)

For spectral activity and events

dB_thresholdscalar, optional, default is 3dB

data >Threshold is considered to be an event if the length is > rejectLength

For spectral activity and events

rejectDurationscalar, optional, default is None

event shorter than rejectDuration are discarded duration is in s

For ROI

new function region_of_interest_index

seed_levelscalar, default is 13

Higher threshold (in dB) for the absolute binarization. Pixels with values above this threshold are considered part of a potential ROI.

low_levelscalar, default is 6

Lower threshold (in dB) for the absolute binarization. Pixels with values above this threshold and connected to a “seed” pixel are also considered part of a potential ROI.

fusion_roistuple of scalars, default is (0.05, 100)

Tuple defining the temporal (in seconds) and frequency (in Hz) dimensions for morphological closing. This operation fuses nearby ROIs.

remove_rois_flim_minscalar or tuple of scalars, default is 50

Frequency limit (in Hz) below which ROIs are removed. Can be a single value or a tuple defining a range (min_freq, max_freq).

remove_rois_flim_maxscalar, default is none

Frequency limit (in Hz) above which ROIs are removed.

remove_rainboolean, default is True

If True, vertical frequency spikes due to rain are removed as possible by applying a morphological mathematical image processing : grey opening

min_event_durationscalar, optional

Minimum time duration of an event (in s). ROIs shorter than this are removed.

max_event_durationscalar, optional

Maximum time duration of an event (in s). ROIs longer than this are removed.

min_freq_bwscalar, optional

Minimum frequency bandwidth (in Hz). ROIs with smaller bandwidth than this are removed.

max_freq_bwscalar, optional

Maximum frequency bandwidth (in Hz). ROIs with larger bandwidth than this are removed.

max_ratio_xyscalar, optional

Maximum ratio between the vertical axis (y) and horizontal axis (x) that is allowed for a ROI. This is very convenient to remove vertical spikes (e.g. rain). 10 seems a reasonable value to remove most of spikes due to light to medium rainfall.

set DEPRECATED_ROI to True to use the old version of the function (which is now called region_of_interest_index_deprecated)

smooth_param1scalar, default is 1

Standard deviation of the gaussian kernel used to smooth the image The larger is the number, the smoother will be the image and the longer it takes. Standard values should fall between 0.5 to 3

mask_modestring in {‘relative’, ‘absolute’}, optional, default is ‘relative’
if ‘relative’:

Binarize an image based on a double relative threshold. The values used for the thresholding depends on the values found in the image. => relative threshold

if ‘absolute’ :

Binarize an image based on a double relative threshold. The values used for the thresholding are independent of the values in the image => absolute threshold

mask_param1scalar, default is 6

if ‘relative’ : bin_h if ‘absolute’ : bin_std

mask_param2scalar, default is 0.5

if ‘relative’ : bin_l if ‘absolute’ : bin_per

remove_rainboolean, default is False

If True, most of spikes in spectrogram due to rain are removed using a math morphological method, the grey opening

max_ratio_yxscalar, optional, defaultNone

Define the maximum ratio between the vertical axis (y) and horizontal axis (x) that is allowed for a ROI. This is very convenient to remove vertical spikes (e.g. rain). 10 seems a reasonable value to remove most of spikes due to light to medium rainfall.

min_roi, max_roiscalars, optional, default9, 512*10000

Define the minimum and the maximum area possible for an ROI. If None, the minimum ROI area is 1 pixel and the maximum ROI area is the area of the image

For ADI, AEI, RAOQ

bin_stepscalar, optional, default is 1000

Frequency step in Hz

For ADI and AEI

ADI_dB_thresholdscalar, optional, default is -50

Threshold in dB

AEI_dB_thresholdscalar, optional, default is -50

Threshold in dB

Returns:
df_spectral_indices: Panda dataframe

Dataframe containing of the calculated spectral indices :

df_per_bin_indicesPanda dataframe

Dataframe containing of the calculated spectral indices per frequency bin :

Notes

In order to obtain the same output for AEI and ADI as for soundecology,

the signal and the spectrogram need to be processed without detrend on. maad.sound.load(“myfile.wav”, …, detrend = False) maad.sound.spectrogram(s, fs, …, detrend = False) For a complete example, see the examples of the functions acoustic_eveness_index and acoustic_diversity_index

Examples

>>> import maad

Spectral indices on a daylight recording

>>> s, fs = maad.sound.load('../data/cold_forest_daylight.wav')
>>> Sxx_power,tn,fn,ext = maad.sound.spectrogram (s, fs)  
>>> df_spectral_indices_DAY, _ = maad.features.all_spectral_alpha_indices(Sxx_power,tn,fn,display=True, extent=ext)

Spectral indices on a night recording

>>> s, fs = maad.sound.load('../data/cold_forest_night.wav')
>>> Sxx_power,tn,fn,ext = maad.sound.spectrogram (s, fs)  
>>> df_spectral_indices_NIGHT, _ = maad.features.all_spectral_alpha_indices(Sxx_power,tn,fn,display=True)

Variation between night and day

>>> variation = abs(df_spectral_indices_DAY - df_spectral_indices_NIGHT)/df_spectral_indices_NIGHT*100
>>> print('LEQf variation night vs day: %2.2f %%' % variation['LEQf'][0])
LEQf variation night vs day: 34.94 %
>>> print('Hf variation night vs day: %2.2f %%' % variation['Hf'][0])
Hf variation night vs day: 105.61 %
>>> print('ACI variation night vs day: %2.2f %%' % variation['ACI'][0])
ACI variation night vs day: 3.39 %
>>> print('AGI variation night vs day: %2.2f %%' % variation['AGI'][0])
AGI variation night vs day: 20.50 %
>>> print('ROItotal variation night vs day: %2.2f %%' % variation['ROItotal'][0])
ROItotal variation night vs day: 264.47 %