Acoustic Indices

The module acoustic_indices has a collection of functions to calculate acoustic indices from raw audio files.

calculate_acoustic_indices(df_init, ...[, ...])

Calculate acoustic indices for audio files in a DataFrame.

maui.acoustic_indices.calculate_acoustic_indices(df_init, file_path_col, acoustic_indices_methods, pre_calculation_method, parallel, chunk_size=None, temp_dir='./tmp_maui_ac_files/')[source]

Calculate acoustic indices for audio files in a DataFrame.

This method processes a DataFrame containing file paths to audio files, calculates acoustic indices using the specified methods, and returns a DataFrame with the results. The calculations can be performed in parallel or sequentially, depending on the parallel flag.

Return type:

DataFrame

Parameters:
df_initpd.DataFrame

The initial DataFrame containing the file paths to audio files and any other necessary metadata.

file_path_colstr

The name of the column in df_init that contains the file paths to the audio files.

acoustic_indices_methodslist of callables

A list of methods, where each method computes a specific acoustic index. Each method should accept the output of pre_calculation_method and return a dictionary of index names and values.

pre_calculation_methodcallable

A method that performs any necessary pre-calculations on the audio data. It should accept the loaded audio data and sampling rate, returning an object that will be passed to each of the acoustic_indices_methods.

parallelbool

If True, the calculations will be performed in parallel using multiple processes. If False, the calculations will be performed sequentially.

chunk_sizeint, optional

The number of rows to process in each chunk. If not provided, a default value is calculated based on the number of CPU cores available.

temp_dirstr, optional

The directory path where the temporary CSV files will be saved. The default is ‘./tmp_maui_ac_files/’.

Returns:
pd.DataFrame

A DataFrame containing the original data along with the calculated acoustic indices.

Notes

  • The method first divides the DataFrame into smaller chunks, each of which is processed separately to calculate the acoustic indices. The results are saved as temporary CSV files.

  • If parallel is True, multiple processes are used to calculate the indices concurrently. Otherwise, the calculation is done sequentially.

  • The method combines the results from all chunks into a single DataFrame, restores the original data types, and removes the temporary files.

  • The _convert_string_to_list function is applied to the final DataFrame to ensure that the data types are correctly interpreted.