musif.process package

Submodules

musif.process.constants module

musif.process.constants.PRESENCE = 'Presence_of'

Constant to create columns regarding presenc of an instrument or not.

musif.process.constants.voices_list = ['sop', 'ten', 'alt', 'bar', 'bbar', 'bass']

List of prefixes for singers used to find voices columns

musif.process.constants.voices_list_prefixes = ['PartSop_', 'PartTen_', 'PartAlt_', 'PartBar_', 'PartBbar_', 'PartBass_']

List of prefixes Part_ + each element of voices_list

musif.process.processor module

class musif.process.processor.DataProcessor(info: str | pandas.DataFrame, *args, **kwargs)[source]

Bases: object

Processor class that treats columns and information of a DataFrame

This operator processes information from a DataFrame or a .csv file. It deletes unseful columns for analysis and saves important ones. Also saves data in several files in .csv format. The main method .process() returns a DataFrame and saves data. Requires to have a labels file in ./internal_data directory containing each label assigned to each score. …

data

DataFrame extracted with FeaturesExtractor containing all info.

Type:

DataFrame

info

Path to .csv file or Dataframe containing the information from FeaturesExtractor

Type:

str

__init__(info: str | pandas.DataFrame, *args, **kwargs)[source]
Parameters:
  • *args (str) – Could be a path to a .yml file, a PostProcessConfiguration object or a dictionary. Length zero or one.

  • *kwargs (str) – Key words arguments to construct

  • kwargs[info] (Union[str, DataFrame]) – Either a path to a .csv file containing the information either a DataFrame object fromm FeaturesExtractor

delete_duplicated_sound_columns() → None[source]

Deletes the Sound<X>_* columns of every sound performed by exactly one part throughout the DataFrame: for a single-part sound they equal the Part<X>_* columns by construction (the sound scope aggregates over one part). The per-part-mean and part-count columns (NotesMean, SoundingMeasuresMean, NumberOfParts, NumberOfFilteredParts) are kept.

delete_files_without_harmony()[source]

Deletes files (actually rows in the DataFrame) that didn’t have a proper harmonic analysis and, there fore, got a value of 0 in ‘Harmony_Available’ column

delete_undesired(**kwargs) → None[source]

Deletes not necessary columns and rows for statistical analysis.

If keyword arguments are passed in, they overwrite those found into configurationg file

Parameters:

**kwargs (str, optional) – Any value from config.yml can be overwritten by passing arguments to the method

Raises:

KeyError – If any of the columns required to delete is not found in the original DataFrame.

group_columns() → None[source]

Groups Key_*_PercentageMeasures, Key_Modulatory and Degrees columns. Into bigger groups for agregated analysis, keeping the previous ones. Also deletes unnecesary columns for analysis.

process() → pandas.DataFrame[source]

Main method of the class. Removes NaN values, deletes unuseful columns and merges those that are needed according to config.yml file.

Return type:

Dataframe object

replace_nans() → None[source]

Replaces by 0 the empty cells that stand for “no such event”.

Only the columns selected by replace_nans in the configuration are touched, and among them only those that count events or give their proportion (_Count, _Per, and the chord, numeral, key and addition columns of the harmonic analysis). A cell is replaced only in the rows where there was something to measure: the part, sound or family has notes in that score, and, for the columns that depend on the harmonic analysis (Harmony_ and _relative), the analysis is available.

So after this step a 0 is always a measured zero. The cells of a part that is absent from a score stay empty, and so do the statistics (means, deviations, ratios…) that could not be computed.

save(dest_path: str | PurePath, ext='.csv', ft='csv', **kwargs) → None[source]

Saves current information into a file given the name of dest_path

To load one of those file, remember to set the index to musif.extract.constant.ID, and, if windows are used, to musif.extract.constant.WINDOW_ID:

`python df = pd.read_csv('window_alldata.csv').set_index(['Id', 'WindowId']) `

Parameters:
  • dest_path (str or Path) – Path to directory where the file will be stored; the suffix _alldata plus the extension is added.

  • ext (str) – Extension used to save files. Use .gz, .xz, .zip etc. to compress the files. Default: .csv

  • ft (str) – Type of file for saving. The filetype must be supported by pandas, e.g. to_csv, to_feather, to_parquet, etc. Default: csv

separate_instrumentation_column() → None[source]

Separates Instrumentation column into as many columns as instruments present in Instrumentation, assigning a value of 1 for every instrument that is present and 0 if it is not for every row (aria).

musif.process.utils module

musif.process.utils.join_part_degrees(total_degrees: List[str], part: str, df: pandas.DataFrame, sufix: str = '') → None[source]

Group one prefix’s per-degree columns into Asc/Desc/Dasc/Ddesc/Nat/Nonat aggregates, separately for _Count and _Per columns.

The accidental is matched as a token of the column name (not a substring), so prefixes containing ‘b’ or ‘x’ (PartOb_, PartTbn_, …) cannot contaminate the groups.

musif.process.utils.merge_dataframes(name: str, dest_path: str) → None[source]

Takes two dataframes and joins them, apart from deleting rows that are all nans. This is intended for cases where all extraction of a folder cannot be done all at once.

Return type:

Dataframe with the extracted features as a concatenation of two dataframes