Overview#

This notebook gives a general overview of the features included in the dataset.

Hide imports
%load_ext autoreload
%autoreload 2
import os

import dimcat as dc
import pandas as pd
import plotly.express as px
from dimcat import filters, plotting
from IPython.display import display

import utils
RESULTS_PATH = os.path.abspath(os.path.join(utils.OUTPUT_FOLDER, "overview"))
os.makedirs(RESULTS_PATH, exist_ok=True)


def make_output_path(
    filename: str,
    extension=None,
    path=RESULTS_PATH,
) -> str:
    return utils.make_output_path(filename=filename, extension=extension, path=path)


def save_figure_as(
    fig, filename, formats=("png", "pdf"), directory=RESULTS_PATH, **kwargs
):
    if formats is not None:
        for fmt in formats:
            plotting.write_image(fig, filename, directory, format=fmt, **kwargs)
    else:
        plotting.write_image(fig, filename, directory, **kwargs)

Loading data

D = utils.get_dataset("tchaikovsky_seasons", corpus_release="v2.3")
package = D.inputs.get_package()
package_info = package._package.custom
git_tag = package_info.get("git_tag")
utils.print_heading("Data and software versions")
print("Pyotr Tchaikovsky – The Seasons version v2.3")
print(f"Datapackage '{package.package_name}' @ {git_tag}")
print(f"dimcat version {dc.__version__}\n")
D
Data and software versions
--------------------------

Pyotr Tchaikovsky – The Seasons version v2.3
Datapackage 'tchaikovsky_seasons' @ v2.3
dimcat version 3.4.0
Dataset
=======
{'inputs': {'basepath': None,
            'packages': {'tchaikovsky_seasons': ["'tchaikovsky_seasons.measures' "
                                                 '(MuseScoreFacetName.MuseScoreMeasures)',
                                                 "'tchaikovsky_seasons.notes' (MuseScoreFacetName.MuseScoreNotes)",
                                                 "'tchaikovsky_seasons.expanded' "
                                                 '(MuseScoreFacetName.MuseScoreHarmonies)',
                                                 "'tchaikovsky_seasons.chords' (MuseScoreFacetName.MuseScoreChords)",
                                                 "'tchaikovsky_seasons.metadata' (FeatureName.Metadata)"]}},
 'outputs': {'basepath': None, 'packages': {}},
 'pipeline': []}
filtered_D = filters.HasHarmonyLabelsFilter(keep_values=[True]).process(D)
all_metadata = filtered_D.get_metadata()
assert len(all_metadata) > 0, "No pieces selected for analysis."
all_metadata
TimeSig KeySig last_mc last_mn length_qb last_mc_unfolded last_mn_unfolded length_qb_unfolded volta_mcs all_notes_qb ... musicbrainz viaf wikidata originalFormat pdf score integrity staff_1_ambitus staff_1_instrument staff_2_ambitus staff_2_instrument
corpus piece
tchaikovsky_seasons op37a01 {1: '3/4'} {1: 3, 29: 1, 63: 3} 103 103 309.0 103 103 309.0 () 1058.17 ... https://musicbrainz.org/work/6460a645-9844-304... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 mxl https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 53-88 (E#3-E6) Piano 33-88 (A1-E6) Piano
op37a02 {1: '2/4'} {1: 2} 169 169 338.0 181 181 362.0 () 1263.00 ... https://musicbrainz.org/work/b9eb26bd-2d34-390... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 mxl https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 43-93 (G2-A6) Piano 29-85 (F1-C#6) Piano
op37a03 {1: '2/4'} {1: -2} 46 46 92.0 46 46 92.0 () 321.75 ... https://musicbrainz.org/work/d1adc59b-c23d-301... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 mxl https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 55-86 (G3-D6) Piano 38-72 (D2-C5) Piano
op37a04 {1: '6/8'} {1: -2} 87 86 258.5 87 86 258.5 () 804.00 ... https://musicbrainz.org/work/d364de99-f08f-322... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 52-86 (E3-D6) Piano (2) 39-77 (D#2-F5) Piano (2)
op37a05 {1: '9/8', 20: '2/4', 68: '9/8'} {1: 1, 20: 2, 68: 1} 88 88 274.5 88 88 274.5 () 899.50 ... https://musicbrainz.org/work/a0fcf2bc-9344-37e... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 48-86 (C3-D6) Piano (2) 40-74 (E2-D5) Piano (2)
op37a06 {1: '4/4', 40: '3/4', 52: '4/4'} {1: -2, 32: 1, 52: -2} 99 99 384.0 99 99 384.0 () 1299.50 ... https://musicbrainz.org/work/97abe0e5-11f8-308... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 mxl https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 42-91 (F#2-G6) Piano 31-88 (G1-E6) Piano
op37a07 {1: '4/4'} {1: -3} 56 56 224.0 56 56 224.0 () 941.17 ... https://musicbrainz.org/work/43198a46-81be-3ce... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 46-89 (Bb2-F6) Piano (2) 34-77 (Bb1-F5) Piano (2)
op37a08 {1: '6/8'} {1: 2} 199 198 595.5 199 198 595.5 () 1994.00 ... https://musicbrainz.org/work/76f98337-460c-399... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 43-91 (G2-G6) Piano (2) 35-83 (B1-B5) Piano (2)
op37a09 {1: '4/4'} {1: 1} 90 90 360.0 90 90 360.0 () 1430.33 ... https://musicbrainz.org/work/58e2eb4f-6cee-358... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 54-91 (F#3-G6) Piano (2) 36-71 (C2-B4) Piano (2)
op37a10 {1: '4/4'} {1: -1} 56 56 224.0 56 56 224.0 () 808.00 ... https://musicbrainz.org/work/b03dde30-6ae2-32e... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 <NA> https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 53-82 (F3-Bb5) Piano 37-67 (C#2-G4) Piano
op37a11 {1: '4/4'} {1: 4, 28: 1, 51: 4} 83 83 332.0 83 83 332.0 () 967.92 ... https://musicbrainz.org/work/432dd63f-4645-34a... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 45-92 (A2-G#6) Piano (2) 38-75 (D2-D#5) Piano (2)
op37a12 {1: '3/4'} {1: -4, 88: 4, 149: -4} 176 176 528.0 263 263 789.0 () 1856.50 ... https://musicbrainz.org/work/4a023af1-58db-3ce... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 56-92 (G#3-Ab6) Piano (2) 39-75 (Eb2-Eb5) Piano (2)

12 rows × 57 columns

mean_composition_years = utils.corpus_mean_composition_years(all_metadata)
chronological_order = mean_composition_years.index.to_list()
corpus_colors = dict(zip(chronological_order, utils.CORPUS_COLOR_SCALE))
corpus_names = {
    corp: utils.get_corpus_display_name(corp) for corp in chronological_order
}
chronological_corpus_names = list(corpus_names.values())
corpus_name_colors = {
    corpus_names[corp]: color for corp, color in corpus_colors.items()
}
mean_composition_years
corpus
tchaikovsky_seasons    1875.5
Name: mean_composition_year, dtype: float64

Composition dates#

This section relies on the dataset’s metadata.

valid_composed_start = pd.to_numeric(all_metadata.composed_start, errors="coerce")
valid_composed_end = pd.to_numeric(all_metadata.composed_end, errors="coerce")
print(
    f"Composition dates range from {int(valid_composed_start.min())} {valid_composed_start.idxmin()} "
    f"to {int(valid_composed_end.max())} {valid_composed_end.idxmax()}."
)
Composition dates range from 1875 ('tchaikovsky_seasons', 'op37a01') to 1876 ('tchaikovsky_seasons', 'op37a01').

Mean composition years per corpus#

def make_summary(metadata_df):
    piece_is_annotated = metadata_df.label_count > 0
    return metadata_df[piece_is_annotated].copy()
Hide source
summary = make_summary(all_metadata)
bar_data = pd.concat(
    [
        mean_composition_years.rename("year"),
        summary.groupby(level="corpus").size().rename("pieces"),
    ],
    axis=1,
).reset_index()

N = len(summary)
fig = px.bar(
    bar_data,
    x="year",
    y="pieces",
    color="corpus",
    color_discrete_map=corpus_colors,
    title=f"Temporal coverage of the {N} annotated pieces in the Distant Listening Corpus",
)
fig.update_traces(width=5)
fig.update_layout(**utils.STD_LAYOUT)
fig.update_traces(width=5)
save_figure_as(fig, "pieces_timeline_bars")
fig.show()
summary
TimeSig KeySig last_mc last_mn length_qb last_mc_unfolded last_mn_unfolded length_qb_unfolded volta_mcs all_notes_qb ... musicbrainz viaf wikidata originalFormat pdf score integrity staff_1_ambitus staff_1_instrument staff_2_ambitus staff_2_instrument
corpus piece
tchaikovsky_seasons op37a01 {1: '3/4'} {1: 3, 29: 1, 63: 3} 103 103 309.0 103 103 309.0 () 1058.17 ... https://musicbrainz.org/work/6460a645-9844-304... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 mxl https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 53-88 (E#3-E6) Piano 33-88 (A1-E6) Piano
op37a02 {1: '2/4'} {1: 2} 169 169 338.0 181 181 362.0 () 1263.00 ... https://musicbrainz.org/work/b9eb26bd-2d34-390... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 mxl https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 43-93 (G2-A6) Piano 29-85 (F1-C#6) Piano
op37a03 {1: '2/4'} {1: -2} 46 46 92.0 46 46 92.0 () 321.75 ... https://musicbrainz.org/work/d1adc59b-c23d-301... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 mxl https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 55-86 (G3-D6) Piano 38-72 (D2-C5) Piano
op37a04 {1: '6/8'} {1: -2} 87 86 258.5 87 86 258.5 () 804.00 ... https://musicbrainz.org/work/d364de99-f08f-322... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 52-86 (E3-D6) Piano (2) 39-77 (D#2-F5) Piano (2)
op37a05 {1: '9/8', 20: '2/4', 68: '9/8'} {1: 1, 20: 2, 68: 1} 88 88 274.5 88 88 274.5 () 899.50 ... https://musicbrainz.org/work/a0fcf2bc-9344-37e... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 48-86 (C3-D6) Piano (2) 40-74 (E2-D5) Piano (2)
op37a06 {1: '4/4', 40: '3/4', 52: '4/4'} {1: -2, 32: 1, 52: -2} 99 99 384.0 99 99 384.0 () 1299.50 ... https://musicbrainz.org/work/97abe0e5-11f8-308... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 mxl https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 42-91 (F#2-G6) Piano 31-88 (G1-E6) Piano
op37a07 {1: '4/4'} {1: -3} 56 56 224.0 56 56 224.0 () 941.17 ... https://musicbrainz.org/work/43198a46-81be-3ce... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 46-89 (Bb2-F6) Piano (2) 34-77 (Bb1-F5) Piano (2)
op37a08 {1: '6/8'} {1: 2} 199 198 595.5 199 198 595.5 () 1994.00 ... https://musicbrainz.org/work/76f98337-460c-399... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 43-91 (G2-G6) Piano (2) 35-83 (B1-B5) Piano (2)
op37a09 {1: '4/4'} {1: 1} 90 90 360.0 90 90 360.0 () 1430.33 ... https://musicbrainz.org/work/58e2eb4f-6cee-358... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 54-91 (F#3-G6) Piano (2) 36-71 (C2-B4) Piano (2)
op37a10 {1: '4/4'} {1: -1} 56 56 224.0 56 56 224.0 () 808.00 ... https://musicbrainz.org/work/b03dde30-6ae2-32e... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 <NA> https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 53-82 (F3-Bb5) Piano 37-67 (C#2-G4) Piano
op37a11 {1: '4/4'} {1: 4, 28: 1, 51: 4} 83 83 332.0 83 83 332.0 () 967.92 ... https://musicbrainz.org/work/432dd63f-4645-34a... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 45-92 (A2-G#6) Piano (2) 38-75 (D2-D#5) Piano (2)
op37a12 {1: '3/4'} {1: -4, 88: 4, 149: -4} 176 176 528.0 263 263 789.0 () 1856.50 ... https://musicbrainz.org/work/4a023af1-58db-3ce... https://viaf.org/viaf/183857288 https://www.wikidata.org/wiki/Q2914902 xml https://imslp.org/wiki/Special:ReverseLookup/1... Tom Schreyer 56-92 (G#3-Ab6) Piano (2) 39-75 (Eb2-Eb5) Piano (2)

12 rows × 57 columns

Composition years histogram#

Hide source
hist_data = summary.reset_index()
hist_data.corpus = hist_data.corpus.map(corpus_names)
fig = px.histogram(
    hist_data,
    x="composed_end",
    color="corpus",
    labels=dict(
        composed_end="decade",
        count="pieces",
    ),
    color_discrete_map=corpus_name_colors,
    title=f"Temporal coverage of the {N} annotated pieces in the Distant Listening Corpus",
)
fig.update_traces(xbins=dict(size=10))
fig.update_layout(**utils.STD_LAYOUT)
fig.update_legends(font=dict(size=16))
save_figure_as(fig, "pieces_timeline_histogram", height=1250)
fig.show()

Dimensions#

Overview#

def make_overview_table(groupby, group_name="pieces"):
    n_groups = groupby.size().rename(group_name)
    absolute_numbers = dict(
        measures=groupby.last_mn.sum(),
        length=groupby.length_qb.sum(),
        notes=groupby.n_onsets.sum(),
        labels=groupby.label_count.sum(),
    )
    absolute = pd.DataFrame.from_dict(absolute_numbers)
    absolute = pd.concat([n_groups, absolute], axis=1)
    sum_row = pd.DataFrame(absolute.sum(), columns=["sum"]).T
    absolute = pd.concat([absolute, sum_row])
    return absolute


absolute = make_overview_table(summary.groupby("workTitle"))
# print(absolute.astype(int).to_markdown())
absolute.astype(int)
pieces measures length notes labels
The Seasons 12 1250 3919 18169 3059
sum 12 1250 3919 18169 3059
def summarize_dataset(D):
    all_metadata = D.get_metadata()
    summary = make_summary(all_metadata)
    return make_overview_table(summary.groupby(level=0))


corpus_summary = summarize_dataset(D)
print(corpus_summary.astype(int).to_markdown())
|                     |   pieces |   measures |   length |   notes |   labels |
|:--------------------|---------:|-----------:|---------:|--------:|---------:|
| tchaikovsky_seasons |       12 |       1250 |     3919 |   18169 |     3059 |
| sum                 |       12 |       1250 |     3919 |   18169 |     3059 |

Measures#

all_measures = D.get_feature("measures")
print(
    f"{len(all_measures.index)} measures over {len(all_measures.groupby(level=[0,1]))} files."
)
all_measures.head()
1252 measures over 12 files.
mc mn quarterbeats duration_qb keysig timesig act_dur mc_offset numbering_offset dont_count barline breaks repeats next markers jump_bwd jump_fwd play_until
corpus piece i
tchaikovsky_seasons op37a01 0 1 1 0 3.0 3 3/4 3/4 0 <NA> <NA> <NA> <NA> firstMeasure (2,) <NA> <NA> <NA> <NA>
1 2 2 3 3.0 3 3/4 3/4 0 <NA> <NA> <NA> <NA> <NA> (3,) <NA> <NA> <NA> <NA>
2 3 3 6 3.0 3 3/4 3/4 0 <NA> <NA> <NA> <NA> <NA> (4,) <NA> <NA> <NA> <NA>
3 4 4 9 3.0 3 3/4 3/4 0 <NA> <NA> <NA> <NA> <NA> (5,) <NA> <NA> <NA> <NA>
4 5 5 12 3.0 3 3/4 3/4 0 <NA> <NA> <NA> <NA> <NA> (6,) <NA> <NA> <NA> <NA>
all_measures.get_default_analysis().plot_grouped()

Harmony labels#

All symbols, independent of the local key (the mode of which changes their semantics).

try:
    all_annotations = D.get_feature("harmonylabels").df
except Exception:
    all_annotations = pd.DataFrame()
n_annotations = len(all_annotations.index)
includes_annotations = n_annotations > 0
if includes_annotations:
    display(all_annotations.head())
    print(f"Concatenated annotation tables contains {all_annotations.shape[0]} rows.")
    no_chord = all_annotations.root.isna()
    if no_chord.sum() > 0:
        print(
            f"{no_chord.sum()} of them are not chords. Their values are:"
            f" {all_annotations.label[no_chord].value_counts(dropna=False).to_dict()}"
        )
    all_chords = all_annotations[~no_chord].copy()
    print(
        f"Dataset contains {all_chords.shape[0]} tokens and {len(all_chords.chord.unique())} types over "
        f"{len(all_chords.groupby(level=[0,1]))} documents."
    )
    all_annotations["corpus_name"] = all_annotations.index.get_level_values(0).map(
        utils.get_corpus_display_name
    )
    all_chords["corpus_name"] = all_chords.index.get_level_values(0).map(
        utils.get_corpus_display_name
    )
else:
    print("Dataset contains no annotations.")
mc mn quarterbeats quarterbeats_all_endings duration_qb mc_onset mn_onset timesig staff voice ... numeral_or_applied_to_numeral intervals_over_bass intervals_over_root scale_degrees scale_degrees_and_mode scale_degrees_major scale_degrees_minor globalkey localkey chord
corpus piece i
tchaikovsky_seasons op37a01 0 1 1 0 0 2.0 0 0 3/4 2 1 ... V (M2, a4, M6) (M3, P5, m7) (4, 5, 7, 2) (4, 5, 7, 2), major (4, 5, 7, 2) (4, 5, #7, 2) A I V2
1 1 1 2 2 1.0 1/2 1/2 3/4 2 1 ... I (m3, m6) (M3, P5) (3, 5, 1) (3, 5, 1), major (3, 5, 1) (#3, 5, 1) A I I6
2 2 2 3 3 0.5 0 0 3/4 2 1 ... V (P4, M6) (M3, P5) (2, 5, 7) (2, 5, 7), major (2, 5, 7) (2, 5, #7) A I V64
3 2 2 7/2 7/2 0.5 1/8 1/8 3/4 2 1 ... I (M3, P5) (M3, P5) (1, 3, 5) (1, 3, 5), major (1, 3, 5) (1, #3, 5) A I I
4 2 2 4 4 1.0 1/4 1/4 3/4 2 1 ... V (m3, m6) (M3, P5) (7, 2, 5) (7, 2, 5), major (7, 2, 5) (#7, 2, 5) A I V6

5 rows × 52 columns

Concatenated annotation tables contains 2992 rows.
Dataset contains 2992 tokens and 278 types over 12 documents.