Package: Utility Functions (src.utils)

Module: utils.error_handling.py

This module, which is part of the utils package, contains functions for handling and reporting errors in a detailed and user-friendly manner. This allows for better debugging and understanding of any exceptions that occur during the execution of the code.

Functions

  1. text_exception_general(e: Exception) -> str: This function takes an exception as an input and returns a detailed error message. The error message includes the file, function, and line number where the exception occurred, and also the exception message itself.

  2. handle_error(e: Exception) -> None: This function also takes an exception as an input but instead of returning the error message, it prints the message to the console. This function utilizes text_exception_general to generate the error message.

Examples

>>> try:
...     1 / 0  # Raises ZeroDivisionError
... except Exception as e:
...     handle_error(e)  # This will print a detailed error message to the console
iMaT.src.utils.error_handling.handle_error(e: Exception) None[source]

Handle an error by displaying a detailed error message.

This function takes an exception as input and prints a detailed error message to the console. The error message is generated using the text_exception_general function, and includes information about where the error occurred and the nature of the error.

Parameters:

e (Exception) – The exception to be handled.

Return type:

None

Raises:

Exception – If there is an error during error message generation or printing.

iMaT.src.utils.error_handling.text_exception_general(e: Exception) str[source]

Generate a detailed error message.

This function extracts traceback information from an exception and generates a detailed error message. This includes information about the file, function and line number where the error occurred as well as the error message itself.

Parameters:

e (Exception) – The exception from which to generate the error message.

Returns:

A string containing the detailed error message.

Return type:

str

Raises:

Exception – If there is an error during traceback extraction or error message creation.

Examples

>>> try:
...     1 / 0  # Raises ZeroDivisionError
... except Exception as e:
...     print(text_exception_general(e))

Module: utils.misc.py

This module, part of the utils package, provides various utilities for manipulating, displaying and exporting musical score metadata, part names, and analysis results. It uses the music21 library for handling music data and the pandas library for managing and exporting analysis results as a CSV file.

Functions

  • show_metadata(): Displays the metadata of the selected musical score.

  • show_part_names(): Lists the names of the individual parts in the selected score.

  • change_part_names(): Provides an interface for the user to rename the individual parts in the selected score.

  • export_results_to_csv_auto(previous_results, identifier, function_name): Exports the results of the

    previous analysis to a CSV file. The file name is automatically generated based on the analysis function name, a modified identifier (selected scores + selected measures), and the current timestamp.

iMaT.src.utils.misc.change_part_names()[source]

Modify the names of individual parts in the selected score.

This function allows the user to rename the individual parts/voices in the selected musical score. If no score has been selected, it prompts the user to select a score first.

Raises:

Exception – If there is an error during part names modification.

iMaT.src.utils.misc.export_results_to_csv_auto(previous_results, identifier, function_name)[source]

Export previous analysis results to a CSV file.

This function automatically exports the results of the previous analysis to a CSV file with a unique name. The file name is based on the function_name, a modified identifier (selected scores + selected measures), and the current time. The file is saved in the music21’s scratch directory.

Parameters:
  • previous_results (pandas.DataFrame) – The DataFrame containing the results of the previous analysis.

  • identifier (str) – The identifier of the selected scores and measures.

  • function_name (str) – The name of the function that performed the analysis.

Raises:

Exception – If there is an error during CSV file generation or saving.

iMaT.src.utils.misc.show_metadata()[source]

Display metadata of the selected score.

This function extracts and displays the metadata of the selected musical score. If no score has been selected, it prompts the user to select a score first.

Raises:

Exception – If there is an error during metadata extraction or displaying.

iMaT.src.utils.misc.show_part_names()[source]

Display the names of individual parts in the selected score.

This function extracts and displays the names of the individual parts/voices in the selected musical score. If no score has been selected, it prompts the user to select a score first.

Raises:

Exception – If there is an error during part names extraction or displaying.