Input and Output

The module io has a collection of functions to perform input and output operations.

get_audio_info(audio_path, format_name[, ...])

Extract audio file information from a file or directory.

store_df(df, file_type, base_dir, file_name)

Store a DataFrame to a file in a specified format.

maui.io.get_audio_info(audio_path, format_name, date_time_func=None, format_file_path=None, store_duration=False, perc_sample=1)[source]

Extract audio file information from a file or directory.

This function processes audio files specified by the ‘audio_path’ argument, extracting information such as filename structure, timestamps, and duration. It can handle both single audio files and entire directories of audio files.

Parameters:
audio_path: str

The path to an audio file or directory containing audio files.

store_duration: int, optional

Whether to calculate and store audio duration (default is 0).

perc_sample float, optional

Percentage of audio files to include when processing a directory (default is 1).

Returns:
df: pandas.DataFrame

A DataFrame containing information about the audio files.

Raises:
Exception:

If the input is neither a file nor a directory.

Examples

>>> from maui import io
>>> audio_file = "forest_channelA_20210911_153000_jungle.wav"
>>> io.get_audio_info(audio_file, store_duration=1, perc_sample=0.8)
>>> audio_dir = "/path/to/audio/directory"
>>> df = io.get_audio_info(audio_dir, "LEEC_FILE_FORMAT",
                           store_duration=True, perc_sample=1)
>>> df["dt"] = pd.to_datetime(df["timestamp_init"]).dt.date
maui.io.store_df(df, file_type, base_dir, file_name)[source]

Store a DataFrame to a file in a specified format.

This function takes a DataFrame ‘df’ and saves it to a file in the specified ‘file_type’ and location, combining ‘base_dir’ and ‘file_name’.

Parameters:
df: pandas.DataFrame

The DataFrame to be saved.

file_type: str

The file format to use for storing the DataFrame (‘csv’ or ‘pickle’).

base_dir: str

The base directory where the file will be saved.

file_name: str

The name of the file (without file extension).

Returns:
None

Examples

>>> from maui import io
>>> data = {'A': [1, 2, 3], 'B': ['a', 'b', 'c']}
>>> df = pd.DataFrame(data)
>>> io.store_df(df, 'csv', '/path/to/directory', 'my_dataframe')
# Saves the DataFrame as '/path/to/directory/my_dataframe.csv'
>>> io.store_df(df, 'pickle', '/path/to/directory', 'my_dataframe')
# Saves the DataFrame as '/path/to/directory/my_dataframe.pkl'