partitura.musicanalysis

This module contains tools for estimating key signature, time signature, pitch spelling, voice information, tonal tension, as well as methods for deriving note-level features and performance encodings.

partitura.musicanalysis.compute_note_array(part, include_pitch_spelling=False, include_key_signature=False, include_time_signature=False, include_metrical_position=False, include_grace_notes=False, feature_functions=None)[source]

Create an extended note array from this part.

1) Without arguments this returns a structured array of onsets, offsets, pitch, and ID information: equivalent to part.note_array()

2) With any of the flag arguments set to true, a column with the specified information will be added to the array: equivalent t0 part.note_array(*flags)

3) With a list of strings or functions as feature_functions argument, a column (or multiple columns) with the specified information will be added to the array. See also: >>> make_note_features(part) For a list of features see: >>> list_note_feats_functions()

Parameters
  • include_pitch_spelling (bool (optional)) – If True, includes pitch spelling information for each note. Default is False

  • include_key_signature (bool (optional)) – If True, includes key signature information, i.e., the key signature at the onset time of each note (all notes starting at the same time have the same key signature). Default is False

  • include_time_signature (bool (optional)) – If True, includes time signature information, i.e., the time signature at the onset time of each note (all notes starting at the same time have the same time signature). Default is False

  • include_metrical_position (bool (optional)) – If True, includes metrical position information, i.e., the position of the onset time of each note with respect to its measure (all notes starting at the same time have the same metrical position). Default is False

  • include_grace_notes (bool (optional)) – If True, includes grace note information, i.e. if a note is a grace note and the grace type “” for non grace notes). Default is False

  • feature_functions (list or str) – A list of feature functions. Elements of the list can be either the functions themselves or the names of a feature function as strings (or a mix). The feature functions specified by name are looked up in the featuremixer.featurefunctions module.

  • Returns

  • note_array (structured array) –

partitura.musicanalysis.decode_performance(part: Part, performance_array: ndarray, snote_ids=None, part_id=None, part_name=None, return_alignment=False, *args, **kwargs) PerformedPart[source]

Given a Part (score) and a performance array return a PerformedPart.

Parameters
  • part (partitura.score.Part) – A partitura Part representing a score

  • performance_array (structured array) – A performed array related to the part.

  • snote_ids (list) –

  • part_id (str) –

  • part_name (str) –

  • return_alignment (bool) – True returns alignment list of dicts.

Returns

  • ppart (partitura.performance.PerformedPart) – A partitura PerformedPart.

  • alignment (list (optional)) – A list of dicts for the alignment.

partitura.musicanalysis.encode_performance(part: Part, ppart: PerformedPart, alignment: list, return_u_onset_idx=False)[source]

Encode expressive parameters from a matched performance

Parameters
  • part (partitura.Part) – The score full either load from a match file.

  • ppart (partitura.PerformedPart) – A list of Dictionaries

  • alignment (list) – The score–performance alignment, a list of dictionaries

  • return_u_onset_idx (bool) – Return the indices of the unique score onsets

Returns

  • parameters (structured array) – A performance array with 4 fields: beat_period, velocity, timing, and rticulation_log.

  • snote_ids (dict) – A dict of snote_ids corresponding to performance notes.

  • unique_onset_idxs (list (optional)) – List of unique onset ids. Returned only when return_u_onset_idx is set to True.

partitura.musicanalysis.estimate_key(note_info, method='krumhansl', *args, **kwargs)[source]

Estimate key of a piece by comparing the pitch statistics of the note array to key profiles 2, 3.

Parameters
  • note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or as a structured array. If it is a structured array, it has to contain the fields generated by the note_array properties of Part or PerformedPart objects. If the array contains onset and duration information of both score and performance, (e.g., containing both onset_beat and onset_sec), the score information will be preferred.

  • method ({'krumhansl'}) – Method for estimating the key. For now ‘krumhansl’ is the only supported method.

  • args – Positional and Keyword arguments for the key estimation method

  • kwargs – Positional and Keyword arguments for the key estimation method

Returns

String representing the key name (i.e., Root(alteration)(m if minor)). See partitura.utils.key_name_to_fifths_mode and partitura.utils.fifths_mode_to_key_name.

Return type

str

References

2

Krumhansl, Carol L. (1990) “Cognitive foundations of musical pitch”, Oxford University Press, New York.

3

Temperley, D. (1999) “What’s key for key? The Krumhansl-Schmuckler key-finding algorithm reconsidered”. Music Perception. 17(1), pp. 65–100.

partitura.musicanalysis.estimate_spelling(note_info, method='ps13s1', **kwargs)[source]

Estimate pitch spelling using the ps13 algorithm 4, 5.

Parameters
  • note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or as a structured array. If it is a structured array, it has to contain the fields generated by the note_array properties of Part or PerformedPart objects. If the array contains onset and duration information of both score and performance, (e.g., containing both onset_beat and onset_sec), the score information will be preferred.

  • method ({'ps13s1'}) – Pitch spelling algorithm. More methods will be added.

  • **kwargs – Keyword arguments for the algorithm specified in method.

Returns

spelling – Array with pitch spellings. The fields are ‘step’, ‘alter’ and ‘octave’

Return type

structured array

References

4

Meredith, D. (2006). “The ps13 Pitch Spelling Algorithm”. Journal of New Music Research, 35(2):121.

5

Meredith, D. (2019). “RecurSIA-RRT: Recursive translatable point-set pattern discovery with removal of redundant translators”. 12th International Workshop on Machine Learning and Music. Würzburg, Germany.

partitura.musicanalysis.estimate_time(note_info)[source]

Estimate tempo, meter (currently only time signature numerator), and beats

Parameters

note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or as a structured array. If it is a structured array, it has to contain the fields generated by the note_array properties of Part or PerformedPart objects. If the array contains onset and duration information of both score and performance, (e.g., containing both onset_beat and onset_sec), the score information will be preferred.

Returns

Tempo, meter, and beat information

Return type

dict

partitura.musicanalysis.estimate_tonaltension(note_info, ws=1.0, ss='onset', scale_factor=0.09249316305671976, w=array([0.516, 0.315, 0.168]), alpha=0.75, beta=0.75)[source]

Compute tonal tension ribbons defined in 1

Parameters
  • note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or as a structured array. If it is a structured array, it has to contain the fields generated by the note_array properties of Part or PerformedPart objects. If the array contains onset and duration information of both score and performance, (e.g., containing both onset_beat and onset_sec), the score information will be preferred. Furthermore, this method requires pitch spelling and key signature information. If a structured note array is provided as input, this information can be optionally provided in fields step, alter, ks_fifths and ks_mode. If these fields are not found in the input structured array, they will be estimated using the key and pitch spelling estimation methods from partitura.musicanalysis.estimate_key and and partitura.musicanalysis.estimate_spelling, respectively.

  • ws ({int, float, np.array}, optional) – Window size for computing the tonal tension. If a number, it determines the size of the window centered at each specified score position (see ss below). If a numpy array, a 2D array of shape (len(ss), 2) specifying the left and right distance from each score position in ss. Default is 1 beat.

  • ss ({float, int, np.array, 'onset'}, optional.) – Step size or score position for computing the tonal tension features. If a number, this parameter determines the size of the step (in beats) starting from the first score position. If an array, it specifies the score positions at which the tonal tension is estimated. If ‘onset’, it computes the tension at each unique score position (i.e., all notes in a chord have the same score position). Default is ‘onset’.

  • scale_factor (float) – A multiplicative scaling factor.

  • w (np.ndarray) – Weights for the chords

  • alpha (float) – Alpha.

  • beta (float) – Beta.

Returns

tonal_tension – Array containing the tonal tension features. It contains the fields cloud_diameter, cloud_momentum, tensile_strain and onset.

Return type

structured array

References

1

D. Herremans and E. Chew (2016) Tension ribbons: Quantifying and visualising tonal tension. Proceedings of the Second International Conference on Technologies for Music Notation and Representation (TENOR), Cambridge, UK.

partitura.musicanalysis.estimate_voices(note_info, monophonic_voices=True)[source]
Voice estimation using the voice separation algorithm

proposed in 6.

Parameters
  • note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or as a structured array. If it is a structured array, it has to contain the fields generated by the note_array properties of Part or PerformedPart objects. If the array contains onset and duration information of both score and performance, (e.g., containing both onset_beat and onset_sec), the score information will be preferred.

  • monophonic_voices (bool) – If True voices are guaranteed to be monophonic. Otherwise notes with the same onset and duration are treated as a chord and assigned to the same voice. Defaults to False.

Returns

voice – Voice for each note in the notearray. (The voices start with 1, as is the MusicXML convention).

Return type

numpy array

References

6

Chew, E. and Wu, Xiaodan (2004) “Separating Voices in Polyphonic Music: A Contig Mapping Approach”. In Uffe Kock, editor, “Computer Music Modeling and Retrieval”. Springer Berlin Heidelberg.

partitura.musicanalysis.full_note_array(part)[source]

Create a note array with all available information.

partitura.musicanalysis.list_note_feats_functions()[source]

Return a list of all feature function names defined in this module.

The feature function names listed here can be specified by name in the make_feature function. For example:

>>> feature, names = make_note_feats(part, ['metrical_feature', 'articulation_feature'])
Returns

A list of strings

Return type

list

partitura.musicanalysis.make_note_features(part: Union[Part, PartGroup, List], feature_functions: Union[List, str], add_idx: bool = False) Tuple[ndarray, List][source]

Compute the specified feature functions for a part.

The function returns the computed feature functions as a N x M array, where N equals len(part.notes_tied) and M equals the total number of descriptors of all feature functions that occur in part.

Furthermore the function returns the names of the feature functions. A list of strings of size M. The names have the name of the function prepended to the name of the descriptor. For example if a function named abc_feature returns descriptors a, b, and c, then the list of names returned by make_feature(part, [‘abc_feature’]) will be [‘abc_feature.a’, ‘abc_feature.b’, ‘abc_feature.c’].

Parameters
  • part (Part) – The score as a Part instance

  • feature_functions (list or str) – A list of feature functions. Elements of the list can be either the functions themselves or the names of a feature function as strings (or a mix), or the keywork “all”. The feature functions specified by name are looked up in the featuremixer.featurefunctions module.

Returns

  • feature (ndarray) – The feature functions

  • names (list) – The feature names

partitura.musicanalysis.make_rest_features(part: Union[Part, PartGroup, List], feature_functions: Union[List, str], add_idx: bool = False) Tuple[ndarray, List][source]

Compute the specified feature functions for a part.

The function returns the computed feature functions as a N x M array, where N equals len(part.rests) and M equals the total number of descriptors of all feature functions that occur in part.

Parameters
  • part (Part) – The score as a Part instance

  • feature_functions (list or str) – A list of feature functions. Elements of the list can be either the functions themselves or the names of a feature function as strings (or a mix), or the keywork “all”. The feature functions specified by name are looked up in the featuremixer.featurefunctions module.

Returns

  • feature (ndarray) – The feature functions

  • names (list) – The feature names